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