oxlint-tailwindcss 1.2.0 → 1.3.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 +24 -1
- package/dist/index.cjs +433 -256
- package/dist/index.d.cts +1 -2
- package/dist/index.d.mts +1 -2
- package/dist/index.mjs +435 -260
- package/package.json +7 -7
- 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
|
|
@@ -1507,8 +1582,20 @@ async function main() {
|
|
|
1507
1582
|
main()
|
|
1508
1583
|
.then(() => { Atomics.store(control, 2, 1); Atomics.notify(control, 2); })
|
|
1509
1584
|
.catch((e) => signalError(e));
|
|
1585
|
+
} catch (e) {
|
|
1586
|
+
signalError(e);
|
|
1587
|
+
}
|
|
1510
1588
|
`;
|
|
1511
|
-
|
|
1589
|
+
function cacheDirName() {
|
|
1590
|
+
try {
|
|
1591
|
+
const info = (0, node_os.userInfo)();
|
|
1592
|
+
const id = typeof info.uid === "number" && info.uid >= 0 ? String(info.uid) : info.username;
|
|
1593
|
+
return `oxlint-tailwindcss-${String(id).replace(/[^a-zA-Z0-9_-]/g, "_")}`;
|
|
1594
|
+
} catch {
|
|
1595
|
+
return "oxlint-tailwindcss";
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
const CACHE_DIR = (0, node_path.join)((0, node_os.tmpdir)(), cacheDirName());
|
|
1512
1599
|
/**
|
|
1513
1600
|
* Cache key derived from:
|
|
1514
1601
|
* - md5(PRECOMPUTE_SCRIPT): auto-invalidates when our precompute logic changes,
|
|
@@ -1527,17 +1614,73 @@ const CACHE_KEY = computeCacheKey(PRECOMPUTE_SCRIPT, TAILWIND_NODE_VERSION);
|
|
|
1527
1614
|
function computeContentHash(content) {
|
|
1528
1615
|
return (0, node_crypto.createHash)("md5").update(`${CACHE_KEY}:${content}`).digest("hex");
|
|
1529
1616
|
}
|
|
1617
|
+
const IMPORT_RE = /@import\s+(?:url\(\s*)?['"]([^'"]+)['"]/g;
|
|
1618
|
+
/**
|
|
1619
|
+
* Concatenate the entry CSS with the content of its locally-imported files, so
|
|
1620
|
+
* the cache key invalidates when an `@import`'d file changes — not only when the
|
|
1621
|
+
* entry itself does (DS-A2). Without this, editing a `@theme`/component file
|
|
1622
|
+
* pulled in via `@import "./theme.css"` served a stale design system until the
|
|
1623
|
+
* entry was touched or the Tailwind version changed.
|
|
1624
|
+
*
|
|
1625
|
+
* Resolves RELATIVE imports (`./`, `../`) recursively up to a small depth;
|
|
1626
|
+
* package imports (`@import "tailwindcss"`, `tw-animate-css`) are already
|
|
1627
|
+
* covered by the `@tailwindcss/node` version baked into CACHE_KEY. Best-effort:
|
|
1628
|
+
* an unreadable import contributes nothing (it can't affect the DS either).
|
|
1629
|
+
*/
|
|
1630
|
+
function hashableContent(entryPath, entryContent) {
|
|
1631
|
+
const parts = [entryContent];
|
|
1632
|
+
const seen = new Set([(0, node_path.resolve)(entryPath)]);
|
|
1633
|
+
const visit = (cssPath, content, depth) => {
|
|
1634
|
+
if (depth <= 0) return;
|
|
1635
|
+
const baseDir = (0, node_path.dirname)(cssPath);
|
|
1636
|
+
IMPORT_RE.lastIndex = 0;
|
|
1637
|
+
const specifiers = [];
|
|
1638
|
+
let m;
|
|
1639
|
+
while ((m = IMPORT_RE.exec(content)) !== null) if (m[1].startsWith(".")) specifiers.push(m[1]);
|
|
1640
|
+
for (const spec of specifiers) {
|
|
1641
|
+
const importPath = (0, node_path.resolve)(baseDir, spec.split("?")[0]);
|
|
1642
|
+
if (seen.has(importPath)) continue;
|
|
1643
|
+
seen.add(importPath);
|
|
1644
|
+
let importContent;
|
|
1645
|
+
try {
|
|
1646
|
+
importContent = (0, node_fs.readFileSync)(importPath, "utf-8");
|
|
1647
|
+
} catch {
|
|
1648
|
+
continue;
|
|
1649
|
+
}
|
|
1650
|
+
parts.push(importContent);
|
|
1651
|
+
visit(importPath, importContent, depth - 1);
|
|
1652
|
+
}
|
|
1653
|
+
};
|
|
1654
|
+
visit((0, node_path.resolve)(entryPath), entryContent, 4);
|
|
1655
|
+
return parts.join("\0");
|
|
1656
|
+
}
|
|
1530
1657
|
function getContentCachePath(contentHash) {
|
|
1531
1658
|
return (0, node_path.join)(CACHE_DIR, `${contentHash}.json`);
|
|
1532
1659
|
}
|
|
1660
|
+
/**
|
|
1661
|
+
* Minimal shape check for a cache payload. Guards against (a) a poisoned file
|
|
1662
|
+
* planted by a local attacker and (b) a corrupt/half-written or version-skewed
|
|
1663
|
+
* file. A `{}` that is valid JSON but missing fields would otherwise blow up
|
|
1664
|
+
* later in `DesignSystemCache.fromPrecomputed` with a raw TypeError that isn't
|
|
1665
|
+
* plugin-fatal, breaking the lint with no diagnostic. We don't deep-validate
|
|
1666
|
+
* every entry — just enough that `fromPrecomputed` can rely on the fields.
|
|
1667
|
+
*/
|
|
1668
|
+
function isPrecomputedData(data) {
|
|
1669
|
+
if (typeof data !== "object" || data === null) return false;
|
|
1670
|
+
const d = data;
|
|
1671
|
+
const isObject = (v) => typeof v === "object" && v !== null;
|
|
1672
|
+
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);
|
|
1673
|
+
}
|
|
1533
1674
|
function tryReadCache(cachePath) {
|
|
1534
1675
|
const raw = tryReadRawCache(cachePath);
|
|
1535
1676
|
if (raw === null) return null;
|
|
1677
|
+
let data;
|
|
1536
1678
|
try {
|
|
1537
|
-
|
|
1679
|
+
data = JSON.parse(raw);
|
|
1538
1680
|
} catch {
|
|
1539
1681
|
return null;
|
|
1540
1682
|
}
|
|
1683
|
+
return isPrecomputedData(data) ? data : null;
|
|
1541
1684
|
}
|
|
1542
1685
|
function tryReadRawCache(cachePath) {
|
|
1543
1686
|
try {
|
|
@@ -1564,6 +1707,23 @@ function tryUnlink(path) {
|
|
|
1564
1707
|
(0, node_fs.unlinkSync)(path);
|
|
1565
1708
|
} catch {}
|
|
1566
1709
|
}
|
|
1710
|
+
/**
|
|
1711
|
+
* Reclaim a stale lock by exclusive rename rather than unlink (DS-M1). Two
|
|
1712
|
+
* waiters that both judge the lock stale would otherwise both `unlink` it — and
|
|
1713
|
+
* the second unlink could delete a FRESH lock a third isolate just created,
|
|
1714
|
+
* letting two precomputes run in parallel (the very amplification the lock
|
|
1715
|
+
* exists to prevent, #24). `renameSync` moves the file atomically: only one
|
|
1716
|
+
* waiter wins the move; the loser gets ENOENT and loops back to re-check.
|
|
1717
|
+
*/
|
|
1718
|
+
function reclaimStaleLock(lockPath) {
|
|
1719
|
+
const reclaimPath = `${lockPath}.reclaim.${process.pid}.${node_worker_threads.threadId}.${precomputeSeq++}`;
|
|
1720
|
+
try {
|
|
1721
|
+
(0, node_fs.renameSync)(lockPath, reclaimPath);
|
|
1722
|
+
} catch {
|
|
1723
|
+
return;
|
|
1724
|
+
}
|
|
1725
|
+
tryUnlink(reclaimPath);
|
|
1726
|
+
}
|
|
1567
1727
|
/** control[2] — the worker's ready/done signal (0=loading, 1=done, -1=error). */
|
|
1568
1728
|
const PRECOMPUTE_SIGNAL_INDEX = 2;
|
|
1569
1729
|
const ERR_BUFFER_SIZE = 64 * 1024;
|
|
@@ -1616,15 +1776,12 @@ function runPrecomputeViaWorker(resolvedPath, tailwindNodePath, cachePath, timeo
|
|
|
1616
1776
|
} catch (cause) {
|
|
1617
1777
|
throw precomputeLoadError(resolvedPath, cause);
|
|
1618
1778
|
}
|
|
1619
|
-
|
|
1620
|
-
worker.on("error", (err) => {
|
|
1621
|
-
workerError = err;
|
|
1622
|
-
});
|
|
1779
|
+
worker.on("error", () => {});
|
|
1623
1780
|
try {
|
|
1624
1781
|
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
1782
|
if (control[PRECOMPUTE_SIGNAL_INDEX] === -1) {
|
|
1626
1783
|
const len = errLengthView.getUint32(0);
|
|
1627
|
-
throw precomputeLoadError(resolvedPath, len > 0 ? new Error(Buffer.from(errDataArea.slice(0, len)).toString("utf-8")) :
|
|
1784
|
+
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
1785
|
}
|
|
1629
1786
|
} finally {
|
|
1630
1787
|
tryUnlink(tmpPath);
|
|
@@ -1632,14 +1789,17 @@ function runPrecomputeViaWorker(resolvedPath, tailwindNodePath, cachePath, timeo
|
|
|
1632
1789
|
}
|
|
1633
1790
|
}
|
|
1634
1791
|
/**
|
|
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
|
|
1792
|
+
* Run the precompute worker, then read back and validate the JSON it wrote to
|
|
1793
|
+
* `cachePath`. Used by both the lock-winner path and the uncoordinated degrade
|
|
1794
|
+
* path. Returns the validated `PrecomputedData` (never a raw string), so a
|
|
1795
|
+
* malformed payload surfaces as a clear diagnostic here instead of crashing
|
|
1796
|
+
* later in `DesignSystemCache.fromPrecomputed`.
|
|
1637
1797
|
*/
|
|
1638
1798
|
function precomputeAndRead(resolvedPath, tailwindNodePath, cachePath, timeout) {
|
|
1639
1799
|
runPrecomputeViaWorker(resolvedPath, tailwindNodePath, cachePath, timeout);
|
|
1640
|
-
const
|
|
1641
|
-
if (
|
|
1642
|
-
return
|
|
1800
|
+
const data = tryReadCache(cachePath);
|
|
1801
|
+
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.");
|
|
1802
|
+
return data;
|
|
1643
1803
|
}
|
|
1644
1804
|
/**
|
|
1645
1805
|
* Return the raw precompute JSON for `contentHash`, spawning at most one
|
|
@@ -1650,26 +1810,30 @@ function computeWithLock(resolvedPath, tailwindNodePath, contentHash, cachePath,
|
|
|
1650
1810
|
const lockPath = (0, node_path.join)(CACHE_DIR, `${contentHash}.lock`);
|
|
1651
1811
|
const staleMs = timeout + 3e4;
|
|
1652
1812
|
try {
|
|
1653
|
-
(0, node_fs.mkdirSync)(CACHE_DIR, {
|
|
1813
|
+
(0, node_fs.mkdirSync)(CACHE_DIR, {
|
|
1814
|
+
recursive: true,
|
|
1815
|
+
mode: 448
|
|
1816
|
+
});
|
|
1654
1817
|
} catch {
|
|
1655
1818
|
return precomputeAndRead(resolvedPath, tailwindNodePath, cachePath, timeout);
|
|
1656
1819
|
}
|
|
1657
1820
|
const start = Date.now();
|
|
1658
1821
|
for (;;) {
|
|
1659
|
-
const
|
|
1660
|
-
if (
|
|
1822
|
+
const cached = tryReadCache(cachePath);
|
|
1823
|
+
if (cached) return cached;
|
|
1661
1824
|
let lockFd;
|
|
1662
1825
|
try {
|
|
1663
1826
|
lockFd = (0, node_fs.openSync)(lockPath, "wx");
|
|
1664
1827
|
} catch (cause) {
|
|
1665
1828
|
if (cause.code === "EEXIST") {
|
|
1666
|
-
if (lockAgeMs(lockPath) > staleMs || Date.now() - start > staleMs * 2)
|
|
1829
|
+
if (lockAgeMs(lockPath) > staleMs || Date.now() - start > staleMs * 2) reclaimStaleLock(lockPath);
|
|
1667
1830
|
else syncSleep(LOCK_POLL_MS);
|
|
1668
1831
|
continue;
|
|
1669
1832
|
}
|
|
1670
1833
|
return precomputeAndRead(resolvedPath, tailwindNodePath, cachePath, timeout);
|
|
1671
1834
|
}
|
|
1672
1835
|
try {
|
|
1836
|
+
tryUnlink(cachePath);
|
|
1673
1837
|
return precomputeAndRead(resolvedPath, tailwindNodePath, cachePath, timeout);
|
|
1674
1838
|
} finally {
|
|
1675
1839
|
(0, node_fs.closeSync)(lockFd);
|
|
@@ -1692,17 +1856,12 @@ function loadDesignSystemSync(cssPath, timeout) {
|
|
|
1692
1856
|
} catch (cause) {
|
|
1693
1857
|
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
1858
|
}
|
|
1695
|
-
const contentHash = computeContentHash(content);
|
|
1859
|
+
const contentHash = computeContentHash(hashableContent(resolvedPath, content));
|
|
1696
1860
|
const contentCachePath = getContentCachePath(contentHash);
|
|
1697
1861
|
const cached = tryReadCache(contentCachePath);
|
|
1698
1862
|
if (cached) return cached;
|
|
1699
1863
|
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
|
-
}
|
|
1864
|
+
return computeWithLock(resolvedPath, TAILWIND_NODE_PATH, contentHash, contentCachePath, timeout ?? 6e4);
|
|
1706
1865
|
}
|
|
1707
1866
|
//#endregion
|
|
1708
1867
|
//#region src/design-system/debug.ts
|
|
@@ -2176,8 +2335,14 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2176
2335
|
if (allowlist.has(className)) return true;
|
|
2177
2336
|
return ignorePrefixes.some((prefix) => className.startsWith(prefix));
|
|
2178
2337
|
}
|
|
2179
|
-
function
|
|
2180
|
-
|
|
2338
|
+
function strippedUtility(className) {
|
|
2339
|
+
const { utility, variant } = splitUtilityAndVariant(className);
|
|
2340
|
+
const { bare, position } = splitImportant(utility);
|
|
2341
|
+
return {
|
|
2342
|
+
variant,
|
|
2343
|
+
bare,
|
|
2344
|
+
position
|
|
2345
|
+
};
|
|
2181
2346
|
}
|
|
2182
2347
|
function check(locations) {
|
|
2183
2348
|
if (locations.length === 0) return;
|
|
@@ -2191,8 +2356,8 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2191
2356
|
if (shouldIgnore(cls)) continue;
|
|
2192
2357
|
const validity = cache.classValidity(cls);
|
|
2193
2358
|
if (validity === "valid") continue;
|
|
2194
|
-
const
|
|
2195
|
-
if (DEPRECATED_MAP[
|
|
2359
|
+
const { variant, bare, position } = strippedUtility(cls);
|
|
2360
|
+
if (DEPRECATED_MAP[bare]) continue;
|
|
2196
2361
|
if (validity === "missing-prefix") {
|
|
2197
2362
|
const fixed = `${cache.prefix}:${cls}`;
|
|
2198
2363
|
const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? fixed : c));
|
|
@@ -2217,7 +2382,8 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2217
2382
|
});
|
|
2218
2383
|
continue;
|
|
2219
2384
|
}
|
|
2220
|
-
const
|
|
2385
|
+
const suggestionBare = findBestSuggestion(bare, cache.validClasses);
|
|
2386
|
+
const suggestion = suggestionBare ? variant + reattachImportant(suggestionBare, position) : null;
|
|
2221
2387
|
if (suggestion) {
|
|
2222
2388
|
const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? suggestion : c));
|
|
2223
2389
|
context.report({
|
|
@@ -2377,7 +2543,7 @@ const noConflictingClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2377
2543
|
}],
|
|
2378
2544
|
defaultOptions: [{}],
|
|
2379
2545
|
messages: {
|
|
2380
|
-
conflict: "\"{{classA}}\" and \"{{classB}}\" affect {{properties}}.
|
|
2546
|
+
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
2547
|
...DS_UNAVAILABLE_MESSAGE
|
|
2382
2548
|
}
|
|
2383
2549
|
},
|
|
@@ -2410,9 +2576,11 @@ const noConflictingClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2410
2576
|
const propsA = propsMap.get(classA) ?? [];
|
|
2411
2577
|
for (let j = i + 1; j < variantClasses.length; j++) {
|
|
2412
2578
|
const classB = variantClasses[j];
|
|
2579
|
+
if (classA === classB) continue;
|
|
2413
2580
|
const propsB = propsMap.get(classB) ?? [];
|
|
2414
2581
|
if (shouldSkipPair(classA, classB, propsA, propsB)) continue;
|
|
2415
|
-
const
|
|
2582
|
+
const propsBSet = new Set(propsB);
|
|
2583
|
+
const overlap = propsA.filter((p) => propsBSet.has(p));
|
|
2416
2584
|
if (overlap.length > 0) {
|
|
2417
2585
|
const propList = overlap.length <= 3 ? `"${overlap.join("\", \"")}"` : `${overlap.length} CSS properties`;
|
|
2418
2586
|
context.report({
|
|
@@ -2421,8 +2589,7 @@ const noConflictingClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2421
2589
|
data: {
|
|
2422
2590
|
classA,
|
|
2423
2591
|
classB,
|
|
2424
|
-
properties: propList
|
|
2425
|
-
winner: classB
|
|
2592
|
+
properties: propList
|
|
2426
2593
|
}
|
|
2427
2594
|
});
|
|
2428
2595
|
}
|
|
@@ -2454,16 +2621,104 @@ const noConflictingClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2454
2621
|
*/
|
|
2455
2622
|
const BUFFER_SIZE = 4 * 1024 * 1024;
|
|
2456
2623
|
const HEADER_INTS = 4;
|
|
2624
|
+
const LENGTH_OFFSET = HEADER_INTS * 4;
|
|
2457
2625
|
const DATA_OFFSET = 20;
|
|
2458
2626
|
const INIT_TIMEOUT = 6e4;
|
|
2459
2627
|
const REQUEST_TIMEOUT = 3e4;
|
|
2628
|
+
/**
|
|
2629
|
+
* Build the worker script shared by `sort-service` and `canonicalize-service`.
|
|
2630
|
+
* Owns the entire SharedArrayBuffer protocol (offsets derived from the same
|
|
2631
|
+
* constants the host uses, so they can't drift), the design-system load with
|
|
2632
|
+
* error propagation (DS-M4: the real cause is written into the buffer so the
|
|
2633
|
+
* host can surface it, not a generic "failed to load"), the ready signal, and
|
|
2634
|
+
* the request loop. `handlerExpr` is a function expression `(ds, request) =>
|
|
2635
|
+
* result` — the only part that differs between services.
|
|
2636
|
+
*/
|
|
2637
|
+
function makeWorkerScript(handlerExpr) {
|
|
2638
|
+
return `
|
|
2639
|
+
const { workerData } = require('worker_threads');
|
|
2640
|
+
async function main() {
|
|
2641
|
+
const { sharedBuffer, cssPath } = workerData;
|
|
2642
|
+
const control = new Int32Array(sharedBuffer, 0, ${HEADER_INTS});
|
|
2643
|
+
const lengthView = new DataView(sharedBuffer, ${LENGTH_OFFSET}, 4);
|
|
2644
|
+
const dataArea = new Uint8Array(sharedBuffer, ${DATA_OFFSET});
|
|
2645
|
+
|
|
2646
|
+
// On load failure, write the real cause into the data region so the host can
|
|
2647
|
+
// report it instead of a bare "failed to load the design system".
|
|
2648
|
+
function signalLoadError(e) {
|
|
2649
|
+
try {
|
|
2650
|
+
const msg = Buffer.from(String((e && e.message) || e || 'unknown design-system load error'), 'utf-8');
|
|
2651
|
+
const n = Math.min(msg.length, dataArea.length);
|
|
2652
|
+
dataArea.set(msg.subarray(0, n), 0);
|
|
2653
|
+
lengthView.setUint32(0, n);
|
|
2654
|
+
} catch {}
|
|
2655
|
+
Atomics.store(control, 2, -1);
|
|
2656
|
+
Atomics.notify(control, 2);
|
|
2657
|
+
}
|
|
2658
|
+
|
|
2659
|
+
let ds;
|
|
2660
|
+
try {
|
|
2661
|
+
const { __unstable__loadDesignSystem } = require(workerData.tailwindNodePath);
|
|
2662
|
+
const { readFileSync } = require('fs');
|
|
2663
|
+
const { dirname } = require('path');
|
|
2664
|
+
const css = readFileSync(cssPath, 'utf-8');
|
|
2665
|
+
ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
|
|
2666
|
+
} catch (e) {
|
|
2667
|
+
signalLoadError(e);
|
|
2668
|
+
return;
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2671
|
+
Atomics.store(control, 2, 1);
|
|
2672
|
+
Atomics.notify(control, 2);
|
|
2673
|
+
|
|
2674
|
+
const handler = ${handlerExpr};
|
|
2675
|
+
|
|
2676
|
+
while (true) {
|
|
2677
|
+
Atomics.wait(control, 0, 0);
|
|
2678
|
+
const len = lengthView.getUint32(0);
|
|
2679
|
+
const requestStr = Buffer.from(dataArea.slice(0, len)).toString('utf-8');
|
|
2680
|
+
Atomics.store(control, 0, 0);
|
|
2681
|
+
|
|
2682
|
+
let response;
|
|
2683
|
+
try {
|
|
2684
|
+
const request = JSON.parse(requestStr);
|
|
2685
|
+
const result = handler(ds, request);
|
|
2686
|
+
response = Buffer.from(JSON.stringify(result), 'utf-8');
|
|
2687
|
+
} catch {
|
|
2688
|
+
response = Buffer.from('null', 'utf-8');
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2691
|
+
// DS-M6: if the response doesn't fit the shared buffer, reply with a
|
|
2692
|
+
// sentinel the host reads as a rejected request, instead of letting
|
|
2693
|
+
// dataArea.set throw and kill the worker (which would hang the caller
|
|
2694
|
+
// until the request timeout and then report a misleading timeout).
|
|
2695
|
+
if (response.length > dataArea.length) {
|
|
2696
|
+
response = Buffer.from('null', 'utf-8');
|
|
2697
|
+
}
|
|
2698
|
+
|
|
2699
|
+
dataArea.set(response, 0);
|
|
2700
|
+
lengthView.setUint32(0, response.length);
|
|
2701
|
+
Atomics.store(control, 1, 1);
|
|
2702
|
+
Atomics.notify(control, 1);
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
|
+
main().catch(() => {});
|
|
2706
|
+
`;
|
|
2707
|
+
}
|
|
2460
2708
|
var DesignSystemWorker = class {
|
|
2461
2709
|
opts;
|
|
2462
2710
|
ready = null;
|
|
2463
2711
|
lastError = null;
|
|
2712
|
+
lastErrorCssPath = null;
|
|
2464
2713
|
constructor(opts) {
|
|
2465
2714
|
this.opts = opts;
|
|
2466
2715
|
}
|
|
2716
|
+
/** Record an error as sticky for `cssPath` and return it for `throw`. */
|
|
2717
|
+
remember(cssPath, err) {
|
|
2718
|
+
this.lastError = err;
|
|
2719
|
+
this.lastErrorCssPath = cssPath;
|
|
2720
|
+
return err;
|
|
2721
|
+
}
|
|
2467
2722
|
/**
|
|
2468
2723
|
* Ensure the worker is running and pointed at `cssPath`. Returns the
|
|
2469
2724
|
* ready state. Throws `SortServiceError` on any failure (init timeout,
|
|
@@ -2471,14 +2726,12 @@ var DesignSystemWorker = class {
|
|
|
2471
2726
|
* cssPath rethrow without retrying.
|
|
2472
2727
|
*/
|
|
2473
2728
|
ensure(cssPath) {
|
|
2474
|
-
if (this.lastError && this.
|
|
2729
|
+
if (this.lastError && this.lastErrorCssPath === cssPath) throw this.lastError;
|
|
2475
2730
|
if (this.ready && this.ready.cssPath === cssPath) return this.ready;
|
|
2476
2731
|
if (this.ready) this.cleanup();
|
|
2477
2732
|
this.lastError = null;
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
throw this.lastError;
|
|
2481
|
-
}
|
|
2733
|
+
this.lastErrorCssPath = null;
|
|
2734
|
+
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
2735
|
const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
|
|
2483
2736
|
const controlArray = new Int32Array(sharedBuffer, 0, HEADER_INTS);
|
|
2484
2737
|
const lengthView = new DataView(sharedBuffer, HEADER_INTS * 4, 4);
|
|
@@ -2494,22 +2747,22 @@ var DesignSystemWorker = class {
|
|
|
2494
2747
|
}
|
|
2495
2748
|
});
|
|
2496
2749
|
} catch (cause) {
|
|
2497
|
-
this.
|
|
2498
|
-
throw this.lastError;
|
|
2750
|
+
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
2751
|
}
|
|
2500
2752
|
worker.unref();
|
|
2501
2753
|
worker.on("error", (err) => {
|
|
2502
2754
|
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 });
|
|
2755
|
+
this.lastErrorCssPath = cssPath;
|
|
2503
2756
|
});
|
|
2504
2757
|
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
2758
|
this.terminateWorker(worker);
|
|
2507
|
-
throw this.
|
|
2759
|
+
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
2760
|
}
|
|
2509
2761
|
if (controlArray[2] === -1) {
|
|
2510
|
-
|
|
2762
|
+
const len = lengthView.getUint32(0);
|
|
2763
|
+
const detail = len > 0 ? Buffer.from(dataArea.slice(0, len)).toString("utf-8") : "";
|
|
2511
2764
|
this.terminateWorker(worker);
|
|
2512
|
-
throw this.
|
|
2765
|
+
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
2766
|
}
|
|
2514
2767
|
this.ready = {
|
|
2515
2768
|
worker,
|
|
@@ -2533,9 +2786,8 @@ var DesignSystemWorker = class {
|
|
|
2533
2786
|
Atomics.store(state.controlArray, 0, 1);
|
|
2534
2787
|
Atomics.notify(state.controlArray, 0);
|
|
2535
2788
|
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
2789
|
this.cleanup();
|
|
2538
|
-
throw this.
|
|
2790
|
+
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
2791
|
}
|
|
2540
2792
|
const responseLen = state.lengthView.getUint32(0);
|
|
2541
2793
|
const responseStr = Buffer.from(state.dataArea.slice(0, responseLen)).toString("utf-8");
|
|
@@ -2544,20 +2796,19 @@ var DesignSystemWorker = class {
|
|
|
2544
2796
|
try {
|
|
2545
2797
|
parsed = JSON.parse(responseStr);
|
|
2546
2798
|
} 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
2799
|
this.cleanup();
|
|
2549
|
-
throw this.
|
|
2800
|
+
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
2801
|
}
|
|
2551
2802
|
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
2803
|
this.cleanup();
|
|
2554
|
-
throw this.
|
|
2804
|
+
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
2805
|
}
|
|
2556
2806
|
return parsed;
|
|
2557
2807
|
}
|
|
2558
2808
|
reset() {
|
|
2559
2809
|
this.cleanup();
|
|
2560
2810
|
this.lastError = null;
|
|
2811
|
+
this.lastErrorCssPath = null;
|
|
2561
2812
|
}
|
|
2562
2813
|
cleanup() {
|
|
2563
2814
|
if (this.ready) {
|
|
@@ -2589,60 +2840,14 @@ var DesignSystemWorker = class {
|
|
|
2589
2840
|
* subsequent lookup is O(1).
|
|
2590
2841
|
*/
|
|
2591
2842
|
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
|
-
`,
|
|
2843
|
+
workerScript: makeWorkerScript(`(ds, request) => {
|
|
2844
|
+
const { classes, rem } = request;
|
|
2845
|
+
const options = rem ? { rem } : undefined;
|
|
2846
|
+
return classes.map((cls) => {
|
|
2847
|
+
const r = ds.canonicalizeCandidates([cls], options);
|
|
2848
|
+
return r[0] ?? cls;
|
|
2849
|
+
});
|
|
2850
|
+
}`),
|
|
2646
2851
|
serviceName: "canonicalize"
|
|
2647
2852
|
});
|
|
2648
2853
|
/**
|
|
@@ -2687,7 +2892,7 @@ function canonicalizeClassesSync(cssPath, classes, rem) {
|
|
|
2687
2892
|
for (let k = 0; k < uniqueMissing.length; k++) freshByClass.set(uniqueMissing[k], fresh[k]);
|
|
2688
2893
|
for (let j = 0; j < missing.length; j++) {
|
|
2689
2894
|
const cls = missing[j];
|
|
2690
|
-
const value = freshByClass.get(cls) ?? cls;
|
|
2895
|
+
const value = roundRemValue(freshByClass.get(cls) ?? cls);
|
|
2691
2896
|
canonCache.set(cachePrefix + cls, value);
|
|
2692
2897
|
out[missingIdx[j]] = value;
|
|
2693
2898
|
}
|
|
@@ -2779,62 +2984,17 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
|
2779
2984
|
* Atomics.wait, fail-loud, sticky lastError) lives in `./ds-worker.ts`.
|
|
2780
2985
|
*/
|
|
2781
2986
|
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
|
-
`,
|
|
2987
|
+
workerScript: makeWorkerScript(`(ds, classes) => {
|
|
2988
|
+
const ordered = ds.getClassOrder(classes);
|
|
2989
|
+
return [...ordered]
|
|
2990
|
+
.sort((a, b) => {
|
|
2991
|
+
if (a[1] === null && b[1] === null) return 0;
|
|
2992
|
+
if (a[1] === null) return -1;
|
|
2993
|
+
if (b[1] === null) return 1;
|
|
2994
|
+
return a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0;
|
|
2995
|
+
})
|
|
2996
|
+
.map(([name]) => name);
|
|
2997
|
+
}`),
|
|
2838
2998
|
serviceName: "sort"
|
|
2839
2999
|
});
|
|
2840
3000
|
/**
|
|
@@ -2886,13 +3046,9 @@ const enforceSortOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
2886
3046
|
}
|
|
2887
3047
|
function sortStrict(classes) {
|
|
2888
3048
|
const groups = /* @__PURE__ */ new Map();
|
|
2889
|
-
const groupOrder = [];
|
|
2890
3049
|
for (const cls of classes) {
|
|
2891
3050
|
const { variant } = splitUtilityAndVariant(cls);
|
|
2892
|
-
if (!groups.has(variant))
|
|
2893
|
-
groups.set(variant, []);
|
|
2894
|
-
groupOrder.push(variant);
|
|
2895
|
-
}
|
|
3051
|
+
if (!groups.has(variant)) groups.set(variant, []);
|
|
2896
3052
|
groups.get(variant).push(cls);
|
|
2897
3053
|
}
|
|
2898
3054
|
for (const [, groupClasses] of groups) {
|
|
@@ -3074,26 +3230,6 @@ const enforceShorthand = (0, _oxlint_plugins.defineRule)({
|
|
|
3074
3230
|
}
|
|
3075
3231
|
});
|
|
3076
3232
|
//#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
3233
|
//#region src/rules/enforce-logical.ts
|
|
3098
3234
|
const LOGICAL_PHYSICAL_SCHEMA = {
|
|
3099
3235
|
type: "object",
|
|
@@ -3234,9 +3370,14 @@ function createDirectionalMapper(context, opts) {
|
|
|
3234
3370
|
if (matchesAny(cls, allowlist)) return null;
|
|
3235
3371
|
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
3236
3372
|
const { bare: bareUtility, position } = splitImportant(utility);
|
|
3373
|
+
const negative = bareUtility.startsWith("-");
|
|
3374
|
+
const core = negative ? bareUtility.slice(1) : bareUtility;
|
|
3237
3375
|
for (const { from, to, axis } of opts.mappings) {
|
|
3238
3376
|
if (direction !== "both" && direction !== axis) continue;
|
|
3239
|
-
if (
|
|
3377
|
+
if (core === from || core.startsWith(`${from}-`)) {
|
|
3378
|
+
const suffix = core.slice(from.length);
|
|
3379
|
+
return `${variant}${reattachImportant(`${negative ? "-" : ""}${to}${suffix}`, position)}`;
|
|
3380
|
+
}
|
|
3240
3381
|
}
|
|
3241
3382
|
return null;
|
|
3242
3383
|
}
|
|
@@ -3379,10 +3520,16 @@ const noRestrictedClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
3379
3520
|
createOnce(context) {
|
|
3380
3521
|
const getConfig = createLazyOptions(context, (o) => ({
|
|
3381
3522
|
restrictedClasses: new Set(o?.classes ?? []),
|
|
3382
|
-
patterns: (o?.patterns ?? []).
|
|
3383
|
-
|
|
3384
|
-
|
|
3385
|
-
|
|
3523
|
+
patterns: (o?.patterns ?? []).flatMap((p) => {
|
|
3524
|
+
try {
|
|
3525
|
+
return [{
|
|
3526
|
+
regex: new RegExp(p.pattern),
|
|
3527
|
+
message: p.message
|
|
3528
|
+
}];
|
|
3529
|
+
} catch {
|
|
3530
|
+
return [];
|
|
3531
|
+
}
|
|
3532
|
+
})
|
|
3386
3533
|
}));
|
|
3387
3534
|
function check(locations) {
|
|
3388
3535
|
const { restrictedClasses, patterns } = getConfig();
|
|
@@ -3511,6 +3658,7 @@ const enforceConsistentImportantPosition = (0, _oxlint_plugins.defineRule)({
|
|
|
3511
3658
|
});
|
|
3512
3659
|
//#endregion
|
|
3513
3660
|
//#region src/rules/enforce-negative-arbitrary-values.ts
|
|
3661
|
+
const SIMPLE_DIMENSION = /^\d*\.?\d+[a-z%]*$/;
|
|
3514
3662
|
function fixClass(cls) {
|
|
3515
3663
|
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
3516
3664
|
const hasImportantPrefix = utility.startsWith("!");
|
|
@@ -3523,6 +3671,7 @@ function fixClass(cls) {
|
|
|
3523
3671
|
if (bracketClose === -1 || bracketClose < bracketOpen) return null;
|
|
3524
3672
|
const innerValue = bare.slice(bracketOpen + 1, bracketClose);
|
|
3525
3673
|
if (innerValue.startsWith("-")) return null;
|
|
3674
|
+
if (!SIMPLE_DIMENSION.test(innerValue)) return null;
|
|
3526
3675
|
const baseUtility = bare.slice(1, bracketOpen);
|
|
3527
3676
|
return `${variant}${hasImportantPrefix ? "!" : ""}${baseUtility}[-${innerValue}]${hasImportantSuffix ? "!" : ""}`;
|
|
3528
3677
|
}
|
|
@@ -3657,13 +3806,48 @@ const KNOWN_PREFIXES = [
|
|
|
3657
3806
|
"via",
|
|
3658
3807
|
"to"
|
|
3659
3808
|
];
|
|
3809
|
+
const PROPERTY_GROUP_BY_UTILITY = {};
|
|
3810
|
+
for (const u of [
|
|
3811
|
+
"block",
|
|
3812
|
+
"inline-block",
|
|
3813
|
+
"inline",
|
|
3814
|
+
"flex",
|
|
3815
|
+
"inline-flex",
|
|
3816
|
+
"grid",
|
|
3817
|
+
"inline-grid",
|
|
3818
|
+
"flow-root",
|
|
3819
|
+
"contents",
|
|
3820
|
+
"table",
|
|
3821
|
+
"inline-table",
|
|
3822
|
+
"table-caption",
|
|
3823
|
+
"table-cell",
|
|
3824
|
+
"table-row",
|
|
3825
|
+
"table-row-group",
|
|
3826
|
+
"table-header-group",
|
|
3827
|
+
"table-footer-group",
|
|
3828
|
+
"table-column",
|
|
3829
|
+
"table-column-group",
|
|
3830
|
+
"list-item",
|
|
3831
|
+
"hidden"
|
|
3832
|
+
]) PROPERTY_GROUP_BY_UTILITY[u] = "display";
|
|
3833
|
+
for (const u of [
|
|
3834
|
+
"static",
|
|
3835
|
+
"fixed",
|
|
3836
|
+
"absolute",
|
|
3837
|
+
"relative",
|
|
3838
|
+
"sticky"
|
|
3839
|
+
]) PROPERTY_GROUP_BY_UTILITY[u] = "position";
|
|
3660
3840
|
/**
|
|
3661
|
-
*
|
|
3662
|
-
*
|
|
3841
|
+
* Maps a utility to a key identifying the CSS property it sets, so a base and a
|
|
3842
|
+
* variant class for the same property group together. Exact-match equivalence
|
|
3843
|
+
* groups (display, position) win; otherwise fall back to the prefix heuristic
|
|
3844
|
+
* (e.g. "bg" from "bg-gray-900", "text" from "text-white").
|
|
3663
3845
|
*/
|
|
3664
3846
|
function getUtilityPrefix(utility) {
|
|
3665
3847
|
let u = splitImportant(utility).bare;
|
|
3666
3848
|
if (u.startsWith("-")) u = u.slice(1);
|
|
3849
|
+
const group = PROPERTY_GROUP_BY_UTILITY[u];
|
|
3850
|
+
if (group) return group;
|
|
3667
3851
|
for (const prefix of KNOWN_PREFIXES) if (u === prefix || u.startsWith(`${prefix}-`)) return prefix;
|
|
3668
3852
|
const dashIdx = u.indexOf("-");
|
|
3669
3853
|
return dashIdx >= 0 ? u.slice(0, dashIdx) : u;
|
|
@@ -3771,13 +3955,10 @@ const noHardcodedColors = (0, _oxlint_plugins.defineRule)({
|
|
|
3771
3955
|
docs: { description: "Disallow hardcoded color values in Tailwind CSS classes" },
|
|
3772
3956
|
schema: [{
|
|
3773
3957
|
type: "object",
|
|
3774
|
-
properties: {
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
items: { type: "string" }
|
|
3779
|
-
}
|
|
3780
|
-
},
|
|
3958
|
+
properties: { allow: {
|
|
3959
|
+
type: "array",
|
|
3960
|
+
items: { type: "string" }
|
|
3961
|
+
} },
|
|
3781
3962
|
additionalProperties: false
|
|
3782
3963
|
}],
|
|
3783
3964
|
defaultOptions: [{ allow: [] }],
|
|
@@ -3809,24 +3990,6 @@ const noHardcodedColors = (0, _oxlint_plugins.defineRule)({
|
|
|
3809
3990
|
});
|
|
3810
3991
|
//#endregion
|
|
3811
3992
|
//#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
3993
|
const noContradictingVariants = (0, _oxlint_plugins.defineRule)({
|
|
3831
3994
|
meta: {
|
|
3832
3995
|
type: "suggestion",
|
|
@@ -3861,18 +4024,6 @@ const noContradictingVariants = (0, _oxlint_plugins.defineRule)({
|
|
|
3861
4024
|
});
|
|
3862
4025
|
//#endregion
|
|
3863
4026
|
//#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
4027
|
const DEFAULT_VARIANT_ORDER = [
|
|
3877
4028
|
"*",
|
|
3878
4029
|
"**",
|
|
@@ -3971,17 +4122,12 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
3971
4122
|
},
|
|
3972
4123
|
createOnce(context) {
|
|
3973
4124
|
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) {
|
|
4125
|
+
const getOptions = createLazyOptions(context, (o) => ({ order: o?.order }));
|
|
4126
|
+
function buildPriority(order, dsCache) {
|
|
4127
|
+
if (order) {
|
|
3982
4128
|
const map = /* @__PURE__ */ new Map();
|
|
3983
|
-
for (let i = 0; i <
|
|
3984
|
-
const fallback =
|
|
4129
|
+
for (let i = 0; i < order.length; i++) map.set(order[i], i);
|
|
4130
|
+
const fallback = order.length;
|
|
3985
4131
|
return (v) => map.get(v) ?? fallback;
|
|
3986
4132
|
}
|
|
3987
4133
|
if (dsCache && dsCache.hasVariantOrder()) {
|
|
@@ -3992,17 +4138,36 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
3992
4138
|
for (let i = 0; i < DEFAULT_VARIANT_ORDER.length; i++) map.set(DEFAULT_VARIANT_ORDER[i], i);
|
|
3993
4139
|
const fallback = DEFAULT_VARIANT_ORDER.length;
|
|
3994
4140
|
return (v) => map.get(v) ?? fallback;
|
|
3995
|
-
}
|
|
3996
|
-
const
|
|
4141
|
+
}
|
|
4142
|
+
const priorityByEntry = /* @__PURE__ */ new Map();
|
|
4143
|
+
const prefixByEntry = /* @__PURE__ */ new Map();
|
|
4144
|
+
function resolveForFile() {
|
|
4145
|
+
let dsCache = null;
|
|
4146
|
+
let entryKey = "";
|
|
3997
4147
|
try {
|
|
3998
|
-
|
|
4148
|
+
const ds = getDS();
|
|
4149
|
+
dsCache = ds.cache;
|
|
4150
|
+
entryKey = ds.entryPoint;
|
|
3999
4151
|
} catch (err) {
|
|
4000
4152
|
if (!isFatalError(err)) throw err;
|
|
4001
|
-
return "";
|
|
4002
4153
|
}
|
|
4003
|
-
|
|
4154
|
+
let priorityOf = priorityByEntry.get(entryKey);
|
|
4155
|
+
if (!priorityOf) {
|
|
4156
|
+
priorityOf = buildPriority(getOptions().order, dsCache);
|
|
4157
|
+
priorityByEntry.set(entryKey, priorityOf);
|
|
4158
|
+
}
|
|
4159
|
+
let prefix = prefixByEntry.get(entryKey);
|
|
4160
|
+
if (prefix === void 0) {
|
|
4161
|
+
prefix = dsCache?.prefix ?? "";
|
|
4162
|
+
prefixByEntry.set(entryKey, prefix);
|
|
4163
|
+
}
|
|
4164
|
+
return {
|
|
4165
|
+
priorityOf,
|
|
4166
|
+
prefix
|
|
4167
|
+
};
|
|
4168
|
+
}
|
|
4004
4169
|
function reorderClass(cls) {
|
|
4005
|
-
const prefix =
|
|
4170
|
+
const { priorityOf, prefix } = resolveForFile();
|
|
4006
4171
|
let pfx = "";
|
|
4007
4172
|
let body = cls;
|
|
4008
4173
|
if (prefix && cls.startsWith(prefix + ":")) {
|
|
@@ -4011,13 +4176,25 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
4011
4176
|
}
|
|
4012
4177
|
const variants = extractVariants(body);
|
|
4013
4178
|
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
4179
|
const pseudo = [];
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4180
|
+
const rest = [];
|
|
4181
|
+
for (const v of variants) if (isPseudoElementVariant(v)) pseudo.push(v);
|
|
4182
|
+
else rest.push(v);
|
|
4183
|
+
const reorderedRest = [];
|
|
4184
|
+
let segment = [];
|
|
4185
|
+
const flushSegment = () => {
|
|
4186
|
+
if (segment.length === 0) return;
|
|
4187
|
+
segment.sort((a, b) => priorityOf(a) - priorityOf(b));
|
|
4188
|
+
reorderedRest.push(...segment);
|
|
4189
|
+
segment = [];
|
|
4190
|
+
};
|
|
4191
|
+
for (const v of rest) if (isSelectorBarrier(v)) {
|
|
4192
|
+
flushSegment();
|
|
4193
|
+
reorderedRest.push(v);
|
|
4194
|
+
} else segment.push(v);
|
|
4195
|
+
flushSegment();
|
|
4196
|
+
pseudo.sort((a, b) => priorityOf(a) - priorityOf(b));
|
|
4197
|
+
const final = [...reorderedRest, ...pseudo];
|
|
4021
4198
|
if (variants.every((v, i) => v === final[i])) return null;
|
|
4022
4199
|
const utility = extractUtility(body);
|
|
4023
4200
|
return pfx + final.join(":") + ":" + utility;
|