oxlint-tailwindcss 1.2.0 → 1.3.1
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 +28 -5
- package/dist/index.cjs +500 -256
- package/dist/index.d.cts +1 -2
- package/dist/index.d.mts +1 -2
- package/dist/index.mjs +502 -260
- package/package.json +9 -9
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,26 @@ let node_crypto = require("node:crypto");
|
|
|
4
4
|
let node_fs = require("node:fs");
|
|
5
5
|
let node_path = require("node:path");
|
|
6
6
|
let node_os = require("node:os");
|
|
7
|
+
//#region src/utils/allowlist.ts
|
|
8
|
+
/**
|
|
9
|
+
* Shared regex-allowlist helpers used by rules that accept an `allowlist`
|
|
10
|
+
* option of regex source strings (currently enforce-logical / enforce-physical).
|
|
11
|
+
*
|
|
12
|
+
* Invalid regex sources are skipped rather than thrown so a typo in one
|
|
13
|
+
* pattern doesn't blow up the entire lint run.
|
|
14
|
+
*/
|
|
15
|
+
function compileRegexList(patterns) {
|
|
16
|
+
if (!patterns || patterns.length === 0) return [];
|
|
17
|
+
const compiled = [];
|
|
18
|
+
for (const p of patterns) try {
|
|
19
|
+
compiled.push(new RegExp(p));
|
|
20
|
+
} catch {}
|
|
21
|
+
return compiled;
|
|
22
|
+
}
|
|
23
|
+
function matchesAny(value, list) {
|
|
24
|
+
return list.some((re) => re.test(value));
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
7
27
|
//#region src/utils/extractors.ts
|
|
8
28
|
/**
|
|
9
29
|
* Preserves leading/trailing spaces in fixed class strings for template literals.
|
|
@@ -81,7 +101,7 @@ function getExtractorConfig(context) {
|
|
|
81
101
|
attributes: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.attributes, tw.attributes, exclude?.attributes),
|
|
82
102
|
callees: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.callees, tw.callees, exclude?.callees),
|
|
83
103
|
tags: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.tags, tw.tags, exclude?.tags),
|
|
84
|
-
variablePatterns: [...filteredPatterns, ...(tw.variablePatterns
|
|
104
|
+
variablePatterns: [...filteredPatterns, ...compileRegexList(tw.variablePatterns)]
|
|
85
105
|
};
|
|
86
106
|
configCache.set(context, resolved);
|
|
87
107
|
return resolved;
|
|
@@ -352,6 +372,9 @@ function getCalleeName(node) {
|
|
|
352
372
|
}
|
|
353
373
|
//#endregion
|
|
354
374
|
//#region src/utils/class-splitter.ts
|
|
375
|
+
function isWhitespace(char) {
|
|
376
|
+
return char === " " || char === " " || char === "\n" || char === "\r" || char === "\f" || char === "\v";
|
|
377
|
+
}
|
|
355
378
|
/**
|
|
356
379
|
* Splits a Tailwind class string respecting:
|
|
357
380
|
* - Nested brackets: bg-[url('...')], h-[calc(100%+2rem)]
|
|
@@ -374,9 +397,9 @@ function splitClasses(classString) {
|
|
|
374
397
|
}
|
|
375
398
|
if (!inSingleQuote && !inDoubleQuote) {
|
|
376
399
|
if (char === "[") bracketDepth++;
|
|
377
|
-
if (char === "]") bracketDepth
|
|
400
|
+
if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
|
|
378
401
|
}
|
|
379
|
-
if (
|
|
402
|
+
if (isWhitespace(char) && bracketDepth === 0) {
|
|
380
403
|
if (current.length > 0) {
|
|
381
404
|
classes.push(current);
|
|
382
405
|
current = "";
|
|
@@ -403,9 +426,9 @@ function splitClassesWithSeparators(classString) {
|
|
|
403
426
|
}
|
|
404
427
|
if (!inSingleQuote && !inDoubleQuote) {
|
|
405
428
|
if (char === "[") bracketDepth++;
|
|
406
|
-
if (char === "]") bracketDepth
|
|
429
|
+
if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
|
|
407
430
|
}
|
|
408
|
-
if (
|
|
431
|
+
if (isWhitespace(char) && bracketDepth === 0) {
|
|
409
432
|
if (current.length > 0) {
|
|
410
433
|
classes.push(current);
|
|
411
434
|
separators.push(currentSep);
|
|
@@ -691,6 +714,52 @@ function reattachImportant(bare, position) {
|
|
|
691
714
|
if (position === "suffix") return `${bare}!`;
|
|
692
715
|
return bare;
|
|
693
716
|
}
|
|
717
|
+
/**
|
|
718
|
+
* Pseudo-element variants. They select a generated box (`::before`, `::marker`,
|
|
719
|
+
* …) rather than the element itself, so they must sit innermost in the variant
|
|
720
|
+
* chain (closest to the utility). Canonical home shared by
|
|
721
|
+
* `consistent-variant-order` (partitions them last) and
|
|
722
|
+
* `no-contradicting-variants` (they can't contradict a base class).
|
|
723
|
+
*/
|
|
724
|
+
const PSEUDO_ELEMENT_VARIANTS = new Set([
|
|
725
|
+
"before",
|
|
726
|
+
"after",
|
|
727
|
+
"file",
|
|
728
|
+
"placeholder",
|
|
729
|
+
"selection",
|
|
730
|
+
"marker",
|
|
731
|
+
"backdrop",
|
|
732
|
+
"first-line",
|
|
733
|
+
"first-letter",
|
|
734
|
+
"details-content"
|
|
735
|
+
]);
|
|
736
|
+
function isPseudoElementVariant(variant) {
|
|
737
|
+
return PSEUDO_ELEMENT_VARIANTS.has(variant);
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Selector barriers: variants that re-point the selector at a *different*
|
|
741
|
+
* element than the ones around them — child (`*`), descendant (`**`),
|
|
742
|
+
* arbitrary selectors (`[&>svg]`) and compound child selectors (`*:data-[…]`).
|
|
743
|
+
*
|
|
744
|
+
* Unlike pseudo-elements, these are NOT free to move to the end of the chain:
|
|
745
|
+
* `hover:*:flex` (`&:hover > *`) and `*:hover:flex` (`& > *:hover`) target
|
|
746
|
+
* different elements. `consistent-variant-order` treats them as hard
|
|
747
|
+
* reordering barriers — variants never cross them.
|
|
748
|
+
*/
|
|
749
|
+
function isSelectorBarrier(variant) {
|
|
750
|
+
if (variant === "*" || variant === "**") return true;
|
|
751
|
+
if (variant.startsWith("[") && variant.endsWith("]")) return true;
|
|
752
|
+
if (variant.startsWith("*:")) return true;
|
|
753
|
+
return false;
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Whether a variant changes the selector target (pseudo-element OR selector
|
|
757
|
+
* barrier). Such variants don't impose a condition on the same element, so they
|
|
758
|
+
* can't make a variant class contradict/duplicate a base class.
|
|
759
|
+
*/
|
|
760
|
+
function changesTarget(variant) {
|
|
761
|
+
return isPseudoElementVariant(variant) || isSelectorBarrier(variant);
|
|
762
|
+
}
|
|
694
763
|
//#endregion
|
|
695
764
|
//#region src/utils/floating-point.ts
|
|
696
765
|
/**
|
|
@@ -1117,6 +1186,12 @@ function signalError(e) {
|
|
|
1117
1186
|
Atomics.store(control, 2, -1);
|
|
1118
1187
|
Atomics.notify(control, 2);
|
|
1119
1188
|
}
|
|
1189
|
+
// Everything below — including the top-level require()s — runs inside this try
|
|
1190
|
+
// so any SYNCHRONOUS module-scope failure (a broken @tailwindcss/node install,
|
|
1191
|
+
// missing fs/path) is routed through signalError. Without it the worker would
|
|
1192
|
+
// die unsignaled and the main thread would block until the full timeout, then
|
|
1193
|
+
// report a misleading "timed out" instead of the real cause.
|
|
1194
|
+
try {
|
|
1120
1195
|
// Resolve @tailwindcss/node via an absolute path passed in by the parent —
|
|
1121
1196
|
// bare-specifier lookup from the worker's cwd fails under pnpm strict
|
|
1122
1197
|
// workspaces (the module lives under node_modules/.pnpm/... which is not on the
|
|
@@ -1234,6 +1309,39 @@ async function main() {
|
|
|
1234
1309
|
const dash = cls.lastIndexOf('-');
|
|
1235
1310
|
if (dash > 0) knownPrefixes.add(cls.slice(0, dash));
|
|
1236
1311
|
}
|
|
1312
|
+
// Curated static utilities valid in v4 but absent from getClassList() (#37).
|
|
1313
|
+
// These are special-cased in Tailwind's compiler, so they appear in neither
|
|
1314
|
+
// getClassList() NOR the utility registry (\`utilities.keys('static')\`) — only
|
|
1315
|
+
// an explicit probe surfaces them:
|
|
1316
|
+
// - \`@container-size\` (\`container-type: size\`) — sibling of the enumerated
|
|
1317
|
+
// \`@container\` / \`@container-normal\`; was flagged as a typo of \`contain-size\`.
|
|
1318
|
+
// - \`filter-none\` / \`backdrop-filter-none\` (\`filter: none\`) — the reset
|
|
1319
|
+
// utilities; their functional bases enumerate values but omit \`none\`.
|
|
1320
|
+
// - \`max-w-screen\` (\`max-width: 100vw\`).
|
|
1321
|
+
// Validated via candidatesToCss (self-prunes on any Tailwind version that doesn't
|
|
1322
|
+
// emit them) and their CSS is captured so the cssProps phase below treats them
|
|
1323
|
+
// exactly like their getClassList siblings — otherwise no-conflicting-classes
|
|
1324
|
+
// would flag \`@container @container-normal\` but silently accept
|
|
1325
|
+
// \`@container @container-size\`. Named forms (\`@container-size/main\`) are covered
|
|
1326
|
+
// by the slash-modifier path in cache.isValid once the base lands in validClasses.
|
|
1327
|
+
const staticExtras = [
|
|
1328
|
+
'@container-size',
|
|
1329
|
+
'filter-none',
|
|
1330
|
+
'backdrop-filter-none',
|
|
1331
|
+
'max-w-screen',
|
|
1332
|
+
].filter((c) => !validSet.has(c));
|
|
1333
|
+
const staticExtraCss = {};
|
|
1334
|
+
if (staticExtras.length > 0) {
|
|
1335
|
+
const staticResults = ds.candidatesToCss(staticExtras.map(pfx));
|
|
1336
|
+
for (let i = 0; i < staticExtras.length; i++) {
|
|
1337
|
+
if (staticResults[i] != null) {
|
|
1338
|
+
validClasses.push(staticExtras[i]);
|
|
1339
|
+
validSet.add(staticExtras[i]);
|
|
1340
|
+
staticExtraCss[staticExtras[i]] = staticResults[i];
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1237
1345
|
const extraCandidates = [];
|
|
1238
1346
|
const breakpoints = ['sm', 'md', 'lg', 'xl', '2xl'];
|
|
1239
1347
|
for (const prefix of knownPrefixes) {
|
|
@@ -1255,6 +1363,27 @@ async function main() {
|
|
|
1255
1363
|
}
|
|
1256
1364
|
}
|
|
1257
1365
|
|
|
1366
|
+
// Negative variants of utilities that support them (#37). getClassList()
|
|
1367
|
+
// enumerates negatives for most (\`-m-4\`, \`-translate-x-2\`) but omits a few
|
|
1368
|
+
// (\`-col-1\`, \`-row-1\`, \`-hue-rotate-45\`, \`-backdrop-hue-rotate-45\`). Probe
|
|
1369
|
+
// \`-<prefix>-1\` for every known prefix lacking negative coverage; candidatesToCss
|
|
1370
|
+
// self-prunes utilities that reject negatives (\`-p-1\` → null), so only genuinely
|
|
1371
|
+
// negative-capable prefixes land in validClasses, giving isValid's / getOrder's
|
|
1372
|
+
// numeric-prefix heuristic the \`-<prefix>\` it needs to accept any \`-<prefix>-<n>\`.
|
|
1373
|
+
const negativeProbes = [];
|
|
1374
|
+
for (const prefix of knownPrefixes) {
|
|
1375
|
+
if (!knownPrefixes.has('-' + prefix)) negativeProbes.push('-' + prefix + '-1');
|
|
1376
|
+
}
|
|
1377
|
+
if (negativeProbes.length > 0) {
|
|
1378
|
+
const negResults = ds.candidatesToCss(negativeProbes.map(pfx));
|
|
1379
|
+
for (let i = 0; i < negativeProbes.length; i++) {
|
|
1380
|
+
if (negResults[i] != null && !validSet.has(negativeProbes[i])) {
|
|
1381
|
+
validClasses.push(negativeProbes[i]);
|
|
1382
|
+
validSet.add(negativeProbes[i]);
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1258
1387
|
// Marker classes: group/peer don't produce CSS but enable group-hover:/peer-checked: variants
|
|
1259
1388
|
const allVariants = ds.getVariants();
|
|
1260
1389
|
for (const v of allVariants) {
|
|
@@ -1301,6 +1430,11 @@ async function main() {
|
|
|
1301
1430
|
'decoration-clone', 'decoration-slice',
|
|
1302
1431
|
'bg-gradient-to-t', 'bg-gradient-to-tr', 'bg-gradient-to-r', 'bg-gradient-to-br',
|
|
1303
1432
|
'bg-gradient-to-b', 'bg-gradient-to-bl', 'bg-gradient-to-l', 'bg-gradient-to-tl',
|
|
1433
|
+
// v3 background/object-position spellings reordered in v4 (#37):
|
|
1434
|
+
// \`bg-left-top\` -> \`bg-top-left\`. canonicalizeCandidates rewrites them, so
|
|
1435
|
+
// enforce-canonical suggests the v4 form and no-unknown-classes accepts them.
|
|
1436
|
+
'bg-left-top', 'bg-right-top', 'bg-left-bottom', 'bg-right-bottom',
|
|
1437
|
+
'object-left-top', 'object-right-top', 'object-left-bottom', 'object-right-bottom',
|
|
1304
1438
|
];
|
|
1305
1439
|
for (const cls of validClasses) {
|
|
1306
1440
|
if (cls.startsWith('inset-s-')) legacyCandidates.push('start-' + cls.slice(8));
|
|
@@ -1429,6 +1563,14 @@ async function main() {
|
|
|
1429
1563
|
}
|
|
1430
1564
|
}
|
|
1431
1565
|
|
|
1566
|
+
// cssProps for the curated static extras (#37) so they participate in conflict
|
|
1567
|
+
// detection exactly like their getClassList siblings (e.g. \`@container-size\` and
|
|
1568
|
+
// \`@container\` both declaring \`container-type\`).
|
|
1569
|
+
for (const name in staticExtraCss) {
|
|
1570
|
+
const props = extractRootCssProps(staticExtraCss[name], pfx(name));
|
|
1571
|
+
if (props.length > 0) cssProps[name] = props;
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1432
1574
|
// Variant ordering from the design system
|
|
1433
1575
|
const variantOrder = {};
|
|
1434
1576
|
const variants = ds.getVariants();
|
|
@@ -1507,8 +1649,20 @@ async function main() {
|
|
|
1507
1649
|
main()
|
|
1508
1650
|
.then(() => { Atomics.store(control, 2, 1); Atomics.notify(control, 2); })
|
|
1509
1651
|
.catch((e) => signalError(e));
|
|
1652
|
+
} catch (e) {
|
|
1653
|
+
signalError(e);
|
|
1654
|
+
}
|
|
1510
1655
|
`;
|
|
1511
|
-
|
|
1656
|
+
function cacheDirName() {
|
|
1657
|
+
try {
|
|
1658
|
+
const info = (0, node_os.userInfo)();
|
|
1659
|
+
const id = typeof info.uid === "number" && info.uid >= 0 ? String(info.uid) : info.username;
|
|
1660
|
+
return `oxlint-tailwindcss-${String(id).replace(/[^a-zA-Z0-9_-]/g, "_")}`;
|
|
1661
|
+
} catch {
|
|
1662
|
+
return "oxlint-tailwindcss";
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
const CACHE_DIR = (0, node_path.join)((0, node_os.tmpdir)(), cacheDirName());
|
|
1512
1666
|
/**
|
|
1513
1667
|
* Cache key derived from:
|
|
1514
1668
|
* - md5(PRECOMPUTE_SCRIPT): auto-invalidates when our precompute logic changes,
|
|
@@ -1527,17 +1681,73 @@ const CACHE_KEY = computeCacheKey(PRECOMPUTE_SCRIPT, TAILWIND_NODE_VERSION);
|
|
|
1527
1681
|
function computeContentHash(content) {
|
|
1528
1682
|
return (0, node_crypto.createHash)("md5").update(`${CACHE_KEY}:${content}`).digest("hex");
|
|
1529
1683
|
}
|
|
1684
|
+
const IMPORT_RE = /@import\s+(?:url\(\s*)?['"]([^'"]+)['"]/g;
|
|
1685
|
+
/**
|
|
1686
|
+
* Concatenate the entry CSS with the content of its locally-imported files, so
|
|
1687
|
+
* the cache key invalidates when an `@import`'d file changes — not only when the
|
|
1688
|
+
* entry itself does (DS-A2). Without this, editing a `@theme`/component file
|
|
1689
|
+
* pulled in via `@import "./theme.css"` served a stale design system until the
|
|
1690
|
+
* entry was touched or the Tailwind version changed.
|
|
1691
|
+
*
|
|
1692
|
+
* Resolves RELATIVE imports (`./`, `../`) recursively up to a small depth;
|
|
1693
|
+
* package imports (`@import "tailwindcss"`, `tw-animate-css`) are already
|
|
1694
|
+
* covered by the `@tailwindcss/node` version baked into CACHE_KEY. Best-effort:
|
|
1695
|
+
* an unreadable import contributes nothing (it can't affect the DS either).
|
|
1696
|
+
*/
|
|
1697
|
+
function hashableContent(entryPath, entryContent) {
|
|
1698
|
+
const parts = [entryContent];
|
|
1699
|
+
const seen = new Set([(0, node_path.resolve)(entryPath)]);
|
|
1700
|
+
const visit = (cssPath, content, depth) => {
|
|
1701
|
+
if (depth <= 0) return;
|
|
1702
|
+
const baseDir = (0, node_path.dirname)(cssPath);
|
|
1703
|
+
IMPORT_RE.lastIndex = 0;
|
|
1704
|
+
const specifiers = [];
|
|
1705
|
+
let m;
|
|
1706
|
+
while ((m = IMPORT_RE.exec(content)) !== null) if (m[1].startsWith(".")) specifiers.push(m[1]);
|
|
1707
|
+
for (const spec of specifiers) {
|
|
1708
|
+
const importPath = (0, node_path.resolve)(baseDir, spec.split("?")[0]);
|
|
1709
|
+
if (seen.has(importPath)) continue;
|
|
1710
|
+
seen.add(importPath);
|
|
1711
|
+
let importContent;
|
|
1712
|
+
try {
|
|
1713
|
+
importContent = (0, node_fs.readFileSync)(importPath, "utf-8");
|
|
1714
|
+
} catch {
|
|
1715
|
+
continue;
|
|
1716
|
+
}
|
|
1717
|
+
parts.push(importContent);
|
|
1718
|
+
visit(importPath, importContent, depth - 1);
|
|
1719
|
+
}
|
|
1720
|
+
};
|
|
1721
|
+
visit((0, node_path.resolve)(entryPath), entryContent, 4);
|
|
1722
|
+
return parts.join("\0");
|
|
1723
|
+
}
|
|
1530
1724
|
function getContentCachePath(contentHash) {
|
|
1531
1725
|
return (0, node_path.join)(CACHE_DIR, `${contentHash}.json`);
|
|
1532
1726
|
}
|
|
1727
|
+
/**
|
|
1728
|
+
* Minimal shape check for a cache payload. Guards against (a) a poisoned file
|
|
1729
|
+
* planted by a local attacker and (b) a corrupt/half-written or version-skewed
|
|
1730
|
+
* file. A `{}` that is valid JSON but missing fields would otherwise blow up
|
|
1731
|
+
* later in `DesignSystemCache.fromPrecomputed` with a raw TypeError that isn't
|
|
1732
|
+
* plugin-fatal, breaking the lint with no diagnostic. We don't deep-validate
|
|
1733
|
+
* every entry — just enough that `fromPrecomputed` can rely on the fields.
|
|
1734
|
+
*/
|
|
1735
|
+
function isPrecomputedData(data) {
|
|
1736
|
+
if (typeof data !== "object" || data === null) return false;
|
|
1737
|
+
const d = data;
|
|
1738
|
+
const isObject = (v) => typeof v === "object" && v !== null;
|
|
1739
|
+
return Array.isArray(d.validClasses) && Array.isArray(d.componentClasses) && typeof d.prefix === "string" && isObject(d.canonical) && isObject(d.order) && isObject(d.cssProps) && isObject(d.variantOrder) && isObject(d.arbitraryEquivalents);
|
|
1740
|
+
}
|
|
1533
1741
|
function tryReadCache(cachePath) {
|
|
1534
1742
|
const raw = tryReadRawCache(cachePath);
|
|
1535
1743
|
if (raw === null) return null;
|
|
1744
|
+
let data;
|
|
1536
1745
|
try {
|
|
1537
|
-
|
|
1746
|
+
data = JSON.parse(raw);
|
|
1538
1747
|
} catch {
|
|
1539
1748
|
return null;
|
|
1540
1749
|
}
|
|
1750
|
+
return isPrecomputedData(data) ? data : null;
|
|
1541
1751
|
}
|
|
1542
1752
|
function tryReadRawCache(cachePath) {
|
|
1543
1753
|
try {
|
|
@@ -1564,6 +1774,23 @@ function tryUnlink(path) {
|
|
|
1564
1774
|
(0, node_fs.unlinkSync)(path);
|
|
1565
1775
|
} catch {}
|
|
1566
1776
|
}
|
|
1777
|
+
/**
|
|
1778
|
+
* Reclaim a stale lock by exclusive rename rather than unlink (DS-M1). Two
|
|
1779
|
+
* waiters that both judge the lock stale would otherwise both `unlink` it — and
|
|
1780
|
+
* the second unlink could delete a FRESH lock a third isolate just created,
|
|
1781
|
+
* letting two precomputes run in parallel (the very amplification the lock
|
|
1782
|
+
* exists to prevent, #24). `renameSync` moves the file atomically: only one
|
|
1783
|
+
* waiter wins the move; the loser gets ENOENT and loops back to re-check.
|
|
1784
|
+
*/
|
|
1785
|
+
function reclaimStaleLock(lockPath) {
|
|
1786
|
+
const reclaimPath = `${lockPath}.reclaim.${process.pid}.${node_worker_threads.threadId}.${precomputeSeq++}`;
|
|
1787
|
+
try {
|
|
1788
|
+
(0, node_fs.renameSync)(lockPath, reclaimPath);
|
|
1789
|
+
} catch {
|
|
1790
|
+
return;
|
|
1791
|
+
}
|
|
1792
|
+
tryUnlink(reclaimPath);
|
|
1793
|
+
}
|
|
1567
1794
|
/** control[2] — the worker's ready/done signal (0=loading, 1=done, -1=error). */
|
|
1568
1795
|
const PRECOMPUTE_SIGNAL_INDEX = 2;
|
|
1569
1796
|
const ERR_BUFFER_SIZE = 64 * 1024;
|
|
@@ -1616,15 +1843,12 @@ function runPrecomputeViaWorker(resolvedPath, tailwindNodePath, cachePath, timeo
|
|
|
1616
1843
|
} catch (cause) {
|
|
1617
1844
|
throw precomputeLoadError(resolvedPath, cause);
|
|
1618
1845
|
}
|
|
1619
|
-
|
|
1620
|
-
worker.on("error", (err) => {
|
|
1621
|
-
workerError = err;
|
|
1622
|
-
});
|
|
1846
|
+
worker.on("error", () => {});
|
|
1623
1847
|
try {
|
|
1624
1848
|
if (Atomics.wait(control, PRECOMPUTE_SIGNAL_INDEX, 0, timeout) === "timed-out") throw new DesignSystemLoadError(`Timed out precomputing design system from "${resolvedPath}" after ${timeout}ms.`, "Raise `settings.tailwindcss.timeout` if your machine or CI runner is slow, or verify the CSS imports resolve.");
|
|
1625
1849
|
if (control[PRECOMPUTE_SIGNAL_INDEX] === -1) {
|
|
1626
1850
|
const len = errLengthView.getUint32(0);
|
|
1627
|
-
throw precomputeLoadError(resolvedPath, len > 0 ? new Error(Buffer.from(errDataArea.slice(0, len)).toString("utf-8")) :
|
|
1851
|
+
throw precomputeLoadError(resolvedPath, len > 0 ? new Error(Buffer.from(errDataArea.slice(0, len)).toString("utf-8")) : /* @__PURE__ */ new Error("precompute worker exited without reporting a cause (it may have been killed by the OS, e.g. under memory pressure)"));
|
|
1628
1852
|
}
|
|
1629
1853
|
} finally {
|
|
1630
1854
|
tryUnlink(tmpPath);
|
|
@@ -1632,14 +1856,17 @@ function runPrecomputeViaWorker(resolvedPath, tailwindNodePath, cachePath, timeo
|
|
|
1632
1856
|
}
|
|
1633
1857
|
}
|
|
1634
1858
|
/**
|
|
1635
|
-
* Run the precompute worker, then read back the JSON it wrote to
|
|
1636
|
-
* Used by both the lock-winner path and the uncoordinated degrade
|
|
1859
|
+
* Run the precompute worker, then read back and validate the JSON it wrote to
|
|
1860
|
+
* `cachePath`. Used by both the lock-winner path and the uncoordinated degrade
|
|
1861
|
+
* path. Returns the validated `PrecomputedData` (never a raw string), so a
|
|
1862
|
+
* malformed payload surfaces as a clear diagnostic here instead of crashing
|
|
1863
|
+
* later in `DesignSystemCache.fromPrecomputed`.
|
|
1637
1864
|
*/
|
|
1638
1865
|
function precomputeAndRead(resolvedPath, tailwindNodePath, cachePath, timeout) {
|
|
1639
1866
|
runPrecomputeViaWorker(resolvedPath, tailwindNodePath, cachePath, timeout);
|
|
1640
|
-
const
|
|
1641
|
-
if (
|
|
1642
|
-
return
|
|
1867
|
+
const data = tryReadCache(cachePath);
|
|
1868
|
+
if (data === null) throw new DesignSystemLoadError(`Precompute worker finished but wrote no valid cache file for "${resolvedPath}".`, "This usually means the system temp directory is not writable, or the output was malformed; check its permissions and free space.");
|
|
1869
|
+
return data;
|
|
1643
1870
|
}
|
|
1644
1871
|
/**
|
|
1645
1872
|
* Return the raw precompute JSON for `contentHash`, spawning at most one
|
|
@@ -1650,26 +1877,30 @@ function computeWithLock(resolvedPath, tailwindNodePath, contentHash, cachePath,
|
|
|
1650
1877
|
const lockPath = (0, node_path.join)(CACHE_DIR, `${contentHash}.lock`);
|
|
1651
1878
|
const staleMs = timeout + 3e4;
|
|
1652
1879
|
try {
|
|
1653
|
-
(0, node_fs.mkdirSync)(CACHE_DIR, {
|
|
1880
|
+
(0, node_fs.mkdirSync)(CACHE_DIR, {
|
|
1881
|
+
recursive: true,
|
|
1882
|
+
mode: 448
|
|
1883
|
+
});
|
|
1654
1884
|
} catch {
|
|
1655
1885
|
return precomputeAndRead(resolvedPath, tailwindNodePath, cachePath, timeout);
|
|
1656
1886
|
}
|
|
1657
1887
|
const start = Date.now();
|
|
1658
1888
|
for (;;) {
|
|
1659
|
-
const
|
|
1660
|
-
if (
|
|
1889
|
+
const cached = tryReadCache(cachePath);
|
|
1890
|
+
if (cached) return cached;
|
|
1661
1891
|
let lockFd;
|
|
1662
1892
|
try {
|
|
1663
1893
|
lockFd = (0, node_fs.openSync)(lockPath, "wx");
|
|
1664
1894
|
} catch (cause) {
|
|
1665
1895
|
if (cause.code === "EEXIST") {
|
|
1666
|
-
if (lockAgeMs(lockPath) > staleMs || Date.now() - start > staleMs * 2)
|
|
1896
|
+
if (lockAgeMs(lockPath) > staleMs || Date.now() - start > staleMs * 2) reclaimStaleLock(lockPath);
|
|
1667
1897
|
else syncSleep(LOCK_POLL_MS);
|
|
1668
1898
|
continue;
|
|
1669
1899
|
}
|
|
1670
1900
|
return precomputeAndRead(resolvedPath, tailwindNodePath, cachePath, timeout);
|
|
1671
1901
|
}
|
|
1672
1902
|
try {
|
|
1903
|
+
tryUnlink(cachePath);
|
|
1673
1904
|
return precomputeAndRead(resolvedPath, tailwindNodePath, cachePath, timeout);
|
|
1674
1905
|
} finally {
|
|
1675
1906
|
(0, node_fs.closeSync)(lockFd);
|
|
@@ -1692,17 +1923,12 @@ function loadDesignSystemSync(cssPath, timeout) {
|
|
|
1692
1923
|
} catch (cause) {
|
|
1693
1924
|
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 });
|
|
1694
1925
|
}
|
|
1695
|
-
const contentHash = computeContentHash(content);
|
|
1926
|
+
const contentHash = computeContentHash(hashableContent(resolvedPath, content));
|
|
1696
1927
|
const contentCachePath = getContentCachePath(contentHash);
|
|
1697
1928
|
const cached = tryReadCache(contentCachePath);
|
|
1698
1929
|
if (cached) return cached;
|
|
1699
1930
|
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.");
|
|
1700
|
-
|
|
1701
|
-
try {
|
|
1702
|
-
return JSON.parse(raw);
|
|
1703
|
-
} catch (cause) {
|
|
1704
|
-
throw new DesignSystemLoadError(`Precompute output for "${resolvedPath}" was not valid JSON.`, "This is likely a bug in oxlint-tailwindcss. Please open an issue with the CSS that triggered it.", { cause: cause instanceof Error ? cause : void 0 });
|
|
1705
|
-
}
|
|
1931
|
+
return computeWithLock(resolvedPath, TAILWIND_NODE_PATH, contentHash, contentCachePath, timeout ?? 6e4);
|
|
1706
1932
|
}
|
|
1707
1933
|
//#endregion
|
|
1708
1934
|
//#region src/design-system/debug.ts
|
|
@@ -2176,8 +2402,14 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2176
2402
|
if (allowlist.has(className)) return true;
|
|
2177
2403
|
return ignorePrefixes.some((prefix) => className.startsWith(prefix));
|
|
2178
2404
|
}
|
|
2179
|
-
function
|
|
2180
|
-
|
|
2405
|
+
function strippedUtility(className) {
|
|
2406
|
+
const { utility, variant } = splitUtilityAndVariant(className);
|
|
2407
|
+
const { bare, position } = splitImportant(utility);
|
|
2408
|
+
return {
|
|
2409
|
+
variant,
|
|
2410
|
+
bare,
|
|
2411
|
+
position
|
|
2412
|
+
};
|
|
2181
2413
|
}
|
|
2182
2414
|
function check(locations) {
|
|
2183
2415
|
if (locations.length === 0) return;
|
|
@@ -2191,8 +2423,8 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2191
2423
|
if (shouldIgnore(cls)) continue;
|
|
2192
2424
|
const validity = cache.classValidity(cls);
|
|
2193
2425
|
if (validity === "valid") continue;
|
|
2194
|
-
const
|
|
2195
|
-
if (DEPRECATED_MAP[
|
|
2426
|
+
const { variant, bare, position } = strippedUtility(cls);
|
|
2427
|
+
if (DEPRECATED_MAP[bare]) continue;
|
|
2196
2428
|
if (validity === "missing-prefix") {
|
|
2197
2429
|
const fixed = `${cache.prefix}:${cls}`;
|
|
2198
2430
|
const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? fixed : c));
|
|
@@ -2217,7 +2449,8 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2217
2449
|
});
|
|
2218
2450
|
continue;
|
|
2219
2451
|
}
|
|
2220
|
-
const
|
|
2452
|
+
const suggestionBare = findBestSuggestion(bare, cache.validClasses);
|
|
2453
|
+
const suggestion = suggestionBare ? variant + reattachImportant(suggestionBare, position) : null;
|
|
2221
2454
|
if (suggestion) {
|
|
2222
2455
|
const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? suggestion : c));
|
|
2223
2456
|
context.report({
|
|
@@ -2377,7 +2610,7 @@ const noConflictingClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2377
2610
|
}],
|
|
2378
2611
|
defaultOptions: [{}],
|
|
2379
2612
|
messages: {
|
|
2380
|
-
conflict: "\"{{classA}}\" and \"{{classB}}\" affect {{properties}}.
|
|
2613
|
+
conflict: "\"{{classA}}\" and \"{{classB}}\" both affect {{properties}}. Only one applies — which wins depends on the generated stylesheet order, not the attribute order. Remove one.",
|
|
2381
2614
|
...DS_UNAVAILABLE_MESSAGE
|
|
2382
2615
|
}
|
|
2383
2616
|
},
|
|
@@ -2410,9 +2643,11 @@ const noConflictingClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2410
2643
|
const propsA = propsMap.get(classA) ?? [];
|
|
2411
2644
|
for (let j = i + 1; j < variantClasses.length; j++) {
|
|
2412
2645
|
const classB = variantClasses[j];
|
|
2646
|
+
if (classA === classB) continue;
|
|
2413
2647
|
const propsB = propsMap.get(classB) ?? [];
|
|
2414
2648
|
if (shouldSkipPair(classA, classB, propsA, propsB)) continue;
|
|
2415
|
-
const
|
|
2649
|
+
const propsBSet = new Set(propsB);
|
|
2650
|
+
const overlap = propsA.filter((p) => propsBSet.has(p));
|
|
2416
2651
|
if (overlap.length > 0) {
|
|
2417
2652
|
const propList = overlap.length <= 3 ? `"${overlap.join("\", \"")}"` : `${overlap.length} CSS properties`;
|
|
2418
2653
|
context.report({
|
|
@@ -2421,8 +2656,7 @@ const noConflictingClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2421
2656
|
data: {
|
|
2422
2657
|
classA,
|
|
2423
2658
|
classB,
|
|
2424
|
-
properties: propList
|
|
2425
|
-
winner: classB
|
|
2659
|
+
properties: propList
|
|
2426
2660
|
}
|
|
2427
2661
|
});
|
|
2428
2662
|
}
|
|
@@ -2454,16 +2688,104 @@ const noConflictingClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2454
2688
|
*/
|
|
2455
2689
|
const BUFFER_SIZE = 4 * 1024 * 1024;
|
|
2456
2690
|
const HEADER_INTS = 4;
|
|
2691
|
+
const LENGTH_OFFSET = HEADER_INTS * 4;
|
|
2457
2692
|
const DATA_OFFSET = 20;
|
|
2458
2693
|
const INIT_TIMEOUT = 6e4;
|
|
2459
2694
|
const REQUEST_TIMEOUT = 3e4;
|
|
2695
|
+
/**
|
|
2696
|
+
* Build the worker script shared by `sort-service` and `canonicalize-service`.
|
|
2697
|
+
* Owns the entire SharedArrayBuffer protocol (offsets derived from the same
|
|
2698
|
+
* constants the host uses, so they can't drift), the design-system load with
|
|
2699
|
+
* error propagation (DS-M4: the real cause is written into the buffer so the
|
|
2700
|
+
* host can surface it, not a generic "failed to load"), the ready signal, and
|
|
2701
|
+
* the request loop. `handlerExpr` is a function expression `(ds, request) =>
|
|
2702
|
+
* result` — the only part that differs between services.
|
|
2703
|
+
*/
|
|
2704
|
+
function makeWorkerScript(handlerExpr) {
|
|
2705
|
+
return `
|
|
2706
|
+
const { workerData } = require('worker_threads');
|
|
2707
|
+
async function main() {
|
|
2708
|
+
const { sharedBuffer, cssPath } = workerData;
|
|
2709
|
+
const control = new Int32Array(sharedBuffer, 0, ${HEADER_INTS});
|
|
2710
|
+
const lengthView = new DataView(sharedBuffer, ${LENGTH_OFFSET}, 4);
|
|
2711
|
+
const dataArea = new Uint8Array(sharedBuffer, ${DATA_OFFSET});
|
|
2712
|
+
|
|
2713
|
+
// On load failure, write the real cause into the data region so the host can
|
|
2714
|
+
// report it instead of a bare "failed to load the design system".
|
|
2715
|
+
function signalLoadError(e) {
|
|
2716
|
+
try {
|
|
2717
|
+
const msg = Buffer.from(String((e && e.message) || e || 'unknown design-system load error'), 'utf-8');
|
|
2718
|
+
const n = Math.min(msg.length, dataArea.length);
|
|
2719
|
+
dataArea.set(msg.subarray(0, n), 0);
|
|
2720
|
+
lengthView.setUint32(0, n);
|
|
2721
|
+
} catch {}
|
|
2722
|
+
Atomics.store(control, 2, -1);
|
|
2723
|
+
Atomics.notify(control, 2);
|
|
2724
|
+
}
|
|
2725
|
+
|
|
2726
|
+
let ds;
|
|
2727
|
+
try {
|
|
2728
|
+
const { __unstable__loadDesignSystem } = require(workerData.tailwindNodePath);
|
|
2729
|
+
const { readFileSync } = require('fs');
|
|
2730
|
+
const { dirname } = require('path');
|
|
2731
|
+
const css = readFileSync(cssPath, 'utf-8');
|
|
2732
|
+
ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
|
|
2733
|
+
} catch (e) {
|
|
2734
|
+
signalLoadError(e);
|
|
2735
|
+
return;
|
|
2736
|
+
}
|
|
2737
|
+
|
|
2738
|
+
Atomics.store(control, 2, 1);
|
|
2739
|
+
Atomics.notify(control, 2);
|
|
2740
|
+
|
|
2741
|
+
const handler = ${handlerExpr};
|
|
2742
|
+
|
|
2743
|
+
while (true) {
|
|
2744
|
+
Atomics.wait(control, 0, 0);
|
|
2745
|
+
const len = lengthView.getUint32(0);
|
|
2746
|
+
const requestStr = Buffer.from(dataArea.slice(0, len)).toString('utf-8');
|
|
2747
|
+
Atomics.store(control, 0, 0);
|
|
2748
|
+
|
|
2749
|
+
let response;
|
|
2750
|
+
try {
|
|
2751
|
+
const request = JSON.parse(requestStr);
|
|
2752
|
+
const result = handler(ds, request);
|
|
2753
|
+
response = Buffer.from(JSON.stringify(result), 'utf-8');
|
|
2754
|
+
} catch {
|
|
2755
|
+
response = Buffer.from('null', 'utf-8');
|
|
2756
|
+
}
|
|
2757
|
+
|
|
2758
|
+
// DS-M6: if the response doesn't fit the shared buffer, reply with a
|
|
2759
|
+
// sentinel the host reads as a rejected request, instead of letting
|
|
2760
|
+
// dataArea.set throw and kill the worker (which would hang the caller
|
|
2761
|
+
// until the request timeout and then report a misleading timeout).
|
|
2762
|
+
if (response.length > dataArea.length) {
|
|
2763
|
+
response = Buffer.from('null', 'utf-8');
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2766
|
+
dataArea.set(response, 0);
|
|
2767
|
+
lengthView.setUint32(0, response.length);
|
|
2768
|
+
Atomics.store(control, 1, 1);
|
|
2769
|
+
Atomics.notify(control, 1);
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
main().catch(() => {});
|
|
2773
|
+
`;
|
|
2774
|
+
}
|
|
2460
2775
|
var DesignSystemWorker = class {
|
|
2461
2776
|
opts;
|
|
2462
2777
|
ready = null;
|
|
2463
2778
|
lastError = null;
|
|
2779
|
+
lastErrorCssPath = null;
|
|
2464
2780
|
constructor(opts) {
|
|
2465
2781
|
this.opts = opts;
|
|
2466
2782
|
}
|
|
2783
|
+
/** Record an error as sticky for `cssPath` and return it for `throw`. */
|
|
2784
|
+
remember(cssPath, err) {
|
|
2785
|
+
this.lastError = err;
|
|
2786
|
+
this.lastErrorCssPath = cssPath;
|
|
2787
|
+
return err;
|
|
2788
|
+
}
|
|
2467
2789
|
/**
|
|
2468
2790
|
* Ensure the worker is running and pointed at `cssPath`. Returns the
|
|
2469
2791
|
* ready state. Throws `SortServiceError` on any failure (init timeout,
|
|
@@ -2471,14 +2793,12 @@ var DesignSystemWorker = class {
|
|
|
2471
2793
|
* cssPath rethrow without retrying.
|
|
2472
2794
|
*/
|
|
2473
2795
|
ensure(cssPath) {
|
|
2474
|
-
if (this.lastError && this.
|
|
2796
|
+
if (this.lastError && this.lastErrorCssPath === cssPath) throw this.lastError;
|
|
2475
2797
|
if (this.ready && this.ready.cssPath === cssPath) return this.ready;
|
|
2476
2798
|
if (this.ready) this.cleanup();
|
|
2477
2799
|
this.lastError = null;
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
throw this.lastError;
|
|
2481
|
-
}
|
|
2800
|
+
this.lastErrorCssPath = null;
|
|
2801
|
+
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."));
|
|
2482
2802
|
const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
|
|
2483
2803
|
const controlArray = new Int32Array(sharedBuffer, 0, HEADER_INTS);
|
|
2484
2804
|
const lengthView = new DataView(sharedBuffer, HEADER_INTS * 4, 4);
|
|
@@ -2494,22 +2814,22 @@ var DesignSystemWorker = class {
|
|
|
2494
2814
|
}
|
|
2495
2815
|
});
|
|
2496
2816
|
} catch (cause) {
|
|
2497
|
-
this.
|
|
2498
|
-
throw this.lastError;
|
|
2817
|
+
throw this.remember(cssPath, new SortServiceError(`Failed to spawn ${this.opts.serviceName} worker for "${cssPath}".`, "This is unexpected; please open an issue with the error details.", { cause: cause instanceof Error ? cause : void 0 }));
|
|
2499
2818
|
}
|
|
2500
2819
|
worker.unref();
|
|
2501
2820
|
worker.on("error", (err) => {
|
|
2502
2821
|
this.lastError = new SortServiceError(`${this.opts.serviceName} worker died: ${err.message}`, "The worker will not be restarted in this process. Restart the lint session.", { cause: err });
|
|
2822
|
+
this.lastErrorCssPath = cssPath;
|
|
2503
2823
|
});
|
|
2504
2824
|
if (Atomics.wait(controlArray, 2, 0, INIT_TIMEOUT) === "timed-out") {
|
|
2505
|
-
this.lastError = new SortServiceError(`${this.opts.serviceName} worker timed out loading the design system from "${cssPath}" after ${INIT_TIMEOUT}ms.`, "Raise settings.tailwindcss.timeout if your machine is slow, or verify the CSS imports resolve.");
|
|
2506
2825
|
this.terminateWorker(worker);
|
|
2507
|
-
throw this.
|
|
2826
|
+
throw this.remember(cssPath, new SortServiceError(`${this.opts.serviceName} worker timed out loading the design system from "${cssPath}" after ${INIT_TIMEOUT}ms.`, "Verify the CSS imports resolve; this can also happen if the machine or CI runner is heavily loaded."));
|
|
2508
2827
|
}
|
|
2509
2828
|
if (controlArray[2] === -1) {
|
|
2510
|
-
|
|
2829
|
+
const len = lengthView.getUint32(0);
|
|
2830
|
+
const detail = len > 0 ? Buffer.from(dataArea.slice(0, len)).toString("utf-8") : "";
|
|
2511
2831
|
this.terminateWorker(worker);
|
|
2512
|
-
throw this.
|
|
2832
|
+
throw this.remember(cssPath, new SortServiceError(`${this.opts.serviceName} worker failed to load the design system from "${cssPath}".${detail ? ` ${detail}` : ""}`, "Verify @tailwindcss/node is installed and the CSS file (and its imports) is valid."));
|
|
2513
2833
|
}
|
|
2514
2834
|
this.ready = {
|
|
2515
2835
|
worker,
|
|
@@ -2533,9 +2853,8 @@ var DesignSystemWorker = class {
|
|
|
2533
2853
|
Atomics.store(state.controlArray, 0, 1);
|
|
2534
2854
|
Atomics.notify(state.controlArray, 0);
|
|
2535
2855
|
if (Atomics.wait(state.controlArray, 1, 0, REQUEST_TIMEOUT) === "timed-out") {
|
|
2536
|
-
this.lastError = new SortServiceError(`${this.opts.serviceName} worker request timed out after ${REQUEST_TIMEOUT}ms.`, "Raise settings.tailwindcss.timeout if your machine is slow.");
|
|
2537
2856
|
this.cleanup();
|
|
2538
|
-
throw this.
|
|
2857
|
+
throw this.remember(cssPath, new SortServiceError(`${this.opts.serviceName} worker request timed out after ${REQUEST_TIMEOUT}ms.`, "This is unexpected for typical class lists; please open an issue if it persists."));
|
|
2539
2858
|
}
|
|
2540
2859
|
const responseLen = state.lengthView.getUint32(0);
|
|
2541
2860
|
const responseStr = Buffer.from(state.dataArea.slice(0, responseLen)).toString("utf-8");
|
|
@@ -2544,20 +2863,19 @@ var DesignSystemWorker = class {
|
|
|
2544
2863
|
try {
|
|
2545
2864
|
parsed = JSON.parse(responseStr);
|
|
2546
2865
|
} catch (cause) {
|
|
2547
|
-
this.lastError = new SortServiceError(`${this.opts.serviceName} worker returned non-JSON response.`, "This is a bug; please open an issue.", { cause: cause instanceof Error ? cause : void 0 });
|
|
2548
2866
|
this.cleanup();
|
|
2549
|
-
throw this.
|
|
2867
|
+
throw this.remember(cssPath, new SortServiceError(`${this.opts.serviceName} worker returned non-JSON response.`, "This is a bug; please open an issue.", { cause: cause instanceof Error ? cause : void 0 }));
|
|
2550
2868
|
}
|
|
2551
2869
|
if (parsed === null) {
|
|
2552
|
-
this.lastError = new SortServiceError(`${this.opts.serviceName} worker returned null — request body was rejected.`, "This is a bug; please open an issue with the input that triggered it.");
|
|
2553
2870
|
this.cleanup();
|
|
2554
|
-
throw this.
|
|
2871
|
+
throw this.remember(cssPath, new SortServiceError(`${this.opts.serviceName} worker returned null — the request body was rejected or its response did not fit the buffer.`, "This is a bug; please open an issue with the input that triggered it."));
|
|
2555
2872
|
}
|
|
2556
2873
|
return parsed;
|
|
2557
2874
|
}
|
|
2558
2875
|
reset() {
|
|
2559
2876
|
this.cleanup();
|
|
2560
2877
|
this.lastError = null;
|
|
2878
|
+
this.lastErrorCssPath = null;
|
|
2561
2879
|
}
|
|
2562
2880
|
cleanup() {
|
|
2563
2881
|
if (this.ready) {
|
|
@@ -2589,60 +2907,14 @@ var DesignSystemWorker = class {
|
|
|
2589
2907
|
* subsequent lookup is O(1).
|
|
2590
2908
|
*/
|
|
2591
2909
|
const canonWorker = new DesignSystemWorker({
|
|
2592
|
-
workerScript: `
|
|
2593
|
-
const {
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
let ds;
|
|
2602
|
-
try {
|
|
2603
|
-
const { __unstable__loadDesignSystem } = require(workerData.tailwindNodePath);
|
|
2604
|
-
const { readFileSync } = require('fs');
|
|
2605
|
-
const { dirname } = require('path');
|
|
2606
|
-
const css = readFileSync(cssPath, 'utf-8');
|
|
2607
|
-
ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
|
|
2608
|
-
} catch {
|
|
2609
|
-
Atomics.store(control, 2, -1);
|
|
2610
|
-
Atomics.notify(control, 2);
|
|
2611
|
-
return;
|
|
2612
|
-
}
|
|
2613
|
-
|
|
2614
|
-
Atomics.store(control, 2, 1);
|
|
2615
|
-
Atomics.notify(control, 2);
|
|
2616
|
-
|
|
2617
|
-
while (true) {
|
|
2618
|
-
Atomics.wait(control, 0, 0);
|
|
2619
|
-
const len = lengthView.getUint32(0);
|
|
2620
|
-
const requestStr = Buffer.from(dataArea.slice(0, len)).toString('utf-8');
|
|
2621
|
-
Atomics.store(control, 0, 0);
|
|
2622
|
-
|
|
2623
|
-
let response;
|
|
2624
|
-
try {
|
|
2625
|
-
const { classes, rem } = JSON.parse(requestStr);
|
|
2626
|
-
const options = rem ? { rem } : undefined;
|
|
2627
|
-
// canonicalizeCandidates deduplicates its input, so we must call it
|
|
2628
|
-
// one class at a time to preserve order/length. See sync-loader.ts.
|
|
2629
|
-
const result = classes.map((cls) => {
|
|
2630
|
-
const r = ds.canonicalizeCandidates([cls], options);
|
|
2631
|
-
return r[0] ?? cls;
|
|
2632
|
-
});
|
|
2633
|
-
response = Buffer.from(JSON.stringify(result), 'utf-8');
|
|
2634
|
-
} catch {
|
|
2635
|
-
response = Buffer.from('null', 'utf-8');
|
|
2636
|
-
}
|
|
2637
|
-
|
|
2638
|
-
dataArea.set(response, 0);
|
|
2639
|
-
lengthView.setUint32(0, response.length);
|
|
2640
|
-
Atomics.store(control, 1, 1);
|
|
2641
|
-
Atomics.notify(control, 1);
|
|
2642
|
-
}
|
|
2643
|
-
}
|
|
2644
|
-
main();
|
|
2645
|
-
`,
|
|
2910
|
+
workerScript: makeWorkerScript(`(ds, request) => {
|
|
2911
|
+
const { classes, rem } = request;
|
|
2912
|
+
const options = rem ? { rem } : undefined;
|
|
2913
|
+
return classes.map((cls) => {
|
|
2914
|
+
const r = ds.canonicalizeCandidates([cls], options);
|
|
2915
|
+
return r[0] ?? cls;
|
|
2916
|
+
});
|
|
2917
|
+
}`),
|
|
2646
2918
|
serviceName: "canonicalize"
|
|
2647
2919
|
});
|
|
2648
2920
|
/**
|
|
@@ -2687,7 +2959,7 @@ function canonicalizeClassesSync(cssPath, classes, rem) {
|
|
|
2687
2959
|
for (let k = 0; k < uniqueMissing.length; k++) freshByClass.set(uniqueMissing[k], fresh[k]);
|
|
2688
2960
|
for (let j = 0; j < missing.length; j++) {
|
|
2689
2961
|
const cls = missing[j];
|
|
2690
|
-
const value = freshByClass.get(cls) ?? cls;
|
|
2962
|
+
const value = roundRemValue(freshByClass.get(cls) ?? cls);
|
|
2691
2963
|
canonCache.set(cachePrefix + cls, value);
|
|
2692
2964
|
out[missingIdx[j]] = value;
|
|
2693
2965
|
}
|
|
@@ -2779,62 +3051,17 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
|
2779
3051
|
* Atomics.wait, fail-loud, sticky lastError) lives in `./ds-worker.ts`.
|
|
2780
3052
|
*/
|
|
2781
3053
|
const sortWorker = new DesignSystemWorker({
|
|
2782
|
-
workerScript: `
|
|
2783
|
-
const
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
const { __unstable__loadDesignSystem } = require(workerData.tailwindNodePath);
|
|
2794
|
-
const { readFileSync } = require('fs');
|
|
2795
|
-
const { dirname } = require('path');
|
|
2796
|
-
const css = readFileSync(cssPath, 'utf-8');
|
|
2797
|
-
ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
|
|
2798
|
-
} catch {
|
|
2799
|
-
Atomics.store(control, 2, -1);
|
|
2800
|
-
Atomics.notify(control, 2);
|
|
2801
|
-
return;
|
|
2802
|
-
}
|
|
2803
|
-
|
|
2804
|
-
Atomics.store(control, 2, 1);
|
|
2805
|
-
Atomics.notify(control, 2);
|
|
2806
|
-
|
|
2807
|
-
while (true) {
|
|
2808
|
-
Atomics.wait(control, 0, 0);
|
|
2809
|
-
const len = lengthView.getUint32(0);
|
|
2810
|
-
const requestStr = Buffer.from(dataArea.slice(0, len)).toString('utf-8');
|
|
2811
|
-
Atomics.store(control, 0, 0);
|
|
2812
|
-
|
|
2813
|
-
let response;
|
|
2814
|
-
try {
|
|
2815
|
-
const classes = JSON.parse(requestStr);
|
|
2816
|
-
const ordered = ds.getClassOrder(classes);
|
|
2817
|
-
const sorted = [...ordered]
|
|
2818
|
-
.sort((a, b) => {
|
|
2819
|
-
if (a[1] === null && b[1] === null) return 0;
|
|
2820
|
-
if (a[1] === null) return -1;
|
|
2821
|
-
if (b[1] === null) return 1;
|
|
2822
|
-
return a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0;
|
|
2823
|
-
})
|
|
2824
|
-
.map(([name]) => name);
|
|
2825
|
-
response = Buffer.from(JSON.stringify(sorted), 'utf-8');
|
|
2826
|
-
} catch {
|
|
2827
|
-
response = Buffer.from('null', 'utf-8');
|
|
2828
|
-
}
|
|
2829
|
-
|
|
2830
|
-
dataArea.set(response, 0);
|
|
2831
|
-
lengthView.setUint32(0, response.length);
|
|
2832
|
-
Atomics.store(control, 1, 1);
|
|
2833
|
-
Atomics.notify(control, 1);
|
|
2834
|
-
}
|
|
2835
|
-
}
|
|
2836
|
-
main();
|
|
2837
|
-
`,
|
|
3054
|
+
workerScript: makeWorkerScript(`(ds, classes) => {
|
|
3055
|
+
const ordered = ds.getClassOrder(classes);
|
|
3056
|
+
return [...ordered]
|
|
3057
|
+
.sort((a, b) => {
|
|
3058
|
+
if (a[1] === null && b[1] === null) return 0;
|
|
3059
|
+
if (a[1] === null) return -1;
|
|
3060
|
+
if (b[1] === null) return 1;
|
|
3061
|
+
return a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0;
|
|
3062
|
+
})
|
|
3063
|
+
.map(([name]) => name);
|
|
3064
|
+
}`),
|
|
2838
3065
|
serviceName: "sort"
|
|
2839
3066
|
});
|
|
2840
3067
|
/**
|
|
@@ -2886,13 +3113,9 @@ const enforceSortOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
2886
3113
|
}
|
|
2887
3114
|
function sortStrict(classes) {
|
|
2888
3115
|
const groups = /* @__PURE__ */ new Map();
|
|
2889
|
-
const groupOrder = [];
|
|
2890
3116
|
for (const cls of classes) {
|
|
2891
3117
|
const { variant } = splitUtilityAndVariant(cls);
|
|
2892
|
-
if (!groups.has(variant))
|
|
2893
|
-
groups.set(variant, []);
|
|
2894
|
-
groupOrder.push(variant);
|
|
2895
|
-
}
|
|
3118
|
+
if (!groups.has(variant)) groups.set(variant, []);
|
|
2896
3119
|
groups.get(variant).push(cls);
|
|
2897
3120
|
}
|
|
2898
3121
|
for (const [, groupClasses] of groups) {
|
|
@@ -3074,26 +3297,6 @@ const enforceShorthand = (0, _oxlint_plugins.defineRule)({
|
|
|
3074
3297
|
}
|
|
3075
3298
|
});
|
|
3076
3299
|
//#endregion
|
|
3077
|
-
//#region src/utils/allowlist.ts
|
|
3078
|
-
/**
|
|
3079
|
-
* Shared regex-allowlist helpers used by rules that accept an `allowlist`
|
|
3080
|
-
* option of regex source strings (currently enforce-logical / enforce-physical).
|
|
3081
|
-
*
|
|
3082
|
-
* Invalid regex sources are skipped rather than thrown so a typo in one
|
|
3083
|
-
* pattern doesn't blow up the entire lint run.
|
|
3084
|
-
*/
|
|
3085
|
-
function compileRegexList(patterns) {
|
|
3086
|
-
if (!patterns || patterns.length === 0) return [];
|
|
3087
|
-
const compiled = [];
|
|
3088
|
-
for (const p of patterns) try {
|
|
3089
|
-
compiled.push(new RegExp(p));
|
|
3090
|
-
} catch {}
|
|
3091
|
-
return compiled;
|
|
3092
|
-
}
|
|
3093
|
-
function matchesAny(value, list) {
|
|
3094
|
-
return list.some((re) => re.test(value));
|
|
3095
|
-
}
|
|
3096
|
-
//#endregion
|
|
3097
3300
|
//#region src/rules/enforce-logical.ts
|
|
3098
3301
|
const LOGICAL_PHYSICAL_SCHEMA = {
|
|
3099
3302
|
type: "object",
|
|
@@ -3234,9 +3437,14 @@ function createDirectionalMapper(context, opts) {
|
|
|
3234
3437
|
if (matchesAny(cls, allowlist)) return null;
|
|
3235
3438
|
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
3236
3439
|
const { bare: bareUtility, position } = splitImportant(utility);
|
|
3440
|
+
const negative = bareUtility.startsWith("-");
|
|
3441
|
+
const core = negative ? bareUtility.slice(1) : bareUtility;
|
|
3237
3442
|
for (const { from, to, axis } of opts.mappings) {
|
|
3238
3443
|
if (direction !== "both" && direction !== axis) continue;
|
|
3239
|
-
if (
|
|
3444
|
+
if (core === from || core.startsWith(`${from}-`)) {
|
|
3445
|
+
const suffix = core.slice(from.length);
|
|
3446
|
+
return `${variant}${reattachImportant(`${negative ? "-" : ""}${to}${suffix}`, position)}`;
|
|
3447
|
+
}
|
|
3240
3448
|
}
|
|
3241
3449
|
return null;
|
|
3242
3450
|
}
|
|
@@ -3379,10 +3587,16 @@ const noRestrictedClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
3379
3587
|
createOnce(context) {
|
|
3380
3588
|
const getConfig = createLazyOptions(context, (o) => ({
|
|
3381
3589
|
restrictedClasses: new Set(o?.classes ?? []),
|
|
3382
|
-
patterns: (o?.patterns ?? []).
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3590
|
+
patterns: (o?.patterns ?? []).flatMap((p) => {
|
|
3591
|
+
try {
|
|
3592
|
+
return [{
|
|
3593
|
+
regex: new RegExp(p.pattern),
|
|
3594
|
+
message: p.message
|
|
3595
|
+
}];
|
|
3596
|
+
} catch {
|
|
3597
|
+
return [];
|
|
3598
|
+
}
|
|
3599
|
+
})
|
|
3386
3600
|
}));
|
|
3387
3601
|
function check(locations) {
|
|
3388
3602
|
const { restrictedClasses, patterns } = getConfig();
|
|
@@ -3511,6 +3725,7 @@ const enforceConsistentImportantPosition = (0, _oxlint_plugins.defineRule)({
|
|
|
3511
3725
|
});
|
|
3512
3726
|
//#endregion
|
|
3513
3727
|
//#region src/rules/enforce-negative-arbitrary-values.ts
|
|
3728
|
+
const SIMPLE_DIMENSION = /^\d*\.?\d+[a-z%]*$/;
|
|
3514
3729
|
function fixClass(cls) {
|
|
3515
3730
|
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
3516
3731
|
const hasImportantPrefix = utility.startsWith("!");
|
|
@@ -3523,6 +3738,7 @@ function fixClass(cls) {
|
|
|
3523
3738
|
if (bracketClose === -1 || bracketClose < bracketOpen) return null;
|
|
3524
3739
|
const innerValue = bare.slice(bracketOpen + 1, bracketClose);
|
|
3525
3740
|
if (innerValue.startsWith("-")) return null;
|
|
3741
|
+
if (!SIMPLE_DIMENSION.test(innerValue)) return null;
|
|
3526
3742
|
const baseUtility = bare.slice(1, bracketOpen);
|
|
3527
3743
|
return `${variant}${hasImportantPrefix ? "!" : ""}${baseUtility}[-${innerValue}]${hasImportantSuffix ? "!" : ""}`;
|
|
3528
3744
|
}
|
|
@@ -3657,13 +3873,48 @@ const KNOWN_PREFIXES = [
|
|
|
3657
3873
|
"via",
|
|
3658
3874
|
"to"
|
|
3659
3875
|
];
|
|
3876
|
+
const PROPERTY_GROUP_BY_UTILITY = {};
|
|
3877
|
+
for (const u of [
|
|
3878
|
+
"block",
|
|
3879
|
+
"inline-block",
|
|
3880
|
+
"inline",
|
|
3881
|
+
"flex",
|
|
3882
|
+
"inline-flex",
|
|
3883
|
+
"grid",
|
|
3884
|
+
"inline-grid",
|
|
3885
|
+
"flow-root",
|
|
3886
|
+
"contents",
|
|
3887
|
+
"table",
|
|
3888
|
+
"inline-table",
|
|
3889
|
+
"table-caption",
|
|
3890
|
+
"table-cell",
|
|
3891
|
+
"table-row",
|
|
3892
|
+
"table-row-group",
|
|
3893
|
+
"table-header-group",
|
|
3894
|
+
"table-footer-group",
|
|
3895
|
+
"table-column",
|
|
3896
|
+
"table-column-group",
|
|
3897
|
+
"list-item",
|
|
3898
|
+
"hidden"
|
|
3899
|
+
]) PROPERTY_GROUP_BY_UTILITY[u] = "display";
|
|
3900
|
+
for (const u of [
|
|
3901
|
+
"static",
|
|
3902
|
+
"fixed",
|
|
3903
|
+
"absolute",
|
|
3904
|
+
"relative",
|
|
3905
|
+
"sticky"
|
|
3906
|
+
]) PROPERTY_GROUP_BY_UTILITY[u] = "position";
|
|
3660
3907
|
/**
|
|
3661
|
-
*
|
|
3662
|
-
*
|
|
3908
|
+
* Maps a utility to a key identifying the CSS property it sets, so a base and a
|
|
3909
|
+
* variant class for the same property group together. Exact-match equivalence
|
|
3910
|
+
* groups (display, position) win; otherwise fall back to the prefix heuristic
|
|
3911
|
+
* (e.g. "bg" from "bg-gray-900", "text" from "text-white").
|
|
3663
3912
|
*/
|
|
3664
3913
|
function getUtilityPrefix(utility) {
|
|
3665
3914
|
let u = splitImportant(utility).bare;
|
|
3666
3915
|
if (u.startsWith("-")) u = u.slice(1);
|
|
3916
|
+
const group = PROPERTY_GROUP_BY_UTILITY[u];
|
|
3917
|
+
if (group) return group;
|
|
3667
3918
|
for (const prefix of KNOWN_PREFIXES) if (u === prefix || u.startsWith(`${prefix}-`)) return prefix;
|
|
3668
3919
|
const dashIdx = u.indexOf("-");
|
|
3669
3920
|
return dashIdx >= 0 ? u.slice(0, dashIdx) : u;
|
|
@@ -3771,13 +4022,10 @@ const noHardcodedColors = (0, _oxlint_plugins.defineRule)({
|
|
|
3771
4022
|
docs: { description: "Disallow hardcoded color values in Tailwind CSS classes" },
|
|
3772
4023
|
schema: [{
|
|
3773
4024
|
type: "object",
|
|
3774
|
-
properties: {
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
items: { type: "string" }
|
|
3779
|
-
}
|
|
3780
|
-
},
|
|
4025
|
+
properties: { allow: {
|
|
4026
|
+
type: "array",
|
|
4027
|
+
items: { type: "string" }
|
|
4028
|
+
} },
|
|
3781
4029
|
additionalProperties: false
|
|
3782
4030
|
}],
|
|
3783
4031
|
defaultOptions: [{ allow: [] }],
|
|
@@ -3809,24 +4057,6 @@ const noHardcodedColors = (0, _oxlint_plugins.defineRule)({
|
|
|
3809
4057
|
});
|
|
3810
4058
|
//#endregion
|
|
3811
4059
|
//#region src/rules/no-contradicting-variants.ts
|
|
3812
|
-
const TARGET_CHANGING_VARIANTS = new Set([
|
|
3813
|
-
"after",
|
|
3814
|
-
"before",
|
|
3815
|
-
"file",
|
|
3816
|
-
"placeholder",
|
|
3817
|
-
"marker",
|
|
3818
|
-
"backdrop",
|
|
3819
|
-
"selection",
|
|
3820
|
-
"first-line",
|
|
3821
|
-
"first-letter"
|
|
3822
|
-
]);
|
|
3823
|
-
function changesTarget(variant) {
|
|
3824
|
-
if (TARGET_CHANGING_VARIANTS.has(variant)) return true;
|
|
3825
|
-
if (variant === "*" || variant === "**") return true;
|
|
3826
|
-
if (variant.startsWith("[") && variant.endsWith("]")) return true;
|
|
3827
|
-
if (variant.startsWith("*:")) return true;
|
|
3828
|
-
return false;
|
|
3829
|
-
}
|
|
3830
4060
|
const noContradictingVariants = (0, _oxlint_plugins.defineRule)({
|
|
3831
4061
|
meta: {
|
|
3832
4062
|
type: "suggestion",
|
|
@@ -3861,18 +4091,6 @@ const noContradictingVariants = (0, _oxlint_plugins.defineRule)({
|
|
|
3861
4091
|
});
|
|
3862
4092
|
//#endregion
|
|
3863
4093
|
//#region src/rules/consistent-variant-order.ts
|
|
3864
|
-
const PSEUDO_ELEMENTS = new Set([
|
|
3865
|
-
"before",
|
|
3866
|
-
"after",
|
|
3867
|
-
"file",
|
|
3868
|
-
"placeholder",
|
|
3869
|
-
"selection",
|
|
3870
|
-
"marker",
|
|
3871
|
-
"backdrop",
|
|
3872
|
-
"first-line",
|
|
3873
|
-
"first-letter",
|
|
3874
|
-
"details-content"
|
|
3875
|
-
]);
|
|
3876
4094
|
const DEFAULT_VARIANT_ORDER = [
|
|
3877
4095
|
"*",
|
|
3878
4096
|
"**",
|
|
@@ -3971,17 +4189,12 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
3971
4189
|
},
|
|
3972
4190
|
createOnce(context) {
|
|
3973
4191
|
const getDS = createLazyLoader(context);
|
|
3974
|
-
const
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
dsCache = getDS().cache;
|
|
3978
|
-
} catch (err) {
|
|
3979
|
-
if (!isFatalError(err)) throw err;
|
|
3980
|
-
}
|
|
3981
|
-
if (o?.order) {
|
|
4192
|
+
const getOptions = createLazyOptions(context, (o) => ({ order: o?.order }));
|
|
4193
|
+
function buildPriority(order, dsCache) {
|
|
4194
|
+
if (order) {
|
|
3982
4195
|
const map = /* @__PURE__ */ new Map();
|
|
3983
|
-
for (let i = 0; i <
|
|
3984
|
-
const fallback =
|
|
4196
|
+
for (let i = 0; i < order.length; i++) map.set(order[i], i);
|
|
4197
|
+
const fallback = order.length;
|
|
3985
4198
|
return (v) => map.get(v) ?? fallback;
|
|
3986
4199
|
}
|
|
3987
4200
|
if (dsCache && dsCache.hasVariantOrder()) {
|
|
@@ -3992,17 +4205,36 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
3992
4205
|
for (let i = 0; i < DEFAULT_VARIANT_ORDER.length; i++) map.set(DEFAULT_VARIANT_ORDER[i], i);
|
|
3993
4206
|
const fallback = DEFAULT_VARIANT_ORDER.length;
|
|
3994
4207
|
return (v) => map.get(v) ?? fallback;
|
|
3995
|
-
}
|
|
3996
|
-
const
|
|
4208
|
+
}
|
|
4209
|
+
const priorityByEntry = /* @__PURE__ */ new Map();
|
|
4210
|
+
const prefixByEntry = /* @__PURE__ */ new Map();
|
|
4211
|
+
function resolveForFile() {
|
|
4212
|
+
let dsCache = null;
|
|
4213
|
+
let entryKey = "";
|
|
3997
4214
|
try {
|
|
3998
|
-
|
|
4215
|
+
const ds = getDS();
|
|
4216
|
+
dsCache = ds.cache;
|
|
4217
|
+
entryKey = ds.entryPoint;
|
|
3999
4218
|
} catch (err) {
|
|
4000
4219
|
if (!isFatalError(err)) throw err;
|
|
4001
|
-
return "";
|
|
4002
4220
|
}
|
|
4003
|
-
|
|
4221
|
+
let priorityOf = priorityByEntry.get(entryKey);
|
|
4222
|
+
if (!priorityOf) {
|
|
4223
|
+
priorityOf = buildPriority(getOptions().order, dsCache);
|
|
4224
|
+
priorityByEntry.set(entryKey, priorityOf);
|
|
4225
|
+
}
|
|
4226
|
+
let prefix = prefixByEntry.get(entryKey);
|
|
4227
|
+
if (prefix === void 0) {
|
|
4228
|
+
prefix = dsCache?.prefix ?? "";
|
|
4229
|
+
prefixByEntry.set(entryKey, prefix);
|
|
4230
|
+
}
|
|
4231
|
+
return {
|
|
4232
|
+
priorityOf,
|
|
4233
|
+
prefix
|
|
4234
|
+
};
|
|
4235
|
+
}
|
|
4004
4236
|
function reorderClass(cls) {
|
|
4005
|
-
const prefix =
|
|
4237
|
+
const { priorityOf, prefix } = resolveForFile();
|
|
4006
4238
|
let pfx = "";
|
|
4007
4239
|
let body = cls;
|
|
4008
4240
|
if (prefix && cls.startsWith(prefix + ":")) {
|
|
@@ -4011,13 +4243,25 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
4011
4243
|
}
|
|
4012
4244
|
const variants = extractVariants(body);
|
|
4013
4245
|
if (variants.length < 2) return null;
|
|
4014
|
-
const priorityOf = getPriority();
|
|
4015
|
-
const sorted = [...variants].sort((a, b) => priorityOf(a) - priorityOf(b));
|
|
4016
|
-
const nonPseudo = [];
|
|
4017
4246
|
const pseudo = [];
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4247
|
+
const rest = [];
|
|
4248
|
+
for (const v of variants) if (isPseudoElementVariant(v)) pseudo.push(v);
|
|
4249
|
+
else rest.push(v);
|
|
4250
|
+
const reorderedRest = [];
|
|
4251
|
+
let segment = [];
|
|
4252
|
+
const flushSegment = () => {
|
|
4253
|
+
if (segment.length === 0) return;
|
|
4254
|
+
segment.sort((a, b) => priorityOf(a) - priorityOf(b));
|
|
4255
|
+
reorderedRest.push(...segment);
|
|
4256
|
+
segment = [];
|
|
4257
|
+
};
|
|
4258
|
+
for (const v of rest) if (isSelectorBarrier(v)) {
|
|
4259
|
+
flushSegment();
|
|
4260
|
+
reorderedRest.push(v);
|
|
4261
|
+
} else segment.push(v);
|
|
4262
|
+
flushSegment();
|
|
4263
|
+
pseudo.sort((a, b) => priorityOf(a) - priorityOf(b));
|
|
4264
|
+
const final = [...reorderedRest, ...pseudo];
|
|
4021
4265
|
if (variants.every((v, i) => v === final[i])) return null;
|
|
4022
4266
|
const utility = extractUtility(body);
|
|
4023
4267
|
return pfx + final.join(":") + ":" + utility;
|