oxlint-tailwindcss 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -491,6 +491,21 @@ function getArbitraryValue(cls) {
491
491
  }
492
492
  //#endregion
493
493
  //#region src/design-system/cache.ts
494
+ /** Strip `!` modifier from start or end: `!flex` → `flex`, `flex!` → `flex` */
495
+ function stripImportant(cls) {
496
+ if (cls.startsWith("!")) return {
497
+ bare: cls.slice(1),
498
+ important: true
499
+ };
500
+ if (cls.endsWith("!")) return {
501
+ bare: cls.slice(0, -1),
502
+ important: true
503
+ };
504
+ return {
505
+ bare: cls,
506
+ important: false
507
+ };
508
+ }
494
509
  var DesignSystemCache = class DesignSystemCache {
495
510
  canonicalMap = /* @__PURE__ */ new Map();
496
511
  validitySet = /* @__PURE__ */ new Set();
@@ -522,6 +537,11 @@ var DesignSystemCache = class DesignSystemCache {
522
537
  const canonicalUtility = this.canonicalMap.get(utility);
523
538
  if (canonicalUtility !== void 0) return className.slice(0, className.length - utility.length) + canonicalUtility;
524
539
  }
540
+ const { bare, important } = stripImportant(utility);
541
+ if (important) {
542
+ const canonicalBare = this.canonicalMap.get(bare);
543
+ if (canonicalBare !== void 0) return className.slice(0, className.length - utility.length) + "!" + canonicalBare;
544
+ }
525
545
  return className;
526
546
  }
527
547
  isValid(className) {
@@ -539,13 +559,22 @@ var DesignSystemCache = class DesignSystemCache {
539
559
  const baseOrder = this.orderMap.get(utility);
540
560
  if (baseOrder !== void 0) return baseOrder;
541
561
  }
562
+ const { bare, important } = stripImportant(utility);
563
+ if (important) {
564
+ const bareOrder = this.orderMap.get(bare);
565
+ if (bareOrder !== void 0) return bareOrder;
566
+ }
542
567
  return null;
543
568
  }
544
569
  getClassOrder(classes) {
545
570
  return classes.map((cls) => [cls, this.getOrder(cls)]);
546
571
  }
547
572
  getCssProperties(className) {
548
- return this.cssPropsMap.get(className) ?? [];
573
+ const result = this.cssPropsMap.get(className);
574
+ if (result) return result;
575
+ const { bare, important } = stripImportant(className);
576
+ if (important) return this.cssPropsMap.get(bare) ?? [];
577
+ return [];
549
578
  }
550
579
  getVariantPriority(variant) {
551
580
  return this.variantOrderMap.get(variant) ?? null;
@@ -554,7 +583,11 @@ var DesignSystemCache = class DesignSystemCache {
554
583
  return this.variantOrderMap.size > 0;
555
584
  }
556
585
  getNamedEquivalent(className) {
557
- return this.arbitraryEquivMap.get(className) ?? null;
586
+ const result = this.arbitraryEquivMap.get(className);
587
+ if (result) return result;
588
+ const { bare, important } = stripImportant(className);
589
+ if (important) return this.arbitraryEquivMap.get(bare) ?? null;
590
+ return null;
558
591
  }
559
592
  };
560
593
  //#endregion
@@ -815,8 +848,8 @@ function entryPointFromSettings(settings) {
815
848
  *
816
849
  * Resolution order: rule option `entryPoint` > `settings.tailwindcss.entryPoint` > auto-detect.
817
850
  */
818
- function getLoadedDesignSystem(entryPoint, settings) {
819
- const cssPath = entryPoint ?? entryPointFromSettings(settings) ?? singleton?.path ?? autoDetectEntryPoint();
851
+ function getLoadedDesignSystem(entryPoint, settings, filePath) {
852
+ const cssPath = entryPoint ?? entryPointFromSettings(settings) ?? singleton?.path ?? autoDetectEntryPoint(filePath);
820
853
  if (!cssPath) return null;
821
854
  const resolvedPath = (0, node_path.resolve)(cssPath);
822
855
  try {
@@ -841,6 +874,36 @@ function getLoadedDesignSystem(entryPoint, settings) {
841
874
  return null;
842
875
  }
843
876
  }
877
+ /**
878
+ * Creates a lazy DS loader that retries with more context as it becomes available.
879
+ *
880
+ * In `createOnce`, `context.settings` and `context.filename` throw. When visitors
881
+ * run, they become available. This function retries until it has the file path
882
+ * (meaning we're in a visitor with full context), then gives up.
883
+ */
884
+ function createLazyLoader(context) {
885
+ let result = null;
886
+ let triedWithFilePath = false;
887
+ return () => {
888
+ if (result) return result;
889
+ if (triedWithFilePath) return null;
890
+ let entryPoint;
891
+ try {
892
+ entryPoint = (context.options?.[0])?.entryPoint;
893
+ } catch {}
894
+ let settings;
895
+ try {
896
+ settings = context.settings;
897
+ } catch {}
898
+ let filePath;
899
+ try {
900
+ filePath = context.filename;
901
+ } catch {}
902
+ result = getLoadedDesignSystem(entryPoint, settings, filePath);
903
+ if (filePath) triedWithFilePath = true;
904
+ return result;
905
+ };
906
+ }
844
907
  //#endregion
845
908
  //#region src/types.ts
846
909
  /**
@@ -859,19 +922,6 @@ function safeOptions(context) {
859
922
  return;
860
923
  }
861
924
  }
862
- /**
863
- * Safely read context.settings.
864
- *
865
- * Like `safeOptions`, `context.settings` may not be accessible in `createOnce()`.
866
- * The try/catch handles that gracefully.
867
- */
868
- function safeSettings(context) {
869
- try {
870
- return context.settings ?? void 0;
871
- } catch {
872
- return;
873
- }
874
- }
875
925
  //#endregion
876
926
  //#region src/rules/no-unknown-classes.ts
877
927
  const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
@@ -899,22 +949,35 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
899
949
  }
900
950
  },
901
951
  createOnce(context) {
902
- const options = safeOptions(context);
903
- const result = getLoadedDesignSystem(options?.entryPoint, safeSettings(context));
904
- if (!result) return {};
905
- const { cache } = result;
906
- const allowlist = new Set(options?.allowlist ?? []);
907
- const ignorePrefixes = options?.ignorePrefixes ?? [];
952
+ const getDS = createLazyLoader(context);
953
+ let _allowlist = null;
954
+ let _ignorePrefixes = null;
955
+ function getLazyOptions() {
956
+ if (_allowlist === null) {
957
+ const opts = safeOptions(context);
958
+ _allowlist = new Set(opts?.allowlist ?? []);
959
+ _ignorePrefixes = opts?.ignorePrefixes ?? [];
960
+ }
961
+ return {
962
+ allowlist: _allowlist,
963
+ ignorePrefixes: _ignorePrefixes
964
+ };
965
+ }
908
966
  function shouldIgnore(className) {
967
+ const { allowlist, ignorePrefixes } = getLazyOptions();
909
968
  if (allowlist.has(className)) return true;
910
969
  return ignorePrefixes.some((prefix) => className.startsWith(prefix));
911
970
  }
912
971
  function stripModifiers(className) {
913
972
  let stripped = className;
914
973
  if (stripped.startsWith("!")) stripped = stripped.slice(1);
974
+ if (stripped.endsWith("!")) stripped = stripped.slice(0, -1);
915
975
  return stripped;
916
976
  }
917
977
  function check(locations) {
978
+ const ds = getDS();
979
+ if (!ds) return;
980
+ const { cache } = ds;
918
981
  for (const loc of locations) {
919
982
  const classes = splitClasses(loc.value);
920
983
  for (const cls of classes) {
@@ -968,10 +1031,11 @@ const noConflictingClasses = (0, _oxlint_plugins.defineRule)({
968
1031
  messages: { conflict: "\"{{classA}}\" and \"{{classB}}\" affect {{properties}}. \"{{winner}}\" takes precedence (appears later)." }
969
1032
  },
970
1033
  createOnce(context) {
971
- const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint, safeSettings(context));
972
- if (!result) return {};
973
- const { cache } = result;
1034
+ const getDS = createLazyLoader(context);
974
1035
  function check(locations) {
1036
+ const ds = getDS();
1037
+ if (!ds) return;
1038
+ const { cache } = ds;
975
1039
  for (const loc of locations) {
976
1040
  const classes = splitClasses(loc.value);
977
1041
  if (classes.length < 2) continue;
@@ -986,7 +1050,9 @@ const noConflictingClasses = (0, _oxlint_plugins.defineRule)({
986
1050
  if (variantClasses.length < 2) continue;
987
1051
  const propsMap = /* @__PURE__ */ new Map();
988
1052
  for (const cls of variantClasses) {
989
- const utility = extractUtility(cls);
1053
+ let utility = extractUtility(cls);
1054
+ if (utility.startsWith("!")) utility = utility.slice(1);
1055
+ else if (utility.endsWith("!")) utility = utility.slice(0, -1);
990
1056
  const props = cache.getCssProperties(utility);
991
1057
  propsMap.set(cls, props);
992
1058
  }
@@ -1055,29 +1121,51 @@ const noDeprecatedClasses = (0, _oxlint_plugins.defineRule)({
1055
1121
  messages: { deprecated: "\"{{className}}\" is deprecated in Tailwind v4. Use \"{{replacement}}\" instead." }
1056
1122
  },
1057
1123
  createOnce(context) {
1058
- const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint, safeSettings(context));
1124
+ const getDS = createLazyLoader(context);
1059
1125
  function check(locations) {
1126
+ const dsResult = getDS();
1060
1127
  for (const loc of locations) {
1061
1128
  const classes = splitClasses(loc.value);
1129
+ const offending = [];
1062
1130
  for (const cls of classes) {
1063
1131
  const { utility, variant } = splitUtilityAndVariant(cls);
1064
- const replacement = DEPRECATED_MAP[utility];
1132
+ const hasImportantPrefix = utility.startsWith("!");
1133
+ const hasImportantSuffix = !hasImportantPrefix && utility.endsWith("!");
1134
+ const bareUtility = hasImportantPrefix ? utility.slice(1) : hasImportantSuffix ? utility.slice(0, -1) : utility;
1135
+ const replacement = DEPRECATED_MAP[bareUtility];
1065
1136
  if (!replacement) continue;
1066
- if (result) {
1067
- const canonical = result.cache.canonicalize(utility);
1068
- if (canonical !== utility && canonical === replacement) {}
1137
+ if (dsResult) {
1138
+ const canonical = dsResult.cache.canonicalize(bareUtility);
1139
+ if (canonical !== bareUtility && canonical === replacement) {}
1069
1140
  }
1070
- const fullReplacement = variant + replacement;
1071
- context.report({
1141
+ const fullReplacement = variant + (hasImportantPrefix ? "!" : "") + replacement + (hasImportantSuffix ? "!" : "");
1142
+ offending.push({
1143
+ cls,
1144
+ replacement: fullReplacement
1145
+ });
1146
+ }
1147
+ if (offending.length === 0) continue;
1148
+ const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
1149
+ const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls).join(" ");
1150
+ for (let i = 0; i < offending.length; i++) {
1151
+ const { cls, replacement } = offending[i];
1152
+ if (i === 0) context.report({
1072
1153
  node: loc.node,
1073
1154
  messageId: "deprecated",
1074
1155
  data: {
1075
1156
  className: cls,
1076
- replacement: fullReplacement
1157
+ replacement
1077
1158
  },
1078
1159
  fix(fixer) {
1079
- const fixed = loc.value.replace(cls, fullReplacement);
1080
- return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixed));
1160
+ return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
1161
+ }
1162
+ });
1163
+ else context.report({
1164
+ node: loc.node,
1165
+ messageId: "deprecated",
1166
+ data: {
1167
+ className: cls,
1168
+ replacement
1081
1169
  }
1082
1170
  });
1083
1171
  }
@@ -1114,10 +1202,11 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
1114
1202
  messages: { nonCanonical: "\"{{className}}\" can be written as \"{{canonical}}\". Use the canonical form." }
1115
1203
  },
1116
1204
  createOnce(context) {
1117
- const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint, safeSettings(context));
1118
- if (!result) return {};
1119
- const { cache } = result;
1205
+ const getDS = createLazyLoader(context);
1120
1206
  function check(locations) {
1207
+ const ds = getDS();
1208
+ if (!ds) return;
1209
+ const { cache } = ds;
1121
1210
  for (const loc of locations) {
1122
1211
  const classes = splitClasses(loc.value);
1123
1212
  const canonicals = classes.map((cls) => cache.canonicalize(cls));
@@ -1188,60 +1277,63 @@ const enforceSortOrder = (0, _oxlint_plugins.defineRule)({
1188
1277
  messages: { unsorted: "Tailwind classes are not in the recommended order." }
1189
1278
  },
1190
1279
  createOnce(context) {
1191
- const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint, safeSettings(context));
1192
- if (!result) return {};
1193
- const { cache } = result;
1280
+ const getDS = createLazyLoader(context);
1194
1281
  let _mode = null;
1195
1282
  function getMode() {
1196
1283
  if (_mode === null) _mode = safeOptions(context)?.mode ?? "default";
1197
1284
  return _mode;
1198
1285
  }
1199
- function sortDefault(classes) {
1200
- return [...cache.getClassOrder(classes)].sort((a, b) => {
1201
- const orderA = a[1] ?? 0n;
1202
- const orderB = b[1] ?? 0n;
1203
- if (orderA < orderB) return -1;
1204
- if (orderA > orderB) return 1;
1205
- return 0;
1206
- }).map(([name]) => name);
1207
- }
1208
- function sortStrict(classes) {
1209
- const groups = /* @__PURE__ */ new Map();
1210
- const groupOrder = [];
1211
- for (const cls of classes) {
1212
- const { variant } = splitUtilityAndVariant(cls);
1213
- if (!groups.has(variant)) {
1214
- groups.set(variant, []);
1215
- groupOrder.push(variant);
1216
- }
1217
- groups.get(variant).push(cls);
1218
- }
1219
- for (const [, groupClasses] of groups) {
1220
- const ordered = cache.getClassOrder(groupClasses);
1221
- ordered.sort((a, b) => {
1286
+ function check(locations) {
1287
+ const ds = getDS();
1288
+ if (!ds) return;
1289
+ const { cache } = ds;
1290
+ const mode = getMode();
1291
+ function sortDefault(classes) {
1292
+ return [...cache.getClassOrder(classes)].sort((a, b) => {
1222
1293
  const orderA = a[1] ?? 0n;
1223
1294
  const orderB = b[1] ?? 0n;
1224
1295
  if (orderA < orderB) return -1;
1225
1296
  if (orderA > orderB) return 1;
1226
1297
  return 0;
1298
+ }).map(([name]) => name);
1299
+ }
1300
+ function sortStrict(classes) {
1301
+ const groups = /* @__PURE__ */ new Map();
1302
+ const groupOrder = [];
1303
+ for (const cls of classes) {
1304
+ const { variant } = splitUtilityAndVariant(cls);
1305
+ if (!groups.has(variant)) {
1306
+ groups.set(variant, []);
1307
+ groupOrder.push(variant);
1308
+ }
1309
+ groups.get(variant).push(cls);
1310
+ }
1311
+ for (const [, groupClasses] of groups) {
1312
+ const ordered = cache.getClassOrder(groupClasses);
1313
+ ordered.sort((a, b) => {
1314
+ const orderA = a[1] ?? 0n;
1315
+ const orderB = b[1] ?? 0n;
1316
+ if (orderA < orderB) return -1;
1317
+ if (orderA > orderB) return 1;
1318
+ return 0;
1319
+ });
1320
+ groupClasses.length = 0;
1321
+ for (const [name] of ordered) groupClasses.push(name);
1322
+ }
1323
+ const sortedGroupKeys = [...groups.keys()].sort((a, b) => {
1324
+ if (a === "" && b !== "") return -1;
1325
+ if (a !== "" && b === "") return 1;
1326
+ if (a === "" && b === "") return 0;
1327
+ const variantA = a.slice(0, -1);
1328
+ const variantB = b.slice(0, -1);
1329
+ const firstA = variantA.includes(":") ? variantA.split(":")[0] : variantA;
1330
+ const firstB = variantB.includes(":") ? variantB.split(":")[0] : variantB;
1331
+ return (cache.getVariantPriority(firstA) ?? Number.MAX_SAFE_INTEGER) - (cache.getVariantPriority(firstB) ?? Number.MAX_SAFE_INTEGER);
1227
1332
  });
1228
- groupClasses.length = 0;
1229
- for (const [name] of ordered) groupClasses.push(name);
1333
+ const result = [];
1334
+ for (const key of sortedGroupKeys) result.push(...groups.get(key));
1335
+ return result;
1230
1336
  }
1231
- const sortedGroupKeys = [...groups.keys()].sort((a, b) => {
1232
- if (a === "" && b !== "") return -1;
1233
- if (a !== "" && b === "") return 1;
1234
- if (a === "" && b === "") return 0;
1235
- const variantA = a.slice(0, -1);
1236
- const variantB = b.slice(0, -1);
1237
- return (cache.getVariantPriority(variantA) ?? Number.MAX_SAFE_INTEGER) - (cache.getVariantPriority(variantB) ?? Number.MAX_SAFE_INTEGER);
1238
- });
1239
- const result = [];
1240
- for (const key of sortedGroupKeys) result.push(...groups.get(key));
1241
- return result;
1242
- }
1243
- function check(locations) {
1244
- const mode = getMode();
1245
1337
  for (const loc of locations) {
1246
1338
  const classes = splitClasses(loc.value);
1247
1339
  if (classes.length < 2) continue;
@@ -1346,20 +1438,28 @@ const enforceShorthand = (0, _oxlint_plugins.defineRule)({
1346
1438
  const classSet = new Set(classes);
1347
1439
  const values = /* @__PURE__ */ new Set();
1348
1440
  for (const cls of classes) {
1349
- const match = VALUE_RE.exec(cls);
1441
+ const bare = cls.startsWith("!") ? cls.slice(1) : cls.endsWith("!") ? cls.slice(0, -1) : cls;
1442
+ const match = VALUE_RE.exec(bare);
1350
1443
  if (match) values.add(match[1]);
1351
1444
  }
1352
1445
  for (const value of values) {
1353
1446
  const rules = createShorthandRules(value);
1354
- for (const rule of rules) if (rule.parts.every((p) => classSet.has(p))) {
1355
- const remaining = classes.filter((c) => !rule.parts.includes(c));
1356
- remaining.push(rule.replacement);
1447
+ for (const rule of rules) {
1448
+ const hasImportantPrefix = rule.parts.every((p) => classSet.has(`!${p}`));
1449
+ const hasImportantSuffix = !hasImportantPrefix && rule.parts.every((p) => classSet.has(`${p}!`));
1450
+ const hasPlain = rule.parts.every((p) => classSet.has(p));
1451
+ if (!hasImportantPrefix && !hasImportantSuffix && !hasPlain) continue;
1452
+ const importantStart = hasImportantPrefix ? "!" : "";
1453
+ const importantEnd = hasImportantSuffix ? "!" : "";
1454
+ const matchParts = rule.parts.map((p) => `${importantStart}${p}${importantEnd}`);
1455
+ const remaining = classes.filter((c) => !matchParts.includes(c));
1456
+ remaining.push(`${importantStart}${rule.replacement}${importantEnd}`);
1357
1457
  context.report({
1358
1458
  node: loc.node,
1359
1459
  messageId: "shorthand",
1360
1460
  data: {
1361
- parts: rule.parts.map((p) => `"${p}"`).join(", "),
1362
- replacement: rule.replacement
1461
+ parts: matchParts.map((p) => `"${p}"`).join(", "),
1462
+ replacement: `${importantStart}${rule.replacement}${importantEnd}`
1363
1463
  },
1364
1464
  fix(fixer) {
1365
1465
  return fixer.replaceTextRange(loc.range, preserveSpaces(loc, remaining.join(" ")));
@@ -1418,7 +1518,13 @@ const enforceLogical = (0, _oxlint_plugins.defineRule)({
1418
1518
  createOnce(context) {
1419
1519
  function convertClass(cls) {
1420
1520
  const { utility, variant } = splitUtilityAndVariant(cls);
1421
- for (const [physical, logical] of Object.entries(PHYSICAL_TO_LOGICAL)) if (utility === physical || utility.startsWith(`${physical}-`)) return `${variant}${logical}${utility.slice(physical.length)}`;
1521
+ const hasImportantPrefix = utility.startsWith("!");
1522
+ const hasImportantSuffix = !hasImportantPrefix && utility.endsWith("!");
1523
+ const bareUtility = hasImportantPrefix ? utility.slice(1) : hasImportantSuffix ? utility.slice(0, -1) : utility;
1524
+ for (const [physical, logical] of Object.entries(PHYSICAL_TO_LOGICAL)) if (bareUtility === physical || bareUtility.startsWith(`${physical}-`)) {
1525
+ const suffix = bareUtility.slice(physical.length);
1526
+ return `${variant}${hasImportantPrefix ? "!" : ""}${logical}${suffix}${hasImportantSuffix ? "!" : ""}`;
1527
+ }
1422
1528
  return null;
1423
1529
  }
1424
1530
  function check(locations) {
@@ -1652,7 +1758,10 @@ const noArbitraryValue = (0, _oxlint_plugins.defineRule)({
1652
1758
  const classes = splitClasses(loc.value);
1653
1759
  for (const cls of classes) {
1654
1760
  if (!hasArbitraryValue(cls)) continue;
1655
- if (isAllowed(extractUtility(cls))) continue;
1761
+ let utility = extractUtility(cls);
1762
+ if (utility.startsWith("!")) utility = utility.slice(1);
1763
+ else if (utility.endsWith("!")) utility = utility.slice(0, -1);
1764
+ if (isAllowed(utility)) continue;
1656
1765
  context.report({
1657
1766
  node: loc.node,
1658
1767
  messageId: "noArbitrary",
@@ -1769,14 +1878,18 @@ const enforceConsistentImportantPosition = (0, _oxlint_plugins.defineRule)({
1769
1878
  //#region src/rules/enforce-negative-arbitrary-values.ts
1770
1879
  function fixClass(cls) {
1771
1880
  const { utility, variant } = splitUtilityAndVariant(cls);
1772
- if (!utility.startsWith("-")) return null;
1773
- const bracketOpen = utility.indexOf("[");
1881
+ const hasImportantPrefix = utility.startsWith("!");
1882
+ const hasImportantSuffix = !hasImportantPrefix && utility.endsWith("!");
1883
+ const bare = hasImportantPrefix ? utility.slice(1) : hasImportantSuffix ? utility.slice(0, -1) : utility;
1884
+ if (!bare.startsWith("-")) return null;
1885
+ const bracketOpen = bare.indexOf("[");
1774
1886
  if (bracketOpen === -1) return null;
1775
- const bracketClose = utility.lastIndexOf("]");
1887
+ const bracketClose = bare.lastIndexOf("]");
1776
1888
  if (bracketClose === -1 || bracketClose < bracketOpen) return null;
1777
- const innerValue = utility.slice(bracketOpen + 1, bracketClose);
1889
+ const innerValue = bare.slice(bracketOpen + 1, bracketClose);
1778
1890
  if (innerValue.startsWith("-")) return null;
1779
- return `${variant}${utility.slice(1, bracketOpen)}[-${innerValue}]`;
1891
+ const baseUtility = bare.slice(1, bracketOpen);
1892
+ return `${variant}${hasImportantPrefix ? "!" : ""}${baseUtility}[-${innerValue}]${hasImportantSuffix ? "!" : ""}`;
1780
1893
  }
1781
1894
  /**
1782
1895
  * Detects `-utility-[value]` and suggests `utility-[-value]`.
@@ -1851,17 +1964,22 @@ const EXPLICIT_VAR_RE = /^([a-z][a-z0-9-]*(?:-[a-z0-9]+)*)-\[var\((--[a-zA-Z0-9-
1851
1964
  const SHORTHAND_VAR_RE = /^([a-z][a-z0-9-]*(?:-[a-z0-9]+)*)-\((--[a-zA-Z0-9-]+)\)$/;
1852
1965
  function convertClass(cls, syntax) {
1853
1966
  const { utility, variant } = splitUtilityAndVariant(cls);
1967
+ const hasImportantPrefix = utility.startsWith("!");
1968
+ const hasImportantSuffix = !hasImportantPrefix && utility.endsWith("!");
1969
+ const bareUtility = hasImportantPrefix ? utility.slice(1) : hasImportantSuffix ? utility.slice(0, -1) : utility;
1970
+ const importantStart = hasImportantPrefix ? "!" : "";
1971
+ const importantEnd = hasImportantSuffix ? "!" : "";
1854
1972
  if (syntax === "shorthand") {
1855
- const match = EXPLICIT_VAR_RE.exec(utility);
1973
+ const match = EXPLICIT_VAR_RE.exec(bareUtility);
1856
1974
  if (match) {
1857
1975
  const [, prefix, varName] = match;
1858
- return `${variant}${prefix}-(${varName})`;
1976
+ return `${variant}${importantStart}${prefix}-(${varName})${importantEnd}`;
1859
1977
  }
1860
1978
  } else {
1861
- const match = SHORTHAND_VAR_RE.exec(utility);
1979
+ const match = SHORTHAND_VAR_RE.exec(bareUtility);
1862
1980
  if (match) {
1863
1981
  const [, prefix, varName] = match;
1864
- return `${variant}${prefix}-[var(${varName})]`;
1982
+ return `${variant}${importantStart}${prefix}-[var(${varName})]${importantEnd}`;
1865
1983
  }
1866
1984
  }
1867
1985
  return null;
@@ -1988,6 +2106,7 @@ const KNOWN_PREFIXES = [
1988
2106
  function getUtilityPrefix(utility) {
1989
2107
  let u = utility;
1990
2108
  if (u.startsWith("!")) u = u.slice(1);
2109
+ else if (u.endsWith("!")) u = u.slice(0, -1);
1991
2110
  if (u.startsWith("-")) u = u.slice(1);
1992
2111
  for (const prefix of KNOWN_PREFIXES) if (u === prefix || u.startsWith(`${prefix}-`)) return prefix;
1993
2112
  const dashIdx = u.indexOf("-");
@@ -2140,7 +2259,10 @@ const noHardcodedColors = (0, _oxlint_plugins.defineRule)({
2140
2259
  for (const cls of classes) {
2141
2260
  if (allowlist.has(cls)) continue;
2142
2261
  if (!hasArbitraryValue(cls)) continue;
2143
- if (!isColorUtility(extractUtility(cls))) continue;
2262
+ let utility = extractUtility(cls);
2263
+ if (utility.startsWith("!")) utility = utility.slice(1);
2264
+ else if (utility.endsWith("!")) utility = utility.slice(0, -1);
2265
+ if (!isColorUtility(utility)) continue;
2144
2266
  const value = getArbitraryValue(cls);
2145
2267
  if (!value) continue;
2146
2268
  if (isHardcodedColor(value)) context.report({
@@ -2324,17 +2446,19 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
2324
2446
  messages: { wrongOrder: "\"{{className}}\" has variants in wrong order. Use \"{{replacement}}\" instead." }
2325
2447
  },
2326
2448
  createOnce(context) {
2327
- const dsCache = getLoadedDesignSystem(void 0, safeSettings(context))?.cache ?? null;
2449
+ const getDS = createLazyLoader(context);
2328
2450
  let _config = null;
2329
2451
  function getConfig() {
2330
2452
  if (_config === null) {
2331
2453
  const options = safeOptions(context);
2454
+ const dsCache = getDS()?.cache ?? null;
2332
2455
  const priorityMap = /* @__PURE__ */ new Map();
2333
2456
  if (options?.order) {
2334
2457
  for (let i = 0; i < options.order.length; i++) priorityMap.set(options.order[i], i);
2335
2458
  _config = {
2336
2459
  priorityMap,
2337
- fallbackPriority: options.order.length
2460
+ fallbackPriority: options.order.length,
2461
+ dsCache
2338
2462
  };
2339
2463
  } else if (dsCache && dsCache.hasVariantOrder()) {
2340
2464
  for (const variant of DEFAULT_VARIANT_ORDER) {
@@ -2343,20 +2467,22 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
2343
2467
  }
2344
2468
  _config = {
2345
2469
  priorityMap,
2346
- fallbackPriority: Number.MAX_SAFE_INTEGER
2470
+ fallbackPriority: Number.MAX_SAFE_INTEGER,
2471
+ dsCache
2347
2472
  };
2348
2473
  } else {
2349
2474
  for (let i = 0; i < DEFAULT_VARIANT_ORDER.length; i++) priorityMap.set(DEFAULT_VARIANT_ORDER[i], i);
2350
2475
  _config = {
2351
2476
  priorityMap,
2352
- fallbackPriority: DEFAULT_VARIANT_ORDER.length
2477
+ fallbackPriority: DEFAULT_VARIANT_ORDER.length,
2478
+ dsCache
2353
2479
  };
2354
2480
  }
2355
2481
  }
2356
2482
  return _config;
2357
2483
  }
2358
2484
  function getVariantPriority(variant) {
2359
- const { priorityMap, fallbackPriority } = getConfig();
2485
+ const { priorityMap, fallbackPriority, dsCache } = getConfig();
2360
2486
  const priority = priorityMap.get(variant);
2361
2487
  if (priority !== void 0) return priority;
2362
2488
  if (dsCache && dsCache.hasVariantOrder()) {
@@ -2533,21 +2659,25 @@ const noUnnecessaryArbitraryValue = (0, _oxlint_plugins.defineRule)({
2533
2659
  messages: { unnecessaryArbitrary: "\"{{className}}\" can be written as \"{{replacement}}\". Use the named class instead." }
2534
2660
  },
2535
2661
  createOnce(context) {
2536
- const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint, safeSettings(context));
2537
- if (!result) return {};
2538
- const { cache } = result;
2662
+ const getDS = createLazyLoader(context);
2539
2663
  function check(locations) {
2664
+ const ds = getDS();
2665
+ if (!ds) return;
2666
+ const { cache } = ds;
2540
2667
  for (const loc of locations) {
2541
2668
  const classes = splitClasses(loc.value);
2542
2669
  const offending = [];
2543
2670
  for (const cls of classes) {
2544
2671
  if (!hasArbitraryValue(cls)) continue;
2545
2672
  const { utility, variant } = splitUtilityAndVariant(cls);
2546
- const named = cache.getNamedEquivalent(utility);
2673
+ const hasImportantPrefix = utility.startsWith("!");
2674
+ const hasImportantSuffix = !hasImportantPrefix && utility.endsWith("!");
2675
+ const bareUtility = hasImportantPrefix ? utility.slice(1) : hasImportantSuffix ? utility.slice(0, -1) : utility;
2676
+ const named = cache.getNamedEquivalent(bareUtility);
2547
2677
  if (!named) continue;
2548
2678
  offending.push({
2549
2679
  cls,
2550
- replacement: variant + named
2680
+ replacement: variant + (hasImportantPrefix ? "!" : "") + named + (hasImportantSuffix ? "!" : "")
2551
2681
  });
2552
2682
  }
2553
2683
  if (offending.length === 0) continue;