oxlint-tailwindcss 1.8.0 → 1.10.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.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- //#region ../../node_modules/.pnpm/@oxlint+plugins@1.77.0/node_modules/@oxlint/plugins/index.d.ts
1
+ //#region ../../node_modules/.pnpm/@oxlint+plugins@1.78.0/node_modules/@oxlint/plugins/index.d.ts
2
2
  //#endregion
3
3
  //#region src-js/plugins/tokens.d.ts
4
4
  /**
@@ -1599,6 +1599,7 @@ interface TSTypePredicate extends Span {
1599
1599
  parent: Node$1;
1600
1600
  }
1601
1601
  type TSTypePredicateName = IdentifierName | TSThisType;
1602
+ type TSModuleDeclarationKind = "module" | "namespace";
1602
1603
  interface TSModuleDeclaration extends Span {
1603
1604
  type: "TSModuleDeclaration";
1604
1605
  id: BindingIdentifier | StringLiteral | TSQualifiedName;
@@ -1608,7 +1609,6 @@ interface TSModuleDeclaration extends Span {
1608
1609
  global: false;
1609
1610
  parent: Node$1;
1610
1611
  }
1611
- type TSModuleDeclarationKind = "module" | "namespace";
1612
1612
  interface TSGlobalDeclaration extends Span {
1613
1613
  type: "TSModuleDeclaration";
1614
1614
  id: IdentifierName;
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { Worker, threadId } from "node:worker_threads";
3
3
  import { createHash } from "node:crypto";
4
- import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
4
+ import { closeSync, existsSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
5
5
  import { dirname, isAbsolute, join, relative, resolve } from "node:path";
6
6
  import { tmpdir, userInfo } from "node:os";
7
7
  //#region \0rolldown/runtime.js
8
8
  var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
9
9
  //#endregion
10
- //#region ../../node_modules/.pnpm/@oxlint+plugins@1.77.0/node_modules/@oxlint/plugins/index.js
10
+ //#region ../../node_modules/.pnpm/@oxlint+plugins@1.78.0/node_modules/@oxlint/plugins/index.js
11
11
  /**
12
12
  * Define a plugin.
13
13
  *
@@ -94,6 +94,21 @@ function matchesAny(value, list) {
94
94
  //#endregion
95
95
  //#region src/utils/extractors.ts
96
96
  /**
97
+ * Whether this string is the element's FINAL, self-contained class list — the
98
+ * only position where a RELATIONAL rule (one whose verdict for a class depends
99
+ * on the OTHER classes in the string) can decide safely. Everywhere else the
100
+ * string may be an override FRAGMENT merged at runtime — by `cn`/`twMerge`/
101
+ * `cva`, or inside a custom component — with classes contributed in another
102
+ * argument or another module, where claims like "the base already applies
103
+ * unconditionally" or "there is no light base" are undecidable without
104
+ * emulating tailwind-merge (issue #117). The two relational rules
105
+ * (`no-contradicting-variants`, `no-dark-without-light`) gate on this; it is
106
+ * the single home for that decision so it can't drift between them.
107
+ */
108
+ function isFinalClassList(loc) {
109
+ return loc.origin === "jsx-native";
110
+ }
111
+ /**
97
112
  * Preserves leading/trailing spaces in fixed class strings for template literals.
98
113
  * Without this, `h-3 w-3 ${x}` fixed to `size-3${x}` would break classes.
99
114
  */
@@ -195,6 +210,32 @@ function createExtractorVisitors(context, check) {
195
210
  };
196
211
  }
197
212
  /**
213
+ * Stamps every location with its extraction origin and returns the array.
214
+ * Origin is set once at each of the 4 entry points, so the recursive
215
+ * `extractFromExpression` helpers stay origin-agnostic.
216
+ */
217
+ function withOrigin(locations, origin) {
218
+ for (const loc of locations) loc.origin = origin;
219
+ return locations;
220
+ }
221
+ const NATIVE_JSX_TAG = /^[a-z]/;
222
+ /**
223
+ * Classifies the JSX host element of an attribute as a native (lowercase) host
224
+ * — where the `className` literal IS the element's final class list — or a
225
+ * custom component, where the string is opaque (it may be re-merged inside the
226
+ * component with `cva`/`twMerge`). Conservative: unknown parent shapes →
227
+ * component, so a relational rule under-reports rather than emitting a false
228
+ * positive.
229
+ */
230
+ function jsxHostOrigin(node) {
231
+ const parent = node.parent;
232
+ if (parent && parent.type === "JSXOpeningElement") {
233
+ const elementName = parent.name;
234
+ if (elementName.type === "JSXIdentifier" && NATIVE_JSX_TAG.test(elementName.name)) return "jsx-native";
235
+ }
236
+ return "jsx-component";
237
+ }
238
+ /**
198
239
  * Extracts class locations from a JSXAttribute node.
199
240
  * Handles: className="...", className={`...`}, className={cond ? "..." : "..."}
200
241
  */
@@ -202,15 +243,17 @@ function extractFromJSXAttribute(node, config = DEFAULT_EXTRACTOR_CONFIG) {
202
243
  const name = node.name.type === "JSXIdentifier" ? node.name.name : void 0;
203
244
  if (!name || !config.attributes.includes(name)) return [];
204
245
  if (!node.value) return [];
246
+ const hostOrigin = jsxHostOrigin(node);
205
247
  if (node.value.type === "Literal" && typeof node.value.value === "string") return [{
206
248
  value: node.value.value,
207
249
  node: node.value,
208
- range: [node.value.range[0] + 1, node.value.range[1] - 1]
250
+ range: [node.value.range[0] + 1, node.value.range[1] - 1],
251
+ origin: hostOrigin
209
252
  }];
210
253
  if (node.value.type === "JSXExpressionContainer") {
211
254
  const expr = node.value.expression;
212
- if (expr.type === "ObjectExpression") return extractObjectValues(expr);
213
- return extractFromExpression(expr);
255
+ if (expr.type === "ObjectExpression") return withOrigin(extractObjectValues(expr), "jsx-object");
256
+ return withOrigin(extractFromExpression(expr), hostOrigin);
214
257
  }
215
258
  return [];
216
259
  }
@@ -221,12 +264,12 @@ function extractFromJSXAttribute(node, config = DEFAULT_EXTRACTOR_CONFIG) {
221
264
  function extractFromCallExpression(node, config = DEFAULT_EXTRACTOR_CONFIG) {
222
265
  const calleeName = getCalleeName(node.callee);
223
266
  if (!calleeName || !config.callees.includes(calleeName)) return [];
224
- if (calleeName === "cva") return extractFromCvaCall(node);
225
- if (calleeName === "tv") return extractFromTvCall(node);
226
- if (calleeName === "classed") return extractFromClassedCall(node);
267
+ if (calleeName === "cva") return withOrigin(extractFromCvaCall(node), "callee");
268
+ if (calleeName === "tv") return withOrigin(extractFromTvCall(node), "callee");
269
+ if (calleeName === "classed") return withOrigin(extractFromClassedCall(node), "callee");
227
270
  const results = [];
228
271
  for (const arg of node.arguments) extractFromExpression(arg, results);
229
- return results;
272
+ return withOrigin(results, "callee");
230
273
  }
231
274
  /**
232
275
  * Extracts class locations from a TaggedTemplateExpression (tw`...`).
@@ -234,7 +277,7 @@ function extractFromCallExpression(node, config = DEFAULT_EXTRACTOR_CONFIG) {
234
277
  function extractFromTaggedTemplate(node, config = DEFAULT_EXTRACTOR_CONFIG) {
235
278
  const tagName = getCalleeName(node.tag);
236
279
  if (!tagName || !config.tags.includes(tagName)) return [];
237
- return extractFromTemplateLiteral(node.quasi);
280
+ return withOrigin(extractFromTemplateLiteral(node.quasi), "template-tag");
238
281
  }
239
282
  /**
240
283
  * Extracts class string values from an ObjectExpression in a JSX attribute.
@@ -371,7 +414,7 @@ function extractFromVariableDeclarator(node, config = DEFAULT_EXTRACTOR_CONFIG)
371
414
  if (node.id.type !== "Identifier") return [];
372
415
  if (!config.variablePatterns.some((p) => p.test(node.id.name))) return [];
373
416
  if (!node.init) return [];
374
- return extractFromExpression(node.init);
417
+ return withOrigin(extractFromExpression(node.init), "variable");
375
418
  }
376
419
  /**
377
420
  * Walk an expression and append every class-bearing location to `out`.
@@ -1581,6 +1624,14 @@ var DeprecatedEntryPointShapeError = class extends OxlintTailwindError {};
1581
1624
  var DesignSystemLoadError = class extends OxlintTailwindError {};
1582
1625
  /** The sort or canonicalize worker thread failed to initialize or timed out. */
1583
1626
  var SortServiceError = class extends OxlintTailwindError {};
1627
+ /**
1628
+ * The resolved Tailwind engine version is outside the range this plugin
1629
+ * supports: older than v4, a future major (v5+) the plugin was not built for,
1630
+ * or a major-version drift from the version the consumer's build compiles
1631
+ * with. Fail-loud rather than lint against semantics that don't match the
1632
+ * build. See `design-system/engine-guard.ts` for the decision table.
1633
+ */
1634
+ var UnsupportedEngineError = class extends OxlintTailwindError {};
1584
1635
  /** Type-guard: did this error originate from the plugin's fail-loud infrastructure? */
1585
1636
  function isFatalError(err) {
1586
1637
  return err instanceof OxlintTailwindError;
@@ -1651,28 +1702,54 @@ function softGetDS(getDS) {
1651
1702
  //#endregion
1652
1703
  //#region src/design-system/tailwind-node.ts
1653
1704
  /**
1654
- * Single source of truth for the resolved `@tailwindcss/node` entry path
1655
- * and its installed version. Three call sites (sync-loader, sort-service,
1656
- * canonicalize-service) used to each call `require.resolve` independently
1657
- * — this module resolves once at load and exposes the results.
1705
+ * Resolves the Tailwind engine (`@tailwindcss/node`) the plugin runs against.
1706
+ *
1707
+ * Two layers:
1658
1708
  *
1659
- * The version is read from `dist/../package.json` (the published layout)
1660
- * with a walk-up fallback for unconventional installs.
1709
+ * 1. **Bundled fallback** — `TAILWIND_NODE_PATH` / `TAILWIND_NODE_VERSION`,
1710
+ * resolved ONCE at module load from the plugin's own location. This is the
1711
+ * copy shipped as a dependency; used only when the consumer's engine can't
1712
+ * be found.
1713
+ * 2. **Per-entry-point resolution** — `resolveTailwindNodeFor(cssPath)`
1714
+ * resolves the engine from the CONSUMER's project (the `node_modules` around
1715
+ * the resolved CSS entry point), so the linter analyzes with the same
1716
+ * Tailwind the build compiles with (issue #114). Memoized per CSS directory;
1717
+ * a pure function of the on-disk module topology, so every layer
1718
+ * (precompute, live worker services, disk-cache key) that is handed the same
1719
+ * `cssPath` independently agrees on the same engine — no cross-layer
1720
+ * threading required.
1721
+ *
1722
+ * Versions are read from the resolved entry's `package.json` (walk-up
1723
+ * fallback for unconventional layouts).
1661
1724
  */
1662
- function resolveTailwindNodePath() {
1725
+ function tryResolveFrom(specifier, fromDir) {
1663
1726
  try {
1664
- return __require.resolve("@tailwindcss/node");
1727
+ return __require.resolve(specifier, { paths: [fromDir] });
1665
1728
  } catch {
1666
1729
  return null;
1667
1730
  }
1668
1731
  }
1669
- function readVersionFromEntry(entryPath) {
1732
+ function realpathOr(p) {
1733
+ try {
1734
+ return realpathSync(p);
1735
+ } catch {
1736
+ return p;
1737
+ }
1738
+ }
1739
+ /**
1740
+ * Read the `version` from the `package.json` for `name`, starting at
1741
+ * `dirname(entryPath)` and walking up a few levels (packages ship their entry
1742
+ * as `dist/index.{cjs,mjs}` next to the `package.json`, but layouts vary).
1743
+ * The `pkg.name === name` guard backstops a wrong `package.json` found mid-walk
1744
+ * (e.g. through a pnpm symlink). Returns `'unknown'` if nothing matches.
1745
+ */
1746
+ function readVersionFromEntry(entryPath, name) {
1670
1747
  let dir = dirname(entryPath);
1671
1748
  for (let i = 0; i < 5; i++) {
1672
1749
  const pkgJson = join(dir, "package.json");
1673
1750
  if (existsSync(pkgJson)) try {
1674
1751
  const pkg = JSON.parse(readFileSync(pkgJson, "utf-8"));
1675
- if (pkg.name === "@tailwindcss/node" && pkg.version) return pkg.version;
1752
+ if (pkg.name === name && pkg.version) return pkg.version;
1676
1753
  } catch {}
1677
1754
  const parent = dirname(dir);
1678
1755
  if (parent === dir) break;
@@ -1680,21 +1757,93 @@ function readVersionFromEntry(entryPath) {
1680
1757
  }
1681
1758
  return "unknown";
1682
1759
  }
1683
- const entryPath = resolveTailwindNodePath();
1760
+ const bundledEntry = resolveBundledEntry();
1761
+ function resolveBundledEntry() {
1762
+ try {
1763
+ return __require.resolve("@tailwindcss/node");
1764
+ } catch {
1765
+ return null;
1766
+ }
1767
+ }
1684
1768
  /**
1685
- * Absolute path to `@tailwindcss/node`'s main entry, or `null` if not
1686
- * installed. Workers receive this path via workerData; the parent does
1687
- * the resolution because module resolution from a child process's `eval`
1688
- * context (with cwd inside a tmp dir or under pnpm strict workspaces) can
1689
- * fail to find the bare specifier.
1769
+ * Absolute entry of the plugin's own bundled `@tailwindcss/node`, or `null`
1770
+ * if not installed. Used as the last-resort fallback by
1771
+ * `resolveTailwindNodeFor` and passed to workers, which resolve the bare
1772
+ * specifier from a tmp-dir `eval` context (where it would otherwise fail).
1690
1773
  */
1691
- const TAILWIND_NODE_PATH = entryPath;
1774
+ const TAILWIND_NODE_PATH = bundledEntry;
1692
1775
  /**
1693
- * Installed `@tailwindcss/node` version, or `'unknown'`. Used as part of
1694
- * the disk-cache key in sync-loader so cached precompute output is
1695
- * invalidated when the consumer upgrades.
1776
+ * Installed version of the plugin's bundled `@tailwindcss/node`, or
1777
+ * `'unknown'`. This is the version the plugin was built and tested against;
1778
+ * `engine-guard` uses it as the "tested ceiling".
1696
1779
  */
1697
- const TAILWIND_NODE_VERSION = entryPath !== null ? readVersionFromEntry(entryPath) : "unknown";
1780
+ const TAILWIND_NODE_VERSION = bundledEntry !== null ? readVersionFromEntry(bundledEntry, "@tailwindcss/node") : "unknown";
1781
+ const BUILD_TOOL_SPECIFIERS = [
1782
+ "@tailwindcss/postcss",
1783
+ "@tailwindcss/vite",
1784
+ "@tailwindcss/cli"
1785
+ ];
1786
+ /**
1787
+ * The real directories of the consumer's Tailwind build tools, resolved from
1788
+ * the CSS dir. Under pnpm's strict layout `@tailwindcss/node` is only a
1789
+ * transitive dep (not symlinked into the package's `node_modules`), so it is
1790
+ * unreachable from the CSS dir directly — but it IS reachable from the build
1791
+ * tool's own real directory. `realpathSync` follows the pnpm symlink to the
1792
+ * virtual store before we resolve `@tailwindcss/node` relative to it.
1793
+ */
1794
+ function buildToolAnchorDirs(cssDir) {
1795
+ const dirs = [];
1796
+ for (const spec of BUILD_TOOL_SPECIFIERS) {
1797
+ const entry = tryResolveFrom(spec, cssDir);
1798
+ if (entry) dirs.push(dirname(realpathOr(entry)));
1799
+ }
1800
+ return dirs;
1801
+ }
1802
+ const resolutionCache = /* @__PURE__ */ new Map();
1803
+ /**
1804
+ * Resolve the Tailwind engine to run for a given resolved CSS entry point,
1805
+ * anchored on the consumer's project. Memoized per CSS directory.
1806
+ *
1807
+ * Cascade:
1808
+ * 1. `buildVersion` (B) — the consumer's `tailwindcss` resolved from the CSS
1809
+ * dir. Always a direct dep, so it resolves under npm (hoisted) and pnpm
1810
+ * (symlinked into the package). `'unknown'` if the project has no Tailwind.
1811
+ * 2. `nodePath` (E) — the first `@tailwindcss/node` resolvable from
1812
+ * `[cssDir, ...buildToolAnchorDirs]`, preferring the copy whose version
1813
+ * equals `buildVersion` so a hoisted plugin copy can't shadow the
1814
+ * consumer's engine (R2). Falls back to the bundled copy.
1815
+ *
1816
+ * Never throws; degrades to `'unknown'` / bundled so the version guard (not
1817
+ * this function) owns the fail-loud decision.
1818
+ */
1819
+ function resolveTailwindNodeFor(cssPath) {
1820
+ const cssDir = dirname(resolve(cssPath));
1821
+ const cached = resolutionCache.get(cssDir);
1822
+ if (cached) return cached;
1823
+ const twEntry = tryResolveFrom("tailwindcss", cssDir);
1824
+ const buildVersion = twEntry ? readVersionFromEntry(twEntry, "tailwindcss") : "unknown";
1825
+ const candidates = [];
1826
+ for (const dir of [cssDir, ...buildToolAnchorDirs(cssDir)]) {
1827
+ const found = tryResolveFrom("@tailwindcss/node", dir);
1828
+ if (!found) continue;
1829
+ const real = realpathOr(found);
1830
+ if (!candidates.includes(real)) candidates.push(real);
1831
+ }
1832
+ let nodePath = null;
1833
+ if (buildVersion !== "unknown") nodePath = candidates.find((c) => readVersionFromEntry(c, "@tailwindcss/node") === buildVersion) ?? null;
1834
+ if (nodePath === null) nodePath = candidates[0] ?? null;
1835
+ if (nodePath === null) nodePath = TAILWIND_NODE_PATH;
1836
+ const usedBundled = nodePath !== null && TAILWIND_NODE_PATH !== null && realpathOr(nodePath) === realpathOr(TAILWIND_NODE_PATH);
1837
+ const nodeVersion = nodePath !== null ? readVersionFromEntry(realpathOr(nodePath), "@tailwindcss/node") : "unknown";
1838
+ const result = {
1839
+ nodePath,
1840
+ nodeVersion,
1841
+ buildVersion,
1842
+ usedBundled
1843
+ };
1844
+ resolutionCache.set(cssDir, result);
1845
+ return result;
1846
+ }
1698
1847
  //#endregion
1699
1848
  //#region src/design-system/sync-loader.ts
1700
1849
  /**
@@ -1722,7 +1871,7 @@ const TAILWIND_NODE_VERSION = entryPath !== null ? readVersionFromEntry(entryPat
1722
1871
  * `tests/benchmarks/precompute-phases.test.ts` used to keep a hand-copied
1723
1872
  * duplicate of the extractor that silently drifted from the real one, and it is
1724
1873
  * interpolated (not concatenated at runtime), so its text still feeds the
1725
- * `CACHE_KEY` md5 and any edit here invalidates the disk cache automatically.
1874
+ * `SCRIPT_HASH` md5 and any edit here invalidates the disk cache automatically.
1726
1875
  *
1727
1876
  * Exports (in the worker scope): `walkDeclarations`, `scanVarReads`,
1728
1877
  * `isPureVarRead`.
@@ -2625,23 +2774,20 @@ function cacheDirName() {
2625
2774
  }
2626
2775
  }
2627
2776
  const CACHE_DIR = join(tmpdir(), cacheDirName());
2777
+ /** md5 of the precompute script (no version) — the version is folded in per entry point. */
2778
+ const SCRIPT_HASH = createHash("md5").update(PRECOMPUTE_SCRIPT).digest("hex").slice(0, 8);
2628
2779
  /**
2629
- * Cache key derived from:
2630
- * - md5(PRECOMPUTE_SCRIPT): auto-invalidates when our precompute logic changes,
2631
- * since the shape and content of the cached JSON is fully determined by what
2632
- * this script prints to stdout.
2633
- * - @tailwindcss/node version: auto-invalidates when the consumer upgrades
2634
- * tailwindcss (e.g. 4.2 → 4.3 adding `zoom-*`, `tab-*`, `scrollbar-*` etc.),
2635
- * so `validClasses`, `cssProps`, `canonical`, and `arbitraryEquivalents`
2636
- * reflect the installed version. @tailwindcss/node and tailwindcss are
2637
- * published together, so their versions match.
2780
+ * The engine identifier folded into the content hash. Normally the resolved
2781
+ * `@tailwindcss/node` version; when that is `'unknown'` (unreadable
2782
+ * `package.json`) two genuinely different engines would both hash as `unknown`,
2783
+ * so tiebreak on the resolved path (machine-local, but the disk cache is
2784
+ * per-uid/per-machine anyway, and under pnpm the path encodes the version).
2638
2785
  */
2639
- function computeCacheKey(scriptContent, tailwindVersion) {
2640
- return `${createHash("md5").update(scriptContent).digest("hex").slice(0, 8)}:${tailwindVersion}`;
2786
+ function engineCacheKey(res) {
2787
+ return res.nodeVersion === "unknown" && res.nodePath !== null ? `unknown@${res.nodePath}` : res.nodeVersion;
2641
2788
  }
2642
- const CACHE_KEY = computeCacheKey(PRECOMPUTE_SCRIPT, TAILWIND_NODE_VERSION);
2643
- function computeContentHash(content) {
2644
- return createHash("md5").update(`${CACHE_KEY}:${content}`).digest("hex");
2789
+ function computeContentHash(content, engineVersion) {
2790
+ return createHash("md5").update(`${SCRIPT_HASH}:${engineVersion}:${content}`).digest("hex");
2645
2791
  }
2646
2792
  const IMPORT_RE = /@import\s+(?:url\(\s*)?['"]([^'"]+)['"]/g;
2647
2793
  /**
@@ -2653,7 +2799,7 @@ const IMPORT_RE = /@import\s+(?:url\(\s*)?['"]([^'"]+)['"]/g;
2653
2799
  *
2654
2800
  * Resolves RELATIVE imports (`./`, `../`) recursively up to a small depth;
2655
2801
  * package imports (`@import "tailwindcss"`, `tw-animate-css`) are already
2656
- * covered by the `@tailwindcss/node` version baked into CACHE_KEY. Best-effort:
2802
+ * covered by the engine version folded into the content hash. Best-effort:
2657
2803
  * an unreadable import contributes nothing (it can't affect the DS either).
2658
2804
  */
2659
2805
  function hashableContent(entryPath, entryContent) {
@@ -2693,7 +2839,9 @@ function getContentCachePath(contentHash) {
2693
2839
  */
2694
2840
  function cacheArtifactPaths(cssPath) {
2695
2841
  const resolved = resolve(cssPath);
2696
- const hash = computeContentHash(hashableContent(resolved, readFileSync(resolved, "utf-8")));
2842
+ const content = readFileSync(resolved, "utf-8");
2843
+ const res = resolveTailwindNodeFor(resolved);
2844
+ const hash = computeContentHash(hashableContent(resolved, content), engineCacheKey(res));
2697
2845
  return {
2698
2846
  json: getContentCachePath(hash),
2699
2847
  lock: join(CACHE_DIR, `${hash}.lock`)
@@ -2903,12 +3051,13 @@ function loadDesignSystemSync(cssPath, timeout) {
2903
3051
  } catch (cause) {
2904
3052
  throw new DesignSystemLoadError(`Could not read CSS entry point: ${resolvedPath}`, "Verify the path resolves from the oxlint working directory and the file is readable.", { cause: cause instanceof Error ? cause : void 0 });
2905
3053
  }
2906
- const contentHash = computeContentHash(hashableContent(resolvedPath, content));
3054
+ const engine = resolveTailwindNodeFor(resolvedPath);
3055
+ const contentHash = computeContentHash(hashableContent(resolvedPath, content), engineCacheKey(engine));
2907
3056
  const contentCachePath = getContentCachePath(contentHash);
2908
3057
  const cached = tryReadCache(contentCachePath);
2909
3058
  if (cached) return cached;
2910
- if (TAILWIND_NODE_PATH === null) throw new DesignSystemLoadError(`Could not resolve '@tailwindcss/node' while loading "${resolvedPath}".`, "Install '@tailwindcss/node' (or upgrade oxlint-tailwindcss) and re-run.");
2911
- return computeWithLock(resolvedPath, TAILWIND_NODE_PATH, contentHash, contentCachePath, timeout ?? 6e4);
3059
+ if (engine.nodePath === null) throw new DesignSystemLoadError(`Could not resolve '@tailwindcss/node' while loading "${resolvedPath}".`, "Install '@tailwindcss/node' (or upgrade oxlint-tailwindcss) and re-run.");
3060
+ return computeWithLock(resolvedPath, engine.nodePath, contentHash, contentCachePath, timeout ?? 6e4);
2912
3061
  }
2913
3062
  //#endregion
2914
3063
  //#region src/design-system/debug.ts
@@ -2939,6 +3088,207 @@ function debugLog(message) {
2939
3088
  if (_enabled || process.env.DEBUG === "oxlint-tailwindcss") console.error(`${PREFIX} ${message}`);
2940
3089
  }
2941
3090
  //#endregion
3091
+ //#region src/design-system/engine-guard.ts
3092
+ /**
3093
+ * Version safeguards for the consumer-resolved Tailwind engine.
3094
+ *
3095
+ * Once the plugin loads the CONSUMER's Tailwind (`resolveTailwindNodeFor`),
3096
+ * two version facts matter per entry point:
3097
+ *
3098
+ * - `E` — the `@tailwindcss/node` version the plugin will actually run.
3099
+ * - `B` — the `tailwindcss` version the consumer's build compiles with.
3100
+ *
3101
+ * `assessEngine` grades `(E, B)` against the plugin's supported range and the
3102
+ * drift between the two, returning `ok` / `warn` / `fatal`. `emitEngineVerdict`
3103
+ * turns a `fatal` into an `UnsupportedEngineError` (which the fatal-reporter
3104
+ * routes to `designSystemUnavailable` with no per-rule `meta` change) and a
3105
+ * `warn` into a one-time stderr notice.
3106
+ *
3107
+ * The comparator is a hand-rolled subset of semver (no `semver` dependency —
3108
+ * runtime deps stay `@tailwindcss/node` + `tailwindcss` only). It is total and
3109
+ * never throws; unparseable input reads as "unknown".
3110
+ */
3111
+ const WARN_PREFIX = "[oxlint-tailwindcss]";
3112
+ /** The lowest Tailwind major this plugin supports. */
3113
+ const SUPPORTED_MAJOR = 4;
3114
+ /**
3115
+ * `4.1.0`, the minimum engine version. The precompute calls
3116
+ * `ds.canonicalizeCandidates`, which the design system only exposes from
3117
+ * Tailwind 4.1 onward — on 4.0.x it throws `is not a function`, so we fail loud
3118
+ * with a clear message before spawning the worker. A `4.1.0-*` prerelease sorts
3119
+ * below it.
3120
+ */
3121
+ const MIN_ENGINE = {
3122
+ major: 4,
3123
+ minor: 1,
3124
+ patch: 0,
3125
+ prerelease: null
3126
+ };
3127
+ /**
3128
+ * Parse a version string into `{ major, minor, patch, prerelease }`, or `null`
3129
+ * for anything unparseable (`''`, `'unknown'`, a range like `'^4.3.3'`, a dist
3130
+ * tag like `'next'`, non-strings). Total — never throws.
3131
+ */
3132
+ function parseVersion(v) {
3133
+ if (typeof v !== "string") return null;
3134
+ let s = v.trim();
3135
+ if (s === "" || s === "unknown") return null;
3136
+ if (s[0] === "v" || s[0] === "V") s = s.slice(1);
3137
+ const plus = s.indexOf("+");
3138
+ if (plus !== -1) s = s.slice(0, plus);
3139
+ let prerelease = null;
3140
+ const dash = s.indexOf("-");
3141
+ if (dash !== -1) {
3142
+ prerelease = s.slice(dash + 1) || null;
3143
+ s = s.slice(0, dash);
3144
+ }
3145
+ const parts = s.split(".");
3146
+ const major = Number.parseInt(parts[0], 10);
3147
+ if (Number.isNaN(major)) return null;
3148
+ const minor = Number.parseInt(parts[1] ?? "0", 10);
3149
+ const patch = Number.parseInt(parts[2] ?? "0", 10);
3150
+ return {
3151
+ major,
3152
+ minor: Number.isNaN(minor) ? 0 : minor,
3153
+ patch: Number.isNaN(patch) ? 0 : patch,
3154
+ prerelease
3155
+ };
3156
+ }
3157
+ /** Compare by major, minor, patch; at equal core, a release outranks a prerelease. */
3158
+ function compareVersions(a, b) {
3159
+ if (a.major !== b.major) return a.major < b.major ? -1 : 1;
3160
+ if (a.minor !== b.minor) return a.minor < b.minor ? -1 : 1;
3161
+ if (a.patch !== b.patch) return a.patch < b.patch ? -1 : 1;
3162
+ if (a.prerelease === b.prerelease) return 0;
3163
+ if (a.prerelease === null) return 1;
3164
+ if (b.prerelease === null) return -1;
3165
+ return a.prerelease < b.prerelease ? -1 : a.prerelease > b.prerelease ? 1 : 0;
3166
+ }
3167
+ function sameMajor(a, b) {
3168
+ return a.major === b.major;
3169
+ }
3170
+ function sameMinor(a, b) {
3171
+ return a.major === b.major && a.minor === b.minor;
3172
+ }
3173
+ /**
3174
+ * Grade `(E, B)` against the supported range and build drift. First matching
3175
+ * row wins (see the decision table in the PR / plan). Pure and total: safe to
3176
+ * unit-test with literal version strings.
3177
+ */
3178
+ function assessEngine(E, B, opts) {
3179
+ const pe = parseVersion(E);
3180
+ const pb = parseVersion(B);
3181
+ const bundled = opts.bundledVersion;
3182
+ if (pe === null) return {
3183
+ verdict: "ok",
3184
+ kind: "engine-version-unknown",
3185
+ message: "Could not determine the resolved Tailwind engine version; skipping the version guard."
3186
+ };
3187
+ if (pe.major < SUPPORTED_MAJOR || compareVersions(pe, MIN_ENGINE) < 0) return {
3188
+ verdict: "fatal",
3189
+ kind: "engine-too-old",
3190
+ message: `oxlint-tailwindcss requires Tailwind CSS v4.1 or newer, but the resolved engine is ${E}.`,
3191
+ hint: "Upgrade tailwindcss / @tailwindcss/node to v4.1+, or pin an older oxlint-tailwindcss."
3192
+ };
3193
+ if (pe.major > SUPPORTED_MAJOR) {
3194
+ if (opts.allowUntested) return {
3195
+ verdict: "warn",
3196
+ kind: "engine-future-major-allowed",
3197
+ message: `Running against untested Tailwind engine ${E} (a major newer than the tested ${bundled}) because allowUntestedEngine is set — results may be inaccurate.`
3198
+ };
3199
+ return {
3200
+ verdict: "fatal",
3201
+ kind: "engine-future-major",
3202
+ message: `The resolved Tailwind engine ${E} is a major version newer than this plugin was built for (tested against ${bundled}); its behavior is unverified.`,
3203
+ hint: "Set settings.tailwindcss.allowUntestedEngine: true to run anyway (results may be inaccurate), or upgrade oxlint-tailwindcss."
3204
+ };
3205
+ }
3206
+ if (pb !== null && !sameMajor(pe, pb)) {
3207
+ if (opts.allowUntested) return {
3208
+ verdict: "warn",
3209
+ kind: "engine-build-drift-major-allowed",
3210
+ message: `Linting with Tailwind engine ${E} while your build uses tailwindcss@${B} (a different major) because allowUntestedEngine is set — the plugin enforces different semantics than your build produces.`
3211
+ };
3212
+ return {
3213
+ verdict: "fatal",
3214
+ kind: "engine-build-drift-major",
3215
+ message: `Linting with Tailwind engine ${E} but your build uses tailwindcss@${B} (a different major); the plugin would enforce different Tailwind semantics than your build produces.`,
3216
+ hint: "Align the versions, or set settings.tailwindcss.allowUntestedEngine: true to override."
3217
+ };
3218
+ }
3219
+ if (pb !== null && !sameMinor(pe, pb)) return {
3220
+ verdict: "warn",
3221
+ kind: "engine-build-drift-minor",
3222
+ message: `Linting with Tailwind engine ${E} but your build uses tailwindcss@${B}; lint results may differ from your compiled CSS.`,
3223
+ hint: "Align the versions, or ignore if intentional."
3224
+ };
3225
+ const pBundled = parseVersion(bundled);
3226
+ if (pBundled !== null && compareVersions(pe, pBundled) > 0) return {
3227
+ verdict: "warn",
3228
+ kind: "engine-newer-minor",
3229
+ message: `The resolved Tailwind engine ${E} is newer than the version this plugin was tested against (${bundled}); newly added utilities may be reported as unknown.`,
3230
+ hint: "Usually safe; upgrade oxlint-tailwindcss if you see false positives."
3231
+ };
3232
+ return {
3233
+ verdict: "ok",
3234
+ kind: "ok",
3235
+ message: ""
3236
+ };
3237
+ }
3238
+ const warnedEngineKeys = /* @__PURE__ */ new Set();
3239
+ /**
3240
+ * Act on a verdict: `fatal` throws `UnsupportedEngineError` (routed to
3241
+ * `designSystemUnavailable`), `warn` emits a one-time stderr notice keyed by
3242
+ * `(entryPoint, kind, E, B)`, `ok` is silent. `debugLog` (self-gated) always
3243
+ * records the structured detail when debug is on.
3244
+ */
3245
+ function emitEngineVerdict(v, ctx) {
3246
+ if (v.verdict === "fatal") throw new UnsupportedEngineError(v.message, v.hint);
3247
+ if (v.verdict === "warn") {
3248
+ const key = `${ctx.resolvedPath}\0${v.kind}\0${ctx.E}\0${ctx.B}`;
3249
+ if (!warnedEngineKeys.has(key)) {
3250
+ warnedEngineKeys.add(key);
3251
+ console.warn(`${WARN_PREFIX} ${v.message}`);
3252
+ }
3253
+ }
3254
+ debugLog(`engine E=${ctx.E} B=${ctx.B} → ${v.kind}`);
3255
+ }
3256
+ /**
3257
+ * Resolve the engine for `resolvedPath` (or use injected facts), assess it, and
3258
+ * emit the verdict. Throws `UnsupportedEngineError` on a fatal verdict. Called
3259
+ * once per entry point from `getLoadedDesignSystem`, inside its fatal-caching
3260
+ * `try`.
3261
+ */
3262
+ function guardEngine(resolvedPath, allowUntested, override) {
3263
+ let E;
3264
+ let B;
3265
+ let bundledVersion;
3266
+ if (override) {
3267
+ E = override.E;
3268
+ B = override.B;
3269
+ bundledVersion = override.bundledVersion ?? TAILWIND_NODE_VERSION;
3270
+ } else {
3271
+ const res = resolveTailwindNodeFor(resolvedPath);
3272
+ E = res.nodeVersion;
3273
+ B = res.buildVersion;
3274
+ bundledVersion = TAILWIND_NODE_VERSION;
3275
+ }
3276
+ emitEngineVerdict(assessEngine(E, B, {
3277
+ allowUntested,
3278
+ bundledVersion
3279
+ }), {
3280
+ resolvedPath,
3281
+ E,
3282
+ B
3283
+ });
3284
+ }
3285
+ /** Read `settings.tailwindcss.allowUntestedEngine` (default `false`). */
3286
+ function allowUntestedEngineFromSettings(settings) {
3287
+ const tw = settings?.tailwindcss;
3288
+ if (tw && typeof tw === "object" && "allowUntestedEngine" in tw) return tw.allowUntestedEngine === true;
3289
+ return false;
3290
+ }
3291
+ //#endregion
2942
3292
  //#region src/utils/context.ts
2943
3293
  /**
2944
3294
  * Safely read `context.options[0]`. Returns `undefined` if the getter throws
@@ -3212,7 +3562,7 @@ function timeoutFromSettings(settings) {
3212
3562
  * Cached per absolute entry-point path, keyed by mtime. In monorepos each
3213
3563
  * unique CSS gets its own cache entry.
3214
3564
  */
3215
- function getLoadedDesignSystem(cssPath, settings) {
3565
+ function getLoadedDesignSystem(cssPath, settings, engineInfo) {
3216
3566
  const resolvedPath = resolve(cssPath);
3217
3567
  let mtime;
3218
3568
  try {
@@ -3229,6 +3579,7 @@ function getLoadedDesignSystem(cssPath, settings) {
3229
3579
  if (failed && failed.mtime === mtime) throw failed.error;
3230
3580
  let data;
3231
3581
  try {
3582
+ guardEngine(resolvedPath, allowUntestedEngineFromSettings(settings), engineInfo);
3232
3583
  data = loadDesignSystemSync(resolvedPath, timeoutFromSettings(settings));
3233
3584
  } catch (err) {
3234
3585
  if (isFatalError(err)) dsFailureCache.set(resolvedPath, {
@@ -3454,7 +3805,8 @@ var DesignSystemWorker = class {
3454
3805
  this.workers.set(cssPath, existing);
3455
3806
  return existing;
3456
3807
  }
3457
- if (TAILWIND_NODE_PATH === null) throw this.remember(cssPath, new SortServiceError(`Could not resolve '@tailwindcss/node' for the ${this.opts.serviceName} worker.`, "Install '@tailwindcss/node' (or upgrade oxlint-tailwindcss) and re-run."));
3808
+ const { nodePath: tailwindNodePath } = resolveTailwindNodeFor(cssPath);
3809
+ if (tailwindNodePath === null) throw this.remember(cssPath, new SortServiceError(`Could not resolve '@tailwindcss/node' for the ${this.opts.serviceName} worker.`, "Install '@tailwindcss/node' (or upgrade oxlint-tailwindcss) and re-run."));
3458
3810
  const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
3459
3811
  const controlArray = new Int32Array(sharedBuffer, 0, HEADER_INTS);
3460
3812
  const lengthView = new DataView(sharedBuffer, HEADER_INTS * 4, 4);
@@ -3466,7 +3818,7 @@ var DesignSystemWorker = class {
3466
3818
  workerData: {
3467
3819
  sharedBuffer,
3468
3820
  cssPath,
3469
- tailwindNodePath: TAILWIND_NODE_PATH
3821
+ tailwindNodePath
3470
3822
  }
3471
3823
  });
3472
3824
  } catch (cause) {
@@ -6014,6 +6366,7 @@ const noDarkWithoutLight = defineRule({
6014
6366
  const ds = softGetDS(getDS);
6015
6367
  const cache = ds ? ds.cache : null;
6016
6368
  for (const loc of locations) {
6369
+ if (!isFinalClassList(loc)) continue;
6017
6370
  const classes = splitClasses(loc.value);
6018
6371
  if (cache && ds) {
6019
6372
  let unresolved = null;
@@ -6274,6 +6627,7 @@ const noContradictingVariants = defineRule({
6274
6627
  function check(locations) {
6275
6628
  const factsFor = variantFactsLookup();
6276
6629
  for (const loc of locations) {
6630
+ if (!isFinalClassList(loc)) continue;
6277
6631
  const classes = splitClasses(loc.value);
6278
6632
  const baseUtilities = /* @__PURE__ */ new Set();
6279
6633
  for (const cls of classes) if (extractVariants(cls).length === 0) baseUtilities.add(cls);