oxlint-tailwindcss 0.7.1 → 0.8.0

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
@@ -660,7 +660,7 @@ function getArbitraryValue(cls) {
660
660
  //#endregion
661
661
  //#region src/design-system/cache.ts
662
662
  /** Strip `!` modifier from start or end: `!flex` → `flex`, `flex!` → `flex` */
663
- function stripImportant(cls) {
663
+ function stripImportant$1(cls) {
664
664
  if (cls.startsWith("!")) return {
665
665
  bare: cls.slice(1),
666
666
  important: true
@@ -714,7 +714,7 @@ var DesignSystemCache = class DesignSystemCache {
714
714
  const canonicalUtility = this.canonicalMap.get(utility);
715
715
  if (canonicalUtility !== void 0) return className.slice(0, className.length - utility.length) + canonicalUtility;
716
716
  }
717
- const { bare, important } = stripImportant(utility);
717
+ const { bare, important } = stripImportant$1(utility);
718
718
  if (important) {
719
719
  const canonicalBare = this.canonicalMap.get(bare);
720
720
  if (canonicalBare !== void 0) {
@@ -772,7 +772,7 @@ var DesignSystemCache = class DesignSystemCache {
772
772
  if (this.validitySet.has(className)) return true;
773
773
  const utility = extractUtility(className);
774
774
  if (utility !== className && this.validitySet.has(utility)) return true;
775
- const { bare } = stripImportant(utility);
775
+ const { bare } = stripImportant$1(utility);
776
776
  if (bare !== utility && this.validitySet.has(bare)) return true;
777
777
  const slashIdx = bare.lastIndexOf("/");
778
778
  if (slashIdx > 0) {
@@ -796,7 +796,7 @@ var DesignSystemCache = class DesignSystemCache {
796
796
  const hasVariant = utility !== className;
797
797
  let baseOrder = this.orderMap.get(utility) ?? void 0;
798
798
  if (baseOrder === void 0) {
799
- const { bare, important } = stripImportant(utility);
799
+ const { bare, important } = stripImportant$1(utility);
800
800
  if (important) baseOrder = this.orderMap.get(bare) ?? void 0;
801
801
  }
802
802
  if (baseOrder === void 0) {
@@ -805,13 +805,13 @@ var DesignSystemCache = class DesignSystemCache {
805
805
  const base = utility.slice(0, slashIdx);
806
806
  baseOrder = this.orderMap.get(base) ?? void 0;
807
807
  if (baseOrder === void 0) {
808
- const { bare, important } = stripImportant(base);
808
+ const { bare, important } = stripImportant$1(base);
809
809
  if (important) baseOrder = this.orderMap.get(bare) ?? void 0;
810
810
  }
811
811
  }
812
812
  }
813
813
  if (baseOrder === void 0) {
814
- const stripped = stripImportant(utility).bare;
814
+ const stripped = stripImportant$1(utility).bare;
815
815
  const bracketIdx = stripped.indexOf("[");
816
816
  if (bracketIdx > 0) {
817
817
  const prefix = stripped.slice(0, bracketIdx);
@@ -819,7 +819,7 @@ var DesignSystemCache = class DesignSystemCache {
819
819
  }
820
820
  }
821
821
  if (baseOrder === void 0) {
822
- const stripped = stripImportant(utility).bare;
822
+ const stripped = stripImportant$1(utility).bare;
823
823
  const parenIdx = stripped.indexOf("(");
824
824
  if (parenIdx > 0) {
825
825
  const prefix = stripped.slice(0, parenIdx);
@@ -827,7 +827,7 @@ var DesignSystemCache = class DesignSystemCache {
827
827
  }
828
828
  }
829
829
  if (baseOrder === void 0) {
830
- const stripped = stripImportant(utility).bare;
830
+ const stripped = stripImportant$1(utility).bare;
831
831
  const numericMatch = /^(.+)-(\d+\.?\d*)$/.exec(stripped);
832
832
  if (numericMatch && this.getKnownPrefixes().has(numericMatch[1])) baseOrder = this.findOrderByPrefix(numericMatch[1] + "-");
833
833
  }
@@ -846,7 +846,7 @@ var DesignSystemCache = class DesignSystemCache {
846
846
  getCssProperties(className) {
847
847
  const result = this.cssPropsMap.get(className);
848
848
  if (result) return result;
849
- const { bare, important } = stripImportant(className);
849
+ const { bare, important } = stripImportant$1(className);
850
850
  if (important) return this.cssPropsMap.get(bare) ?? [];
851
851
  return [];
852
852
  }
@@ -859,7 +859,7 @@ var DesignSystemCache = class DesignSystemCache {
859
859
  getNamedEquivalent(className) {
860
860
  const result = this.arbitraryEquivMap.get(className);
861
861
  if (result) return result;
862
- const { bare, important } = stripImportant(className);
862
+ const { bare, important } = stripImportant$1(className);
863
863
  if (important) return this.arbitraryEquivMap.get(bare) ?? null;
864
864
  return null;
865
865
  }
@@ -1197,7 +1197,12 @@ async function main() {
1197
1197
  }
1198
1198
  }
1199
1199
 
1200
- // Arbitrary equivalents: map arbitrary forms to named equivalents
1200
+ // Arbitrary equivalents: map arbitrary forms to named equivalents.
1201
+ // Enumerate every dash split point so multi-segment utilities (e.g.
1202
+ // bg-card-foreground) emit candidates for every prefix; lastIndexOf
1203
+ // alone drops the shorter prefix and misses multi-segment mappings.
1204
+ // Start at indexOf('-', 1) so negative utilities (e.g. -translate-x-1)
1205
+ // keep their leading '-' in every prefix instead of producing '' + '-[…]'.
1201
1206
  const arbitraryEquivalents = {};
1202
1207
  const candidates = [];
1203
1208
  for (const cls of validClasses) {
@@ -1209,10 +1214,10 @@ async function main() {
1209
1214
  const pvMatch = cssText.match(/^\\s+([\\w-]+)\\s*:\\s*(.+?)\\s*;?\\s*$/m);
1210
1215
  if (!pvMatch) continue;
1211
1216
  const value = pvMatch[2].trim().replace(/;$/, '');
1212
- const lastDash = cls.lastIndexOf('-');
1213
- if (lastDash <= 0) continue;
1214
- const prefix = cls.slice(0, lastDash);
1215
- candidates.push({ arbitraryForm: prefix + '-[' + value + ']', namedCls: cls, namedCss: cssText });
1217
+ for (let dashPos = cls.indexOf('-', 1); dashPos > 0; dashPos = cls.indexOf('-', dashPos + 1)) {
1218
+ const prefix = cls.slice(0, dashPos);
1219
+ candidates.push({ arbitraryForm: prefix + '-[' + value + ']', namedCls: cls, namedCss: cssText });
1220
+ }
1216
1221
  }
1217
1222
  function extractDeclarations(css) {
1218
1223
  const openBrace = css.indexOf('{');
@@ -1236,7 +1241,37 @@ async function main() {
1236
1241
  main().catch(e => { process.stderr.write(e.message); process.exit(1); });
1237
1242
  `;
1238
1243
  const CACHE_DIR = join(tmpdir(), "oxlint-tailwindcss");
1239
- const CACHE_VERSION = 13;
1244
+ /**
1245
+ * Cache key derived from:
1246
+ * - md5(PRECOMPUTE_SCRIPT): auto-invalidates when our precompute logic changes,
1247
+ * since the shape and content of the cached JSON is fully determined by what
1248
+ * this script prints to stdout.
1249
+ * - @tailwindcss/node version: auto-invalidates when the consumer upgrades
1250
+ * tailwindcss (e.g. 4.2 → 4.3 adding `zoom-*`, `tab-*`, `scrollbar-*` etc.),
1251
+ * so `validClasses`, `cssProps`, `canonical`, and `arbitraryEquivalents`
1252
+ * reflect the installed version. @tailwindcss/node and tailwindcss are
1253
+ * published together, so their versions match.
1254
+ */
1255
+ function computeCacheKey(scriptContent, tailwindVersion) {
1256
+ return `${createHash("md5").update(scriptContent).digest("hex").slice(0, 8)}:${tailwindVersion}`;
1257
+ }
1258
+ function readTailwindVersion() {
1259
+ try {
1260
+ let dir = dirname(__require.resolve("@tailwindcss/node"));
1261
+ while (true) {
1262
+ const candidate = join(dir, "package.json");
1263
+ if (existsSync(candidate)) {
1264
+ const pkg = JSON.parse(readFileSync(candidate, "utf-8"));
1265
+ if (pkg.name === "@tailwindcss/node" && pkg.version) return pkg.version;
1266
+ }
1267
+ const parent = dirname(dir);
1268
+ if (parent === dir) break;
1269
+ dir = parent;
1270
+ }
1271
+ } catch {}
1272
+ return "unknown";
1273
+ }
1274
+ const CACHE_KEY = computeCacheKey(PRECOMPUTE_SCRIPT, readTailwindVersion());
1240
1275
  /**
1241
1276
  * Two-level disk cache for monorepo deduplication:
1242
1277
  *
@@ -1247,10 +1282,10 @@ const CACHE_VERSION = 13;
1247
1282
  * paths share a single content cache entry, avoiding redundant child process spawns.
1248
1283
  */
1249
1284
  function getMtimeIndexPath(cssPath, mtime) {
1250
- return join(CACHE_DIR, `${createHash("md5").update(`v${CACHE_VERSION}:${cssPath}:${mtime}`).digest("hex")}.idx`);
1285
+ return join(CACHE_DIR, `${createHash("md5").update(`${CACHE_KEY}:${cssPath}:${mtime}`).digest("hex")}.idx`);
1251
1286
  }
1252
1287
  function computeContentHash(content) {
1253
- return createHash("md5").update(`v${CACHE_VERSION}:${content}`).digest("hex");
1288
+ return createHash("md5").update(`${CACHE_KEY}:${content}`).digest("hex");
1254
1289
  }
1255
1290
  function getContentCachePath(contentHash) {
1256
1291
  return join(CACHE_DIR, `${contentHash}.json`);
@@ -1507,6 +1542,38 @@ function cachedAutoDetect(filePath) {
1507
1542
  return result;
1508
1543
  }
1509
1544
  /**
1545
+ * Pure resolution of which CSS entry point to use for a given context.
1546
+ *
1547
+ * Resolution order: rule option `entryPoint` > `settingsEntry` (string or
1548
+ * closest-of-array) > `autoDetect(filePath)` > `lastPath` fallback.
1549
+ *
1550
+ * Returns `isExplicit: true` when the result came from a rule option or
1551
+ * settings (not auto-detect / lastPath) — the caller uses this to decide
1552
+ * whether to update the shared `lastLoadedPath` fallback. Auto-detect
1553
+ * results never update the fallback (prevents cross-package contamination
1554
+ * in monorepos).
1555
+ *
1556
+ * `autoDetect` is injected for testability; in production it's
1557
+ * `cachedAutoDetect`. Pure: does not touch module state.
1558
+ */
1559
+ function resolveCssPath(args) {
1560
+ const { entryPoint, settingsEntry, filePath, lastPath, autoDetect } = args;
1561
+ const explicit = entryPoint ?? (Array.isArray(settingsEntry) ? resolveClosestEntryPoint(settingsEntry, filePath) : settingsEntry);
1562
+ if (explicit) return {
1563
+ path: explicit,
1564
+ isExplicit: true
1565
+ };
1566
+ const detected = autoDetect(filePath);
1567
+ if (detected) return {
1568
+ path: detected,
1569
+ isExplicit: false
1570
+ };
1571
+ return {
1572
+ path: lastPath ?? null,
1573
+ isExplicit: false
1574
+ };
1575
+ }
1576
+ /**
1510
1577
  * Returns the design system cache, loading synchronously on first call.
1511
1578
  * Uses execFileSync internally to bridge the async Tailwind API.
1512
1579
  *
@@ -1517,16 +1584,20 @@ function cachedAutoDetect(filePath) {
1517
1584
  * Resolution order: rule option `entryPoint` > `settings.tailwindcss.entryPoint` > auto-detect.
1518
1585
  */
1519
1586
  function getLoadedDesignSystem(entryPoint, settings, filePath) {
1520
- const settingsEntry = entryPointFromSettings(settings);
1521
- const explicitEntry = entryPoint ?? (Array.isArray(settingsEntry) ? resolveClosestEntryPoint(settingsEntry, filePath) : settingsEntry);
1522
- const cssPath = explicitEntry ?? cachedAutoDetect(filePath) ?? lastLoadedPath;
1587
+ const { path: cssPath, isExplicit } = resolveCssPath({
1588
+ entryPoint,
1589
+ settingsEntry: entryPointFromSettings(settings),
1590
+ filePath,
1591
+ lastPath: lastLoadedPath,
1592
+ autoDetect: cachedAutoDetect
1593
+ });
1523
1594
  if (!cssPath) return null;
1524
1595
  const resolvedPath = resolve(cssPath);
1525
1596
  try {
1526
1597
  const mtime = statSync(resolvedPath).mtimeMs;
1527
1598
  const cached = dsCache.get(resolvedPath);
1528
1599
  if (cached && cached.mtime === mtime) {
1529
- if (explicitEntry) lastLoadedPath = resolvedPath;
1600
+ if (isExplicit) lastLoadedPath = resolvedPath;
1530
1601
  return {
1531
1602
  cache: cached.cache,
1532
1603
  entryPoint: resolvedPath
@@ -1540,7 +1611,7 @@ function getLoadedDesignSystem(entryPoint, settings, filePath) {
1540
1611
  mtime
1541
1612
  });
1542
1613
  debugLog(`Loaded design system from "${resolvedPath}"`);
1543
- if (explicitEntry) lastLoadedPath = resolvedPath;
1614
+ if (isExplicit) lastLoadedPath = resolvedPath;
1544
1615
  return {
1545
1616
  cache,
1546
1617
  entryPoint: resolvedPath
@@ -1841,6 +1912,74 @@ const noUnknownClasses = defineRule({
1841
1912
  });
1842
1913
  //#endregion
1843
1914
  //#region src/rules/no-conflicting-classes.ts
1915
+ const COMPLEMENTARY_GROUPS = [
1916
+ /^(from|via|to)-/,
1917
+ /^(transition|duration|ease|delay)(?:-|$)/,
1918
+ /^-?(translate|scale|rotate|skew)-/,
1919
+ /^-?mask-((?:linear|radial|conic|[trblxy])(?:-(?:from|via|to|at))?)(?:-|$)/,
1920
+ /^prose(?:-|$)/
1921
+ ];
1922
+ const COMPOSITION_PAIRS = [
1923
+ [/^text-/, /^leading-/],
1924
+ [/^text-/, /^tracking-/],
1925
+ [/^border(?:-[0-9]|$)/, /^border-(?:solid|dashed|dotted|double|hidden|none)$/],
1926
+ [/^divide-/, /^border(?:-[trblxyse])?-/],
1927
+ [/^prose(?:-|$)/, /^max-w-/],
1928
+ [/^animate-in$/, /^(?:fade|spin|zoom|blur)-in(?:-|$)|^slide-in-from-/],
1929
+ [/^animate-out$/, /^(?:fade|spin|zoom|blur)-out(?:-|$)|^slide-out-to-/],
1930
+ [/^mask-(?:add|subtract|intersect|exclude)$/, /^-?mask-(?:linear|radial|conic|[trblxy])-/]
1931
+ ];
1932
+ function stripImportant(utility) {
1933
+ if (utility.startsWith("!")) return utility.slice(1);
1934
+ if (utility.endsWith("!")) return utility.slice(0, -1);
1935
+ return utility;
1936
+ }
1937
+ /**
1938
+ * Two utilities compose via CSS custom properties if both define their own
1939
+ * --tw-* properties that don't overlap — they each contribute to a shared
1940
+ * shorthand (e.g. `shadow` and `ring` both end up in `box-shadow` via
1941
+ * different intermediate vars).
1942
+ */
1943
+ function isCompositionViaCssVars(propsA, propsB) {
1944
+ const customA = propsA.filter((p) => p.startsWith("--"));
1945
+ const customB = propsB.filter((p) => p.startsWith("--"));
1946
+ if (customA.length === 0 || customB.length === 0) return false;
1947
+ return !customA.some((p) => customB.includes(p));
1948
+ }
1949
+ /**
1950
+ * Detect a narrowing override: the later class's CSS properties are a strict
1951
+ * subset of the earlier class's, so the later class refines one of the
1952
+ * shorthand's properties (size-4 h-6, rounded-t-lg rounded-tl-sm, truncate
1953
+ * text-clip). Direction-sensitive: the inverse means the wider later class
1954
+ * clobbers a prior narrower override.
1955
+ */
1956
+ function isNarrowingOverride(propsEarlier, propsLater) {
1957
+ if (propsLater.length === 0 || propsLater.length >= propsEarlier.length) return false;
1958
+ const setEarlier = new Set(propsEarlier);
1959
+ return propsLater.every((p) => setEarlier.has(p));
1960
+ }
1961
+ /**
1962
+ * Returns true if two classes (within the same variant) should NOT be reported
1963
+ * as conflicting despite sharing CSS properties. Pure: regex tables are passed
1964
+ * in (or default to the module-level constants).
1965
+ */
1966
+ function shouldSkipPair(a, b, propsA, propsB, rules = {}) {
1967
+ if (isCompositionViaCssVars(propsA, propsB)) return true;
1968
+ if (isNarrowingOverride(propsA, propsB)) return true;
1969
+ const ua = stripImportant(extractUtility(a));
1970
+ const ub = stripImportant(extractUtility(b));
1971
+ const groups = rules.complementaryGroups ?? COMPLEMENTARY_GROUPS;
1972
+ for (const re of groups) {
1973
+ const ma = ua.match(re);
1974
+ const mb = ub.match(re);
1975
+ if (!ma || !mb) continue;
1976
+ if (ma[1] === void 0) return true;
1977
+ if (ma[1] !== mb[1]) return true;
1978
+ }
1979
+ const pairs = rules.compositionPairs ?? COMPOSITION_PAIRS;
1980
+ for (const [reA, reB] of pairs) if (reA.test(ua) && reB.test(ub) || reA.test(ub) && reB.test(ua)) return true;
1981
+ return false;
1982
+ }
1844
1983
  const noConflictingClasses = defineRule({
1845
1984
  meta: {
1846
1985
  type: "problem",
@@ -1872,43 +2011,9 @@ const noConflictingClasses = defineRule({
1872
2011
  if (variantClasses.length < 2) continue;
1873
2012
  const propsMap = /* @__PURE__ */ new Map();
1874
2013
  for (const cls of variantClasses) {
1875
- let utility = extractUtility(cls);
1876
- if (utility.startsWith("!")) utility = utility.slice(1);
1877
- else if (utility.endsWith("!")) utility = utility.slice(0, -1);
1878
- const props = cache.getCssProperties(utility);
2014
+ const props = cache.getCssProperties(stripImportant(extractUtility(cls)));
1879
2015
  propsMap.set(cls, props);
1880
2016
  }
1881
- const COMPLEMENTARY_GROUPS = [
1882
- /^(?:from|via|to)-/,
1883
- /^(?:transition|duration|ease|delay)(?:-|$)/,
1884
- /^-?(?:translate|scale|rotate|skew)-/,
1885
- /^prose(?:-|$)/
1886
- ];
1887
- const COMPOSITION_PAIRS = [
1888
- [/^text-/, /^leading-/],
1889
- [/^text-/, /^tracking-/],
1890
- [/^border(?:-[0-9]|$)/, /^border-(?:solid|dashed|dotted|double|hidden|none)$/],
1891
- [/^divide-/, /^border(?:-[trblxyse])?-/],
1892
- [/^prose(?:-|$)/, /^max-w-/]
1893
- ];
1894
- function isCompositionViaCssVars(propsA, propsB) {
1895
- const customA = propsA.filter((p) => p.startsWith("--"));
1896
- const customB = propsB.filter((p) => p.startsWith("--"));
1897
- if (customA.length === 0 || customB.length === 0) return false;
1898
- return !customA.some((p) => customB.includes(p));
1899
- }
1900
- function shouldSkipPair(a, b, propsA, propsB) {
1901
- if (isCompositionViaCssVars(propsA, propsB)) return true;
1902
- let ua = extractUtility(a);
1903
- let ub = extractUtility(b);
1904
- if (ua.startsWith("!")) ua = ua.slice(1);
1905
- else if (ua.endsWith("!")) ua = ua.slice(0, -1);
1906
- if (ub.startsWith("!")) ub = ub.slice(1);
1907
- else if (ub.endsWith("!")) ub = ub.slice(0, -1);
1908
- for (const re of COMPLEMENTARY_GROUPS) if (re.test(ua) && re.test(ub)) return true;
1909
- for (const [reA, reB] of COMPOSITION_PAIRS) if (reA.test(ua) && reB.test(ub) || reA.test(ub) && reB.test(ua)) return true;
1910
- return false;
1911
- }
1912
2017
  for (let i = 0; i < variantClasses.length; i++) {
1913
2018
  const classA = variantClasses[i];
1914
2019
  const propsA = propsMap.get(classA) ?? [];
@@ -3419,8 +3524,10 @@ const LCH_RE = /^lch\s*\(/;
3419
3524
  const LAB_RE = /^lab\s*\(/;
3420
3525
  const HWB_RE = /^hwb\s*\(/;
3421
3526
  const COLOR_RE = /^color\s*\(/;
3527
+ const VAR_REF_RE = /var\(\s*--[\w-]+/i;
3422
3528
  function isHardcodedColor(value) {
3423
3529
  const trimmed = value.trim();
3530
+ if (VAR_REF_RE.test(trimmed)) return false;
3424
3531
  return HEX_RE.test(trimmed) || RGB_RE.test(trimmed) || HSL_RE.test(trimmed) || OKLCH_RE.test(trimmed) || OKLAB_RE.test(trimmed) || LCH_RE.test(trimmed) || LAB_RE.test(trimmed) || HWB_RE.test(trimmed) || COLOR_RE.test(trimmed);
3425
3532
  }
3426
3533
  function isColorUtility(utility) {