oxlint-tailwindcss 0.1.3 → 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.mjs CHANGED
@@ -1,7 +1,9 @@
1
1
  import { definePlugin, defineRule } from "@oxlint/plugins";
2
2
  import { execFileSync } from "node:child_process";
3
+ import { createHash } from "node:crypto";
4
+ import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
3
5
  import { dirname, join, resolve } from "node:path";
4
- import { existsSync, readFileSync, statSync } from "node:fs";
6
+ import { tmpdir } from "node:os";
5
7
  //#region src/utils/extractors.ts
6
8
  /**
7
9
  * Preserves leading/trailing spaces in fixed class strings for template literals.
@@ -489,6 +491,21 @@ function getArbitraryValue(cls) {
489
491
  }
490
492
  //#endregion
491
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
+ }
492
509
  var DesignSystemCache = class DesignSystemCache {
493
510
  canonicalMap = /* @__PURE__ */ new Map();
494
511
  validitySet = /* @__PURE__ */ new Set();
@@ -520,6 +537,11 @@ var DesignSystemCache = class DesignSystemCache {
520
537
  const canonicalUtility = this.canonicalMap.get(utility);
521
538
  if (canonicalUtility !== void 0) return className.slice(0, className.length - utility.length) + canonicalUtility;
522
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
+ }
523
545
  return className;
524
546
  }
525
547
  isValid(className) {
@@ -537,13 +559,22 @@ var DesignSystemCache = class DesignSystemCache {
537
559
  const baseOrder = this.orderMap.get(utility);
538
560
  if (baseOrder !== void 0) return baseOrder;
539
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
+ }
540
567
  return null;
541
568
  }
542
569
  getClassOrder(classes) {
543
570
  return classes.map((cls) => [cls, this.getOrder(cls)]);
544
571
  }
545
572
  getCssProperties(className) {
546
- 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 [];
547
578
  }
548
579
  getVariantPriority(variant) {
549
580
  return this.variantOrderMap.get(variant) ?? null;
@@ -552,7 +583,11 @@ var DesignSystemCache = class DesignSystemCache {
552
583
  return this.variantOrderMap.size > 0;
553
584
  }
554
585
  getNamedEquivalent(className) {
555
- 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;
556
591
  }
557
592
  };
558
593
  //#endregion
@@ -694,9 +729,18 @@ async function main() {
694
729
  }
695
730
  main().catch(e => { process.stderr.write(e.message); process.exit(1); });
696
731
  `;
732
+ const CACHE_DIR = join(tmpdir(), "oxlint-tailwindcss");
733
+ function getCachePath(cssPath, mtime) {
734
+ return join(CACHE_DIR, `${createHash("md5").update(`${cssPath}:${mtime}`).digest("hex")}.json`);
735
+ }
697
736
  function loadDesignSystemSync(cssPath) {
698
737
  const resolvedPath = resolve(cssPath);
699
738
  try {
739
+ const mtime = statSync(resolvedPath).mtimeMs;
740
+ const cachePath = getCachePath(resolvedPath, mtime);
741
+ if (existsSync(cachePath)) try {
742
+ return JSON.parse(readFileSync(cachePath, "utf-8"));
743
+ } catch {}
700
744
  const stdout = execFileSync(process.execPath, ["-e", PRECOMPUTE_SCRIPT], {
701
745
  encoding: "utf-8",
702
746
  timeout: 3e4,
@@ -707,6 +751,10 @@ function loadDesignSystemSync(cssPath) {
707
751
  },
708
752
  cwd: dirname(resolvedPath)
709
753
  });
754
+ try {
755
+ mkdirSync(CACHE_DIR, { recursive: true });
756
+ writeFileSync(cachePath, stdout);
757
+ } catch {}
710
758
  return JSON.parse(stdout);
711
759
  } catch (error) {
712
760
  console.error(`[oxlint-tailwindcss] Failed to load design system from "${resolvedPath}":`, error instanceof Error ? error.message : error);
@@ -715,21 +763,29 @@ function loadDesignSystemSync(cssPath) {
715
763
  }
716
764
  //#endregion
717
765
  //#region src/design-system/auto-detect.ts
718
- const CANDIDATE_PATHS = [
719
- "src/app.css",
720
- "src/globals.css",
721
- "src/global.css",
722
- "src/style.css",
723
- "src/styles.css",
724
- "src/index.css",
725
- "app.css",
726
- "main.css",
727
- "globals.css",
728
- "style.css",
729
- "styles/globals.css",
730
- "app/globals.css",
731
- "assets/css/tailwind.css"
766
+ const CANDIDATE_DIRS = [
767
+ "src",
768
+ ".",
769
+ "app",
770
+ "styles",
771
+ "style",
772
+ "css",
773
+ "assets",
774
+ "assets/css",
775
+ "resources/css"
732
776
  ];
777
+ const CANDIDATE_NAMES = [
778
+ "app",
779
+ "globals",
780
+ "global",
781
+ "style",
782
+ "styles",
783
+ "index",
784
+ "main",
785
+ "tailwind",
786
+ "tailwindcss"
787
+ ];
788
+ const CANDIDATE_PATHS = CANDIDATE_DIRS.flatMap((dir) => CANDIDATE_NAMES.map((name) => dir === "." ? `${name}.css` : `${dir}/${name}.css`));
733
789
  const TAILWIND_SIGNALS = [
734
790
  "@import \"tailwindcss\"",
735
791
  "@import 'tailwindcss'",
@@ -776,12 +832,24 @@ function autoDetectEntryPoint(filePath) {
776
832
  //#region src/design-system/loader.ts
777
833
  let singleton = null;
778
834
  /**
835
+ * Extracts `entryPoint` from `context.settings.tailwindcss`.
836
+ */
837
+ function entryPointFromSettings(settings) {
838
+ const tw = settings?.tailwindcss;
839
+ if (tw && typeof tw === "object" && "entryPoint" in tw) {
840
+ const ep = tw.entryPoint;
841
+ if (typeof ep === "string") return ep;
842
+ }
843
+ }
844
+ /**
779
845
  * Returns the design system cache, loading synchronously on first call.
780
846
  * Uses execFileSync internally to bridge the async Tailwind API.
781
847
  * All rules receive the SAME instance.
848
+ *
849
+ * Resolution order: rule option `entryPoint` > `settings.tailwindcss.entryPoint` > auto-detect.
782
850
  */
783
- function getLoadedDesignSystem(entryPoint) {
784
- const cssPath = entryPoint ?? singleton?.path ?? autoDetectEntryPoint();
851
+ function getLoadedDesignSystem(entryPoint, settings, filePath) {
852
+ const cssPath = entryPoint ?? entryPointFromSettings(settings) ?? singleton?.path ?? autoDetectEntryPoint(filePath);
785
853
  if (!cssPath) return null;
786
854
  const resolvedPath = resolve(cssPath);
787
855
  try {
@@ -806,6 +874,36 @@ function getLoadedDesignSystem(entryPoint) {
806
874
  return null;
807
875
  }
808
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
+ }
809
907
  //#endregion
810
908
  //#region src/types.ts
811
909
  /**
@@ -851,22 +949,35 @@ const noUnknownClasses = defineRule({
851
949
  }
852
950
  },
853
951
  createOnce(context) {
854
- const options = safeOptions(context);
855
- const result = getLoadedDesignSystem(options?.entryPoint);
856
- if (!result) return {};
857
- const { cache } = result;
858
- const allowlist = new Set(options?.allowlist ?? []);
859
- 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
+ }
860
966
  function shouldIgnore(className) {
967
+ const { allowlist, ignorePrefixes } = getLazyOptions();
861
968
  if (allowlist.has(className)) return true;
862
969
  return ignorePrefixes.some((prefix) => className.startsWith(prefix));
863
970
  }
864
971
  function stripModifiers(className) {
865
972
  let stripped = className;
866
973
  if (stripped.startsWith("!")) stripped = stripped.slice(1);
974
+ if (stripped.endsWith("!")) stripped = stripped.slice(0, -1);
867
975
  return stripped;
868
976
  }
869
977
  function check(locations) {
978
+ const ds = getDS();
979
+ if (!ds) return;
980
+ const { cache } = ds;
870
981
  for (const loc of locations) {
871
982
  const classes = splitClasses(loc.value);
872
983
  for (const cls of classes) {
@@ -920,10 +1031,11 @@ const noConflictingClasses = defineRule({
920
1031
  messages: { conflict: "\"{{classA}}\" and \"{{classB}}\" affect {{properties}}. \"{{winner}}\" takes precedence (appears later)." }
921
1032
  },
922
1033
  createOnce(context) {
923
- const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint);
924
- if (!result) return {};
925
- const { cache } = result;
1034
+ const getDS = createLazyLoader(context);
926
1035
  function check(locations) {
1036
+ const ds = getDS();
1037
+ if (!ds) return;
1038
+ const { cache } = ds;
927
1039
  for (const loc of locations) {
928
1040
  const classes = splitClasses(loc.value);
929
1041
  if (classes.length < 2) continue;
@@ -938,7 +1050,9 @@ const noConflictingClasses = defineRule({
938
1050
  if (variantClasses.length < 2) continue;
939
1051
  const propsMap = /* @__PURE__ */ new Map();
940
1052
  for (const cls of variantClasses) {
941
- 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);
942
1056
  const props = cache.getCssProperties(utility);
943
1057
  propsMap.set(cls, props);
944
1058
  }
@@ -1007,29 +1121,51 @@ const noDeprecatedClasses = defineRule({
1007
1121
  messages: { deprecated: "\"{{className}}\" is deprecated in Tailwind v4. Use \"{{replacement}}\" instead." }
1008
1122
  },
1009
1123
  createOnce(context) {
1010
- const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint);
1124
+ const getDS = createLazyLoader(context);
1011
1125
  function check(locations) {
1126
+ const dsResult = getDS();
1012
1127
  for (const loc of locations) {
1013
1128
  const classes = splitClasses(loc.value);
1129
+ const offending = [];
1014
1130
  for (const cls of classes) {
1015
1131
  const { utility, variant } = splitUtilityAndVariant(cls);
1016
- 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];
1017
1136
  if (!replacement) continue;
1018
- if (result) {
1019
- const canonical = result.cache.canonicalize(utility);
1020
- if (canonical !== utility && canonical === replacement) {}
1137
+ if (dsResult) {
1138
+ const canonical = dsResult.cache.canonicalize(bareUtility);
1139
+ if (canonical !== bareUtility && canonical === replacement) {}
1021
1140
  }
1022
- const fullReplacement = variant + replacement;
1023
- 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({
1024
1153
  node: loc.node,
1025
1154
  messageId: "deprecated",
1026
1155
  data: {
1027
1156
  className: cls,
1028
- replacement: fullReplacement
1157
+ replacement
1029
1158
  },
1030
1159
  fix(fixer) {
1031
- const fixed = loc.value.replace(cls, fullReplacement);
1032
- 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
1033
1169
  }
1034
1170
  });
1035
1171
  }
@@ -1066,10 +1202,11 @@ const enforceCanonical = defineRule({
1066
1202
  messages: { nonCanonical: "\"{{className}}\" can be written as \"{{canonical}}\". Use the canonical form." }
1067
1203
  },
1068
1204
  createOnce(context) {
1069
- const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint);
1070
- if (!result) return {};
1071
- const { cache } = result;
1205
+ const getDS = createLazyLoader(context);
1072
1206
  function check(locations) {
1207
+ const ds = getDS();
1208
+ if (!ds) return;
1209
+ const { cache } = ds;
1073
1210
  for (const loc of locations) {
1074
1211
  const classes = splitClasses(loc.value);
1075
1212
  const canonicals = classes.map((cls) => cache.canonicalize(cls));
@@ -1140,60 +1277,63 @@ const enforceSortOrder = defineRule({
1140
1277
  messages: { unsorted: "Tailwind classes are not in the recommended order." }
1141
1278
  },
1142
1279
  createOnce(context) {
1143
- const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint);
1144
- if (!result) return {};
1145
- const { cache } = result;
1280
+ const getDS = createLazyLoader(context);
1146
1281
  let _mode = null;
1147
1282
  function getMode() {
1148
1283
  if (_mode === null) _mode = safeOptions(context)?.mode ?? "default";
1149
1284
  return _mode;
1150
1285
  }
1151
- function sortDefault(classes) {
1152
- return [...cache.getClassOrder(classes)].sort((a, b) => {
1153
- const orderA = a[1] ?? 0n;
1154
- const orderB = b[1] ?? 0n;
1155
- if (orderA < orderB) return -1;
1156
- if (orderA > orderB) return 1;
1157
- return 0;
1158
- }).map(([name]) => name);
1159
- }
1160
- function sortStrict(classes) {
1161
- const groups = /* @__PURE__ */ new Map();
1162
- const groupOrder = [];
1163
- for (const cls of classes) {
1164
- const { variant } = splitUtilityAndVariant(cls);
1165
- if (!groups.has(variant)) {
1166
- groups.set(variant, []);
1167
- groupOrder.push(variant);
1168
- }
1169
- groups.get(variant).push(cls);
1170
- }
1171
- for (const [, groupClasses] of groups) {
1172
- const ordered = cache.getClassOrder(groupClasses);
1173
- 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) => {
1174
1293
  const orderA = a[1] ?? 0n;
1175
1294
  const orderB = b[1] ?? 0n;
1176
1295
  if (orderA < orderB) return -1;
1177
1296
  if (orderA > orderB) return 1;
1178
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);
1179
1332
  });
1180
- groupClasses.length = 0;
1181
- 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;
1182
1336
  }
1183
- const sortedGroupKeys = [...groups.keys()].sort((a, b) => {
1184
- if (a === "" && b !== "") return -1;
1185
- if (a !== "" && b === "") return 1;
1186
- if (a === "" && b === "") return 0;
1187
- const variantA = a.slice(0, -1);
1188
- const variantB = b.slice(0, -1);
1189
- return (cache.getVariantPriority(variantA) ?? Number.MAX_SAFE_INTEGER) - (cache.getVariantPriority(variantB) ?? Number.MAX_SAFE_INTEGER);
1190
- });
1191
- const result = [];
1192
- for (const key of sortedGroupKeys) result.push(...groups.get(key));
1193
- return result;
1194
- }
1195
- function check(locations) {
1196
- const mode = getMode();
1197
1337
  for (const loc of locations) {
1198
1338
  const classes = splitClasses(loc.value);
1199
1339
  if (classes.length < 2) continue;
@@ -1298,20 +1438,28 @@ const enforceShorthand = defineRule({
1298
1438
  const classSet = new Set(classes);
1299
1439
  const values = /* @__PURE__ */ new Set();
1300
1440
  for (const cls of classes) {
1301
- 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);
1302
1443
  if (match) values.add(match[1]);
1303
1444
  }
1304
1445
  for (const value of values) {
1305
1446
  const rules = createShorthandRules(value);
1306
- for (const rule of rules) if (rule.parts.every((p) => classSet.has(p))) {
1307
- const remaining = classes.filter((c) => !rule.parts.includes(c));
1308
- 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}`);
1309
1457
  context.report({
1310
1458
  node: loc.node,
1311
1459
  messageId: "shorthand",
1312
1460
  data: {
1313
- parts: rule.parts.map((p) => `"${p}"`).join(", "),
1314
- replacement: rule.replacement
1461
+ parts: matchParts.map((p) => `"${p}"`).join(", "),
1462
+ replacement: `${importantStart}${rule.replacement}${importantEnd}`
1315
1463
  },
1316
1464
  fix(fixer) {
1317
1465
  return fixer.replaceTextRange(loc.range, preserveSpaces(loc, remaining.join(" ")));
@@ -1370,7 +1518,13 @@ const enforceLogical = defineRule({
1370
1518
  createOnce(context) {
1371
1519
  function convertClass(cls) {
1372
1520
  const { utility, variant } = splitUtilityAndVariant(cls);
1373
- 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
+ }
1374
1528
  return null;
1375
1529
  }
1376
1530
  function check(locations) {
@@ -1604,7 +1758,10 @@ const noArbitraryValue = defineRule({
1604
1758
  const classes = splitClasses(loc.value);
1605
1759
  for (const cls of classes) {
1606
1760
  if (!hasArbitraryValue(cls)) continue;
1607
- 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;
1608
1765
  context.report({
1609
1766
  node: loc.node,
1610
1767
  messageId: "noArbitrary",
@@ -1721,14 +1878,18 @@ const enforceConsistentImportantPosition = defineRule({
1721
1878
  //#region src/rules/enforce-negative-arbitrary-values.ts
1722
1879
  function fixClass(cls) {
1723
1880
  const { utility, variant } = splitUtilityAndVariant(cls);
1724
- if (!utility.startsWith("-")) return null;
1725
- 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("[");
1726
1886
  if (bracketOpen === -1) return null;
1727
- const bracketClose = utility.lastIndexOf("]");
1887
+ const bracketClose = bare.lastIndexOf("]");
1728
1888
  if (bracketClose === -1 || bracketClose < bracketOpen) return null;
1729
- const innerValue = utility.slice(bracketOpen + 1, bracketClose);
1889
+ const innerValue = bare.slice(bracketOpen + 1, bracketClose);
1730
1890
  if (innerValue.startsWith("-")) return null;
1731
- return `${variant}${utility.slice(1, bracketOpen)}[-${innerValue}]`;
1891
+ const baseUtility = bare.slice(1, bracketOpen);
1892
+ return `${variant}${hasImportantPrefix ? "!" : ""}${baseUtility}[-${innerValue}]${hasImportantSuffix ? "!" : ""}`;
1732
1893
  }
1733
1894
  /**
1734
1895
  * Detects `-utility-[value]` and suggests `utility-[-value]`.
@@ -1803,17 +1964,22 @@ const EXPLICIT_VAR_RE = /^([a-z][a-z0-9-]*(?:-[a-z0-9]+)*)-\[var\((--[a-zA-Z0-9-
1803
1964
  const SHORTHAND_VAR_RE = /^([a-z][a-z0-9-]*(?:-[a-z0-9]+)*)-\((--[a-zA-Z0-9-]+)\)$/;
1804
1965
  function convertClass(cls, syntax) {
1805
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 ? "!" : "";
1806
1972
  if (syntax === "shorthand") {
1807
- const match = EXPLICIT_VAR_RE.exec(utility);
1973
+ const match = EXPLICIT_VAR_RE.exec(bareUtility);
1808
1974
  if (match) {
1809
1975
  const [, prefix, varName] = match;
1810
- return `${variant}${prefix}-(${varName})`;
1976
+ return `${variant}${importantStart}${prefix}-(${varName})${importantEnd}`;
1811
1977
  }
1812
1978
  } else {
1813
- const match = SHORTHAND_VAR_RE.exec(utility);
1979
+ const match = SHORTHAND_VAR_RE.exec(bareUtility);
1814
1980
  if (match) {
1815
1981
  const [, prefix, varName] = match;
1816
- return `${variant}${prefix}-[var(${varName})]`;
1982
+ return `${variant}${importantStart}${prefix}-[var(${varName})]${importantEnd}`;
1817
1983
  }
1818
1984
  }
1819
1985
  return null;
@@ -1940,6 +2106,7 @@ const KNOWN_PREFIXES = [
1940
2106
  function getUtilityPrefix(utility) {
1941
2107
  let u = utility;
1942
2108
  if (u.startsWith("!")) u = u.slice(1);
2109
+ else if (u.endsWith("!")) u = u.slice(0, -1);
1943
2110
  if (u.startsWith("-")) u = u.slice(1);
1944
2111
  for (const prefix of KNOWN_PREFIXES) if (u === prefix || u.startsWith(`${prefix}-`)) return prefix;
1945
2112
  const dashIdx = u.indexOf("-");
@@ -2092,7 +2259,10 @@ const noHardcodedColors = defineRule({
2092
2259
  for (const cls of classes) {
2093
2260
  if (allowlist.has(cls)) continue;
2094
2261
  if (!hasArbitraryValue(cls)) continue;
2095
- 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;
2096
2266
  const value = getArbitraryValue(cls);
2097
2267
  if (!value) continue;
2098
2268
  if (isHardcodedColor(value)) context.report({
@@ -2276,17 +2446,19 @@ const consistentVariantOrder = defineRule({
2276
2446
  messages: { wrongOrder: "\"{{className}}\" has variants in wrong order. Use \"{{replacement}}\" instead." }
2277
2447
  },
2278
2448
  createOnce(context) {
2279
- const dsCache = getLoadedDesignSystem()?.cache ?? null;
2449
+ const getDS = createLazyLoader(context);
2280
2450
  let _config = null;
2281
2451
  function getConfig() {
2282
2452
  if (_config === null) {
2283
2453
  const options = safeOptions(context);
2454
+ const dsCache = getDS()?.cache ?? null;
2284
2455
  const priorityMap = /* @__PURE__ */ new Map();
2285
2456
  if (options?.order) {
2286
2457
  for (let i = 0; i < options.order.length; i++) priorityMap.set(options.order[i], i);
2287
2458
  _config = {
2288
2459
  priorityMap,
2289
- fallbackPriority: options.order.length
2460
+ fallbackPriority: options.order.length,
2461
+ dsCache
2290
2462
  };
2291
2463
  } else if (dsCache && dsCache.hasVariantOrder()) {
2292
2464
  for (const variant of DEFAULT_VARIANT_ORDER) {
@@ -2295,20 +2467,22 @@ const consistentVariantOrder = defineRule({
2295
2467
  }
2296
2468
  _config = {
2297
2469
  priorityMap,
2298
- fallbackPriority: Number.MAX_SAFE_INTEGER
2470
+ fallbackPriority: Number.MAX_SAFE_INTEGER,
2471
+ dsCache
2299
2472
  };
2300
2473
  } else {
2301
2474
  for (let i = 0; i < DEFAULT_VARIANT_ORDER.length; i++) priorityMap.set(DEFAULT_VARIANT_ORDER[i], i);
2302
2475
  _config = {
2303
2476
  priorityMap,
2304
- fallbackPriority: DEFAULT_VARIANT_ORDER.length
2477
+ fallbackPriority: DEFAULT_VARIANT_ORDER.length,
2478
+ dsCache
2305
2479
  };
2306
2480
  }
2307
2481
  }
2308
2482
  return _config;
2309
2483
  }
2310
2484
  function getVariantPriority(variant) {
2311
- const { priorityMap, fallbackPriority } = getConfig();
2485
+ const { priorityMap, fallbackPriority, dsCache } = getConfig();
2312
2486
  const priority = priorityMap.get(variant);
2313
2487
  if (priority !== void 0) return priority;
2314
2488
  if (dsCache && dsCache.hasVariantOrder()) {
@@ -2485,21 +2659,25 @@ const noUnnecessaryArbitraryValue = defineRule({
2485
2659
  messages: { unnecessaryArbitrary: "\"{{className}}\" can be written as \"{{replacement}}\". Use the named class instead." }
2486
2660
  },
2487
2661
  createOnce(context) {
2488
- const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint);
2489
- if (!result) return {};
2490
- const { cache } = result;
2662
+ const getDS = createLazyLoader(context);
2491
2663
  function check(locations) {
2664
+ const ds = getDS();
2665
+ if (!ds) return;
2666
+ const { cache } = ds;
2492
2667
  for (const loc of locations) {
2493
2668
  const classes = splitClasses(loc.value);
2494
2669
  const offending = [];
2495
2670
  for (const cls of classes) {
2496
2671
  if (!hasArbitraryValue(cls)) continue;
2497
2672
  const { utility, variant } = splitUtilityAndVariant(cls);
2498
- 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);
2499
2677
  if (!named) continue;
2500
2678
  offending.push({
2501
2679
  cls,
2502
- replacement: variant + named
2680
+ replacement: variant + (hasImportantPrefix ? "!" : "") + named + (hasImportantSuffix ? "!" : "")
2503
2681
  });
2504
2682
  }
2505
2683
  if (offending.length === 0) continue;