oxlint-tailwindcss 1.1.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 +550 -273
- package/dist/index.d.cts +1 -2
- package/dist/index.d.mts +1 -2
- package/dist/index.mjs +552 -277
- 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.mjs
CHANGED
|
@@ -2,12 +2,32 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import { definePlugin, defineRule } from "@oxlint/plugins";
|
|
3
3
|
import { Worker, threadId } from "node:worker_threads";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
|
-
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, statSync, unlinkSync } from "node:fs";
|
|
5
|
+
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync } from "node:fs";
|
|
6
6
|
import { dirname, join, relative, resolve } from "node:path";
|
|
7
|
-
import { tmpdir } from "node:os";
|
|
7
|
+
import { tmpdir, userInfo } from "node:os";
|
|
8
8
|
//#region \0rolldown/runtime.js
|
|
9
9
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
10
10
|
//#endregion
|
|
11
|
+
//#region src/utils/allowlist.ts
|
|
12
|
+
/**
|
|
13
|
+
* Shared regex-allowlist helpers used by rules that accept an `allowlist`
|
|
14
|
+
* option of regex source strings (currently enforce-logical / enforce-physical).
|
|
15
|
+
*
|
|
16
|
+
* Invalid regex sources are skipped rather than thrown so a typo in one
|
|
17
|
+
* pattern doesn't blow up the entire lint run.
|
|
18
|
+
*/
|
|
19
|
+
function compileRegexList(patterns) {
|
|
20
|
+
if (!patterns || patterns.length === 0) return [];
|
|
21
|
+
const compiled = [];
|
|
22
|
+
for (const p of patterns) try {
|
|
23
|
+
compiled.push(new RegExp(p));
|
|
24
|
+
} catch {}
|
|
25
|
+
return compiled;
|
|
26
|
+
}
|
|
27
|
+
function matchesAny(value, list) {
|
|
28
|
+
return list.some((re) => re.test(value));
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
11
31
|
//#region src/utils/extractors.ts
|
|
12
32
|
/**
|
|
13
33
|
* Preserves leading/trailing spaces in fixed class strings for template literals.
|
|
@@ -85,7 +105,7 @@ function getExtractorConfig(context) {
|
|
|
85
105
|
attributes: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.attributes, tw.attributes, exclude?.attributes),
|
|
86
106
|
callees: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.callees, tw.callees, exclude?.callees),
|
|
87
107
|
tags: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.tags, tw.tags, exclude?.tags),
|
|
88
|
-
variablePatterns: [...filteredPatterns, ...(tw.variablePatterns
|
|
108
|
+
variablePatterns: [...filteredPatterns, ...compileRegexList(tw.variablePatterns)]
|
|
89
109
|
};
|
|
90
110
|
configCache.set(context, resolved);
|
|
91
111
|
return resolved;
|
|
@@ -356,6 +376,9 @@ function getCalleeName(node) {
|
|
|
356
376
|
}
|
|
357
377
|
//#endregion
|
|
358
378
|
//#region src/utils/class-splitter.ts
|
|
379
|
+
function isWhitespace(char) {
|
|
380
|
+
return char === " " || char === " " || char === "\n" || char === "\r" || char === "\f" || char === "\v";
|
|
381
|
+
}
|
|
359
382
|
/**
|
|
360
383
|
* Splits a Tailwind class string respecting:
|
|
361
384
|
* - Nested brackets: bg-[url('...')], h-[calc(100%+2rem)]
|
|
@@ -378,9 +401,9 @@ function splitClasses(classString) {
|
|
|
378
401
|
}
|
|
379
402
|
if (!inSingleQuote && !inDoubleQuote) {
|
|
380
403
|
if (char === "[") bracketDepth++;
|
|
381
|
-
if (char === "]") bracketDepth
|
|
404
|
+
if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
|
|
382
405
|
}
|
|
383
|
-
if (
|
|
406
|
+
if (isWhitespace(char) && bracketDepth === 0) {
|
|
384
407
|
if (current.length > 0) {
|
|
385
408
|
classes.push(current);
|
|
386
409
|
current = "";
|
|
@@ -407,9 +430,9 @@ function splitClassesWithSeparators(classString) {
|
|
|
407
430
|
}
|
|
408
431
|
if (!inSingleQuote && !inDoubleQuote) {
|
|
409
432
|
if (char === "[") bracketDepth++;
|
|
410
|
-
if (char === "]") bracketDepth
|
|
433
|
+
if (char === "]") bracketDepth = Math.max(0, bracketDepth - 1);
|
|
411
434
|
}
|
|
412
|
-
if (
|
|
435
|
+
if (isWhitespace(char) && bracketDepth === 0) {
|
|
413
436
|
if (current.length > 0) {
|
|
414
437
|
classes.push(current);
|
|
415
438
|
separators.push(currentSep);
|
|
@@ -695,6 +718,52 @@ function reattachImportant(bare, position) {
|
|
|
695
718
|
if (position === "suffix") return `${bare}!`;
|
|
696
719
|
return bare;
|
|
697
720
|
}
|
|
721
|
+
/**
|
|
722
|
+
* Pseudo-element variants. They select a generated box (`::before`, `::marker`,
|
|
723
|
+
* …) rather than the element itself, so they must sit innermost in the variant
|
|
724
|
+
* chain (closest to the utility). Canonical home shared by
|
|
725
|
+
* `consistent-variant-order` (partitions them last) and
|
|
726
|
+
* `no-contradicting-variants` (they can't contradict a base class).
|
|
727
|
+
*/
|
|
728
|
+
const PSEUDO_ELEMENT_VARIANTS = new Set([
|
|
729
|
+
"before",
|
|
730
|
+
"after",
|
|
731
|
+
"file",
|
|
732
|
+
"placeholder",
|
|
733
|
+
"selection",
|
|
734
|
+
"marker",
|
|
735
|
+
"backdrop",
|
|
736
|
+
"first-line",
|
|
737
|
+
"first-letter",
|
|
738
|
+
"details-content"
|
|
739
|
+
]);
|
|
740
|
+
function isPseudoElementVariant(variant) {
|
|
741
|
+
return PSEUDO_ELEMENT_VARIANTS.has(variant);
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Selector barriers: variants that re-point the selector at a *different*
|
|
745
|
+
* element than the ones around them — child (`*`), descendant (`**`),
|
|
746
|
+
* arbitrary selectors (`[&>svg]`) and compound child selectors (`*:data-[…]`).
|
|
747
|
+
*
|
|
748
|
+
* Unlike pseudo-elements, these are NOT free to move to the end of the chain:
|
|
749
|
+
* `hover:*:flex` (`&:hover > *`) and `*:hover:flex` (`& > *:hover`) target
|
|
750
|
+
* different elements. `consistent-variant-order` treats them as hard
|
|
751
|
+
* reordering barriers — variants never cross them.
|
|
752
|
+
*/
|
|
753
|
+
function isSelectorBarrier(variant) {
|
|
754
|
+
if (variant === "*" || variant === "**") return true;
|
|
755
|
+
if (variant.startsWith("[") && variant.endsWith("]")) return true;
|
|
756
|
+
if (variant.startsWith("*:")) return true;
|
|
757
|
+
return false;
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* Whether a variant changes the selector target (pseudo-element OR selector
|
|
761
|
+
* barrier). Such variants don't impose a condition on the same element, so they
|
|
762
|
+
* can't make a variant class contradict/duplicate a base class.
|
|
763
|
+
*/
|
|
764
|
+
function changesTarget(variant) {
|
|
765
|
+
return isPseudoElementVariant(variant) || isSelectorBarrier(variant);
|
|
766
|
+
}
|
|
698
767
|
//#endregion
|
|
699
768
|
//#region src/utils/floating-point.ts
|
|
700
769
|
/**
|
|
@@ -722,6 +791,8 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
722
791
|
_validClasses = [];
|
|
723
792
|
_knownPrefixes = null;
|
|
724
793
|
_maxOrder = 0n;
|
|
794
|
+
_prefix = "";
|
|
795
|
+
componentSet = /* @__PURE__ */ new Set();
|
|
725
796
|
static fromPrecomputed(data) {
|
|
726
797
|
const cache = new DesignSystemCache();
|
|
727
798
|
cache._validClasses = data.validClasses;
|
|
@@ -734,7 +805,11 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
734
805
|
}
|
|
735
806
|
for (const [cls, props] of Object.entries(data.cssProps)) cache.cssPropsMap.set(cls, props);
|
|
736
807
|
if (data.variantOrder) for (const [name, index] of Object.entries(data.variantOrder)) cache.variantOrderMap.set(name, index);
|
|
737
|
-
if (data.componentClasses) for (const cls of data.componentClasses)
|
|
808
|
+
if (data.componentClasses) for (const cls of data.componentClasses) {
|
|
809
|
+
cache.validitySet.add(cls);
|
|
810
|
+
cache.componentSet.add(cls);
|
|
811
|
+
}
|
|
812
|
+
cache._prefix = data.prefix ?? "";
|
|
738
813
|
if (data.arbitraryEquivalents) for (const [arb, named] of Object.entries(data.arbitraryEquivalents)) cache.arbitraryEquivMap.set(arb, named);
|
|
739
814
|
return cache;
|
|
740
815
|
}
|
|
@@ -744,6 +819,10 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
744
819
|
get maxOrder() {
|
|
745
820
|
return this._maxOrder;
|
|
746
821
|
}
|
|
822
|
+
/** Tailwind v4 project prefix (e.g. 'tw'); '' when none is configured. */
|
|
823
|
+
get prefix() {
|
|
824
|
+
return this._prefix;
|
|
825
|
+
}
|
|
747
826
|
canonicalize(className) {
|
|
748
827
|
const cached = this.canonicalMap.get(className);
|
|
749
828
|
if (cached !== void 0) return cached;
|
|
@@ -842,7 +921,32 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
842
921
|
if (bare.includes("(") && bare.includes(")")) return true;
|
|
843
922
|
return false;
|
|
844
923
|
}
|
|
924
|
+
/**
|
|
925
|
+
* Strict validity for `no-unknown-classes`, prefix-aware.
|
|
926
|
+
*
|
|
927
|
+
* - `'valid'` — usable as written.
|
|
928
|
+
* - `'missing-prefix'`— a real Tailwind utility written WITHOUT the required
|
|
929
|
+
* project prefix (`flex` under `prefix(tw)`); generates no CSS.
|
|
930
|
+
* - `'unknown'` — not a recognized class.
|
|
931
|
+
*
|
|
932
|
+
* When no prefix is configured this collapses to the tolerant `isValid`
|
|
933
|
+
* behavior. `isValid` itself stays tolerant (other rules call it with
|
|
934
|
+
* prefix-free candidates), so the strict check lives here.
|
|
935
|
+
*/
|
|
936
|
+
classValidity(className) {
|
|
937
|
+
if (!this._prefix) return this.isValid(className) ? "valid" : "unknown";
|
|
938
|
+
const tag = this._prefix + ":";
|
|
939
|
+
const hadPrefix = className.startsWith(tag);
|
|
940
|
+
const body = hadPrefix ? className.slice(tag.length) : className;
|
|
941
|
+
let baseUtility = splitImportant(extractUtility(body)).bare;
|
|
942
|
+
const slashIdx = baseUtility.lastIndexOf("/");
|
|
943
|
+
if (slashIdx > 0) baseUtility = baseUtility.slice(0, slashIdx);
|
|
944
|
+
if (this.componentSet.has(baseUtility)) return "valid";
|
|
945
|
+
if (this.isValid(body)) return hadPrefix ? "valid" : "missing-prefix";
|
|
946
|
+
return "unknown";
|
|
947
|
+
}
|
|
845
948
|
getOrder(className) {
|
|
949
|
+
if (this._prefix && className.startsWith(this._prefix + ":")) className = className.slice(this._prefix.length + 1);
|
|
846
950
|
const cached = this.orderMap.get(className);
|
|
847
951
|
if (cached !== void 0) return cached;
|
|
848
952
|
const utility = extractUtility(className);
|
|
@@ -1086,6 +1190,12 @@ function signalError(e) {
|
|
|
1086
1190
|
Atomics.store(control, 2, -1);
|
|
1087
1191
|
Atomics.notify(control, 2);
|
|
1088
1192
|
}
|
|
1193
|
+
// Everything below — including the top-level require()s — runs inside this try
|
|
1194
|
+
// so any SYNCHRONOUS module-scope failure (a broken @tailwindcss/node install,
|
|
1195
|
+
// missing fs/path) is routed through signalError. Without it the worker would
|
|
1196
|
+
// die unsignaled and the main thread would block until the full timeout, then
|
|
1197
|
+
// report a misleading "timed out" instead of the real cause.
|
|
1198
|
+
try {
|
|
1089
1199
|
// Resolve @tailwindcss/node via an absolute path passed in by the parent —
|
|
1090
1200
|
// bare-specifier lookup from the worker's cwd fails under pnpm strict
|
|
1091
1201
|
// workspaces (the module lives under node_modules/.pnpm/... which is not on the
|
|
@@ -1173,6 +1283,16 @@ async function main() {
|
|
|
1173
1283
|
const base = dirname(cssPath);
|
|
1174
1284
|
const ds = await __unstable__loadDesignSystem(css, { base });
|
|
1175
1285
|
|
|
1286
|
+
// Tailwind v4 project prefix (\`@import "tailwindcss" prefix(tw)\`). getClassList()
|
|
1287
|
+
// returns names WITHOUT the prefix, but candidatesToCss/getClassOrder/
|
|
1288
|
+
// canonicalizeCandidates only resolve the PREFIXED form (\`tw:flex\`). We apply
|
|
1289
|
+
// the prefix only when calling the DS and strip it back off before storing, so
|
|
1290
|
+
// every structure stays prefix-free. The prefix is alphanumeric (no ':' '-' '['
|
|
1291
|
+
// ']' '/'), so \`prefix + ':'\` is an unambiguous separator.
|
|
1292
|
+
const prefix = (ds.theme && ds.theme.prefix) || '';
|
|
1293
|
+
const pfx = (c) => prefix ? prefix + ':' + c : c;
|
|
1294
|
+
const unpfx = (c) => (prefix && c.startsWith(prefix + ':')) ? c.slice(prefix.length + 1) : c;
|
|
1295
|
+
|
|
1176
1296
|
const entries = ds.getClassList();
|
|
1177
1297
|
const classNames = entries.map(e => e[0]);
|
|
1178
1298
|
|
|
@@ -1180,8 +1300,10 @@ async function main() {
|
|
|
1180
1300
|
const classNameIndex = new Map();
|
|
1181
1301
|
for (let i = 0; i < classNames.length; i++) classNameIndex.set(classNames[i], i);
|
|
1182
1302
|
|
|
1183
|
-
// Validity: which classes produce CSS
|
|
1184
|
-
|
|
1303
|
+
// Validity: which classes produce CSS. Validate the prefixed form, but keep
|
|
1304
|
+
// cssResults aligned positionally to the unprefixed classNames so the later
|
|
1305
|
+
// cssProps / arbitraryEquivalents phases keep indexing by position.
|
|
1306
|
+
const cssResults = ds.candidatesToCss(classNames.map(pfx));
|
|
1185
1307
|
const validClasses = classNames.filter((_, i) => cssResults[i] != null);
|
|
1186
1308
|
|
|
1187
1309
|
// Expand: validate extra candidates not in getClassList() but valid in v4
|
|
@@ -1203,7 +1325,7 @@ async function main() {
|
|
|
1203
1325
|
}
|
|
1204
1326
|
}
|
|
1205
1327
|
if (extraCandidates.length > 0) {
|
|
1206
|
-
const extraResults = ds.candidatesToCss(extraCandidates);
|
|
1328
|
+
const extraResults = ds.candidatesToCss(extraCandidates.map(pfx));
|
|
1207
1329
|
for (let i = 0; i < extraCandidates.length; i++) {
|
|
1208
1330
|
if (extraResults[i] != null) {
|
|
1209
1331
|
validClasses.push(extraCandidates[i]);
|
|
@@ -1232,9 +1354,11 @@ async function main() {
|
|
|
1232
1354
|
// NOTE: canonicalizeCandidates deduplicates, so we must call it one class at a time
|
|
1233
1355
|
const canonical = {};
|
|
1234
1356
|
for (const cls of classNames) {
|
|
1235
|
-
const result = ds.canonicalizeCandidates([cls]);
|
|
1236
|
-
|
|
1237
|
-
|
|
1357
|
+
const result = ds.canonicalizeCandidates([pfx(cls)]);
|
|
1358
|
+
const canon = result[0] ? unpfx(result[0]) : null;
|
|
1359
|
+
// Compare unprefixed-vs-unprefixed so the prefix itself never reads as a change.
|
|
1360
|
+
if (canon && canon !== cls) {
|
|
1361
|
+
canonical[cls] = canon;
|
|
1238
1362
|
}
|
|
1239
1363
|
}
|
|
1240
1364
|
|
|
@@ -1265,13 +1389,14 @@ async function main() {
|
|
|
1265
1389
|
}
|
|
1266
1390
|
const legacyToProcess = legacyCandidates.filter(cls => !validSet.has(cls));
|
|
1267
1391
|
if (legacyToProcess.length > 0) {
|
|
1268
|
-
const legacyCssResults = ds.candidatesToCss(legacyToProcess);
|
|
1392
|
+
const legacyCssResults = ds.candidatesToCss(legacyToProcess.map(pfx));
|
|
1269
1393
|
for (let i = 0; i < legacyToProcess.length; i++) {
|
|
1270
1394
|
if (legacyCssResults[i] == null) continue;
|
|
1271
1395
|
const cls = legacyToProcess[i];
|
|
1272
|
-
const result = ds.canonicalizeCandidates([cls]);
|
|
1273
|
-
|
|
1274
|
-
|
|
1396
|
+
const result = ds.canonicalizeCandidates([pfx(cls)]);
|
|
1397
|
+
const canon = result[0] ? unpfx(result[0]) : null;
|
|
1398
|
+
if (canon && canon !== cls) {
|
|
1399
|
+
canonical[cls] = canon;
|
|
1275
1400
|
}
|
|
1276
1401
|
// Mark as valid so no-unknown-classes doesn't flag legacy spellings.
|
|
1277
1402
|
validClasses.push(cls);
|
|
@@ -1285,9 +1410,9 @@ async function main() {
|
|
|
1285
1410
|
if (!classNameIndex.has(cls)) allForOrder.push(cls);
|
|
1286
1411
|
}
|
|
1287
1412
|
const order = {};
|
|
1288
|
-
const orderResults = ds.getClassOrder(allForOrder);
|
|
1413
|
+
const orderResults = ds.getClassOrder(allForOrder.map(pfx));
|
|
1289
1414
|
for (const [name, val] of orderResults) {
|
|
1290
|
-
if (val !== null) order[name] = val.toString();
|
|
1415
|
+
if (val !== null) order[unpfx(name)] = val.toString();
|
|
1291
1416
|
}
|
|
1292
1417
|
|
|
1293
1418
|
// CSS properties per class — extract only from the ROOT selector, not descendant selectors.
|
|
@@ -1376,7 +1501,9 @@ async function main() {
|
|
|
1376
1501
|
|
|
1377
1502
|
for (let i = 0; i < classNames.length; i++) {
|
|
1378
1503
|
if (cssResults[i]) {
|
|
1379
|
-
|
|
1504
|
+
// Match against the prefixed selector (the CSS emits \`.tw\\:flex\`), but
|
|
1505
|
+
// store under the unprefixed key. extractRootCssProps CSS-escapes the ':'.
|
|
1506
|
+
const props = extractRootCssProps(cssResults[i], pfx(classNames[i]));
|
|
1380
1507
|
if (props.length > 0) cssProps[classNames[i]] = props;
|
|
1381
1508
|
}
|
|
1382
1509
|
}
|
|
@@ -1402,7 +1529,8 @@ async function main() {
|
|
|
1402
1529
|
let acm;
|
|
1403
1530
|
attrClassRe.lastIndex = 0;
|
|
1404
1531
|
while ((acm = attrClassRe.exec(cssResults[i])) !== null) {
|
|
1405
|
-
|
|
1532
|
+
// Typography-style plugins emit \`[class~="tw:not-prose"]\` under a prefix.
|
|
1533
|
+
componentClasses.push(unpfx(acm[1]));
|
|
1406
1534
|
}
|
|
1407
1535
|
}
|
|
1408
1536
|
}
|
|
@@ -1437,7 +1565,10 @@ async function main() {
|
|
|
1437
1565
|
}
|
|
1438
1566
|
if (candidates.length > 0) {
|
|
1439
1567
|
const arbForms = candidates.map(c => c.arbitraryForm);
|
|
1440
|
-
|
|
1568
|
+
// Prefix only the validation; keys/values stored stay prefix-free. The
|
|
1569
|
+
// declaration block extractDeclarations compares is identical with or
|
|
1570
|
+
// without the prefix (the prefix only affects the selector).
|
|
1571
|
+
const arbResults = ds.candidatesToCss(arbForms.map(pfx));
|
|
1441
1572
|
for (let i = 0; i < candidates.length; i++) {
|
|
1442
1573
|
if (!arbResults[i]) continue;
|
|
1443
1574
|
if (extractDeclarations(arbResults[i]) === extractDeclarations(candidates[i].namedCss)) {
|
|
@@ -1446,7 +1577,7 @@ async function main() {
|
|
|
1446
1577
|
}
|
|
1447
1578
|
}
|
|
1448
1579
|
|
|
1449
|
-
const json = JSON.stringify({ validClasses, canonical, order, cssProps, variantOrder, componentClasses, arbitraryEquivalents });
|
|
1580
|
+
const json = JSON.stringify({ validClasses, canonical, order, cssProps, variantOrder, componentClasses, arbitraryEquivalents, prefix });
|
|
1450
1581
|
// Atomic write: write to a unique temp path then rename, so a peer isolate
|
|
1451
1582
|
// busy-waiting on the cache file never observes a half-written JSON.
|
|
1452
1583
|
writeFileSync(WD_TMP_PATH, json);
|
|
@@ -1455,8 +1586,20 @@ async function main() {
|
|
|
1455
1586
|
main()
|
|
1456
1587
|
.then(() => { Atomics.store(control, 2, 1); Atomics.notify(control, 2); })
|
|
1457
1588
|
.catch((e) => signalError(e));
|
|
1589
|
+
} catch (e) {
|
|
1590
|
+
signalError(e);
|
|
1591
|
+
}
|
|
1458
1592
|
`;
|
|
1459
|
-
|
|
1593
|
+
function cacheDirName() {
|
|
1594
|
+
try {
|
|
1595
|
+
const info = userInfo();
|
|
1596
|
+
const id = typeof info.uid === "number" && info.uid >= 0 ? String(info.uid) : info.username;
|
|
1597
|
+
return `oxlint-tailwindcss-${String(id).replace(/[^a-zA-Z0-9_-]/g, "_")}`;
|
|
1598
|
+
} catch {
|
|
1599
|
+
return "oxlint-tailwindcss";
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
const CACHE_DIR = join(tmpdir(), cacheDirName());
|
|
1460
1603
|
/**
|
|
1461
1604
|
* Cache key derived from:
|
|
1462
1605
|
* - md5(PRECOMPUTE_SCRIPT): auto-invalidates when our precompute logic changes,
|
|
@@ -1475,17 +1618,73 @@ const CACHE_KEY = computeCacheKey(PRECOMPUTE_SCRIPT, TAILWIND_NODE_VERSION);
|
|
|
1475
1618
|
function computeContentHash(content) {
|
|
1476
1619
|
return createHash("md5").update(`${CACHE_KEY}:${content}`).digest("hex");
|
|
1477
1620
|
}
|
|
1621
|
+
const IMPORT_RE = /@import\s+(?:url\(\s*)?['"]([^'"]+)['"]/g;
|
|
1622
|
+
/**
|
|
1623
|
+
* Concatenate the entry CSS with the content of its locally-imported files, so
|
|
1624
|
+
* the cache key invalidates when an `@import`'d file changes — not only when the
|
|
1625
|
+
* entry itself does (DS-A2). Without this, editing a `@theme`/component file
|
|
1626
|
+
* pulled in via `@import "./theme.css"` served a stale design system until the
|
|
1627
|
+
* entry was touched or the Tailwind version changed.
|
|
1628
|
+
*
|
|
1629
|
+
* Resolves RELATIVE imports (`./`, `../`) recursively up to a small depth;
|
|
1630
|
+
* package imports (`@import "tailwindcss"`, `tw-animate-css`) are already
|
|
1631
|
+
* covered by the `@tailwindcss/node` version baked into CACHE_KEY. Best-effort:
|
|
1632
|
+
* an unreadable import contributes nothing (it can't affect the DS either).
|
|
1633
|
+
*/
|
|
1634
|
+
function hashableContent(entryPath, entryContent) {
|
|
1635
|
+
const parts = [entryContent];
|
|
1636
|
+
const seen = new Set([resolve(entryPath)]);
|
|
1637
|
+
const visit = (cssPath, content, depth) => {
|
|
1638
|
+
if (depth <= 0) return;
|
|
1639
|
+
const baseDir = dirname(cssPath);
|
|
1640
|
+
IMPORT_RE.lastIndex = 0;
|
|
1641
|
+
const specifiers = [];
|
|
1642
|
+
let m;
|
|
1643
|
+
while ((m = IMPORT_RE.exec(content)) !== null) if (m[1].startsWith(".")) specifiers.push(m[1]);
|
|
1644
|
+
for (const spec of specifiers) {
|
|
1645
|
+
const importPath = resolve(baseDir, spec.split("?")[0]);
|
|
1646
|
+
if (seen.has(importPath)) continue;
|
|
1647
|
+
seen.add(importPath);
|
|
1648
|
+
let importContent;
|
|
1649
|
+
try {
|
|
1650
|
+
importContent = readFileSync(importPath, "utf-8");
|
|
1651
|
+
} catch {
|
|
1652
|
+
continue;
|
|
1653
|
+
}
|
|
1654
|
+
parts.push(importContent);
|
|
1655
|
+
visit(importPath, importContent, depth - 1);
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
visit(resolve(entryPath), entryContent, 4);
|
|
1659
|
+
return parts.join("\0");
|
|
1660
|
+
}
|
|
1478
1661
|
function getContentCachePath(contentHash) {
|
|
1479
1662
|
return join(CACHE_DIR, `${contentHash}.json`);
|
|
1480
1663
|
}
|
|
1664
|
+
/**
|
|
1665
|
+
* Minimal shape check for a cache payload. Guards against (a) a poisoned file
|
|
1666
|
+
* planted by a local attacker and (b) a corrupt/half-written or version-skewed
|
|
1667
|
+
* file. A `{}` that is valid JSON but missing fields would otherwise blow up
|
|
1668
|
+
* later in `DesignSystemCache.fromPrecomputed` with a raw TypeError that isn't
|
|
1669
|
+
* plugin-fatal, breaking the lint with no diagnostic. We don't deep-validate
|
|
1670
|
+
* every entry — just enough that `fromPrecomputed` can rely on the fields.
|
|
1671
|
+
*/
|
|
1672
|
+
function isPrecomputedData(data) {
|
|
1673
|
+
if (typeof data !== "object" || data === null) return false;
|
|
1674
|
+
const d = data;
|
|
1675
|
+
const isObject = (v) => typeof v === "object" && v !== null;
|
|
1676
|
+
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);
|
|
1677
|
+
}
|
|
1481
1678
|
function tryReadCache(cachePath) {
|
|
1482
1679
|
const raw = tryReadRawCache(cachePath);
|
|
1483
1680
|
if (raw === null) return null;
|
|
1681
|
+
let data;
|
|
1484
1682
|
try {
|
|
1485
|
-
|
|
1683
|
+
data = JSON.parse(raw);
|
|
1486
1684
|
} catch {
|
|
1487
1685
|
return null;
|
|
1488
1686
|
}
|
|
1687
|
+
return isPrecomputedData(data) ? data : null;
|
|
1489
1688
|
}
|
|
1490
1689
|
function tryReadRawCache(cachePath) {
|
|
1491
1690
|
try {
|
|
@@ -1512,6 +1711,23 @@ function tryUnlink(path) {
|
|
|
1512
1711
|
unlinkSync(path);
|
|
1513
1712
|
} catch {}
|
|
1514
1713
|
}
|
|
1714
|
+
/**
|
|
1715
|
+
* Reclaim a stale lock by exclusive rename rather than unlink (DS-M1). Two
|
|
1716
|
+
* waiters that both judge the lock stale would otherwise both `unlink` it — and
|
|
1717
|
+
* the second unlink could delete a FRESH lock a third isolate just created,
|
|
1718
|
+
* letting two precomputes run in parallel (the very amplification the lock
|
|
1719
|
+
* exists to prevent, #24). `renameSync` moves the file atomically: only one
|
|
1720
|
+
* waiter wins the move; the loser gets ENOENT and loops back to re-check.
|
|
1721
|
+
*/
|
|
1722
|
+
function reclaimStaleLock(lockPath) {
|
|
1723
|
+
const reclaimPath = `${lockPath}.reclaim.${process.pid}.${threadId}.${precomputeSeq++}`;
|
|
1724
|
+
try {
|
|
1725
|
+
renameSync(lockPath, reclaimPath);
|
|
1726
|
+
} catch {
|
|
1727
|
+
return;
|
|
1728
|
+
}
|
|
1729
|
+
tryUnlink(reclaimPath);
|
|
1730
|
+
}
|
|
1515
1731
|
/** control[2] — the worker's ready/done signal (0=loading, 1=done, -1=error). */
|
|
1516
1732
|
const PRECOMPUTE_SIGNAL_INDEX = 2;
|
|
1517
1733
|
const ERR_BUFFER_SIZE = 64 * 1024;
|
|
@@ -1564,15 +1780,12 @@ function runPrecomputeViaWorker(resolvedPath, tailwindNodePath, cachePath, timeo
|
|
|
1564
1780
|
} catch (cause) {
|
|
1565
1781
|
throw precomputeLoadError(resolvedPath, cause);
|
|
1566
1782
|
}
|
|
1567
|
-
|
|
1568
|
-
worker.on("error", (err) => {
|
|
1569
|
-
workerError = err;
|
|
1570
|
-
});
|
|
1783
|
+
worker.on("error", () => {});
|
|
1571
1784
|
try {
|
|
1572
1785
|
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.");
|
|
1573
1786
|
if (control[PRECOMPUTE_SIGNAL_INDEX] === -1) {
|
|
1574
1787
|
const len = errLengthView.getUint32(0);
|
|
1575
|
-
throw precomputeLoadError(resolvedPath, len > 0 ? new Error(Buffer.from(errDataArea.slice(0, len)).toString("utf-8")) :
|
|
1788
|
+
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)"));
|
|
1576
1789
|
}
|
|
1577
1790
|
} finally {
|
|
1578
1791
|
tryUnlink(tmpPath);
|
|
@@ -1580,14 +1793,17 @@ function runPrecomputeViaWorker(resolvedPath, tailwindNodePath, cachePath, timeo
|
|
|
1580
1793
|
}
|
|
1581
1794
|
}
|
|
1582
1795
|
/**
|
|
1583
|
-
* Run the precompute worker, then read back the JSON it wrote to
|
|
1584
|
-
* Used by both the lock-winner path and the uncoordinated degrade
|
|
1796
|
+
* Run the precompute worker, then read back and validate the JSON it wrote to
|
|
1797
|
+
* `cachePath`. Used by both the lock-winner path and the uncoordinated degrade
|
|
1798
|
+
* path. Returns the validated `PrecomputedData` (never a raw string), so a
|
|
1799
|
+
* malformed payload surfaces as a clear diagnostic here instead of crashing
|
|
1800
|
+
* later in `DesignSystemCache.fromPrecomputed`.
|
|
1585
1801
|
*/
|
|
1586
1802
|
function precomputeAndRead(resolvedPath, tailwindNodePath, cachePath, timeout) {
|
|
1587
1803
|
runPrecomputeViaWorker(resolvedPath, tailwindNodePath, cachePath, timeout);
|
|
1588
|
-
const
|
|
1589
|
-
if (
|
|
1590
|
-
return
|
|
1804
|
+
const data = tryReadCache(cachePath);
|
|
1805
|
+
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.");
|
|
1806
|
+
return data;
|
|
1591
1807
|
}
|
|
1592
1808
|
/**
|
|
1593
1809
|
* Return the raw precompute JSON for `contentHash`, spawning at most one
|
|
@@ -1598,26 +1814,30 @@ function computeWithLock(resolvedPath, tailwindNodePath, contentHash, cachePath,
|
|
|
1598
1814
|
const lockPath = join(CACHE_DIR, `${contentHash}.lock`);
|
|
1599
1815
|
const staleMs = timeout + 3e4;
|
|
1600
1816
|
try {
|
|
1601
|
-
mkdirSync(CACHE_DIR, {
|
|
1817
|
+
mkdirSync(CACHE_DIR, {
|
|
1818
|
+
recursive: true,
|
|
1819
|
+
mode: 448
|
|
1820
|
+
});
|
|
1602
1821
|
} catch {
|
|
1603
1822
|
return precomputeAndRead(resolvedPath, tailwindNodePath, cachePath, timeout);
|
|
1604
1823
|
}
|
|
1605
1824
|
const start = Date.now();
|
|
1606
1825
|
for (;;) {
|
|
1607
|
-
const
|
|
1608
|
-
if (
|
|
1826
|
+
const cached = tryReadCache(cachePath);
|
|
1827
|
+
if (cached) return cached;
|
|
1609
1828
|
let lockFd;
|
|
1610
1829
|
try {
|
|
1611
1830
|
lockFd = openSync(lockPath, "wx");
|
|
1612
1831
|
} catch (cause) {
|
|
1613
1832
|
if (cause.code === "EEXIST") {
|
|
1614
|
-
if (lockAgeMs(lockPath) > staleMs || Date.now() - start > staleMs * 2)
|
|
1833
|
+
if (lockAgeMs(lockPath) > staleMs || Date.now() - start > staleMs * 2) reclaimStaleLock(lockPath);
|
|
1615
1834
|
else syncSleep(LOCK_POLL_MS);
|
|
1616
1835
|
continue;
|
|
1617
1836
|
}
|
|
1618
1837
|
return precomputeAndRead(resolvedPath, tailwindNodePath, cachePath, timeout);
|
|
1619
1838
|
}
|
|
1620
1839
|
try {
|
|
1840
|
+
tryUnlink(cachePath);
|
|
1621
1841
|
return precomputeAndRead(resolvedPath, tailwindNodePath, cachePath, timeout);
|
|
1622
1842
|
} finally {
|
|
1623
1843
|
closeSync(lockFd);
|
|
@@ -1640,17 +1860,12 @@ function loadDesignSystemSync(cssPath, timeout) {
|
|
|
1640
1860
|
} catch (cause) {
|
|
1641
1861
|
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 });
|
|
1642
1862
|
}
|
|
1643
|
-
const contentHash = computeContentHash(content);
|
|
1863
|
+
const contentHash = computeContentHash(hashableContent(resolvedPath, content));
|
|
1644
1864
|
const contentCachePath = getContentCachePath(contentHash);
|
|
1645
1865
|
const cached = tryReadCache(contentCachePath);
|
|
1646
1866
|
if (cached) return cached;
|
|
1647
1867
|
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.");
|
|
1648
|
-
|
|
1649
|
-
try {
|
|
1650
|
-
return JSON.parse(raw);
|
|
1651
|
-
} catch (cause) {
|
|
1652
|
-
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 });
|
|
1653
|
-
}
|
|
1868
|
+
return computeWithLock(resolvedPath, TAILWIND_NODE_PATH, contentHash, contentCachePath, timeout ?? 6e4);
|
|
1654
1869
|
}
|
|
1655
1870
|
//#endregion
|
|
1656
1871
|
//#region src/design-system/debug.ts
|
|
@@ -2108,6 +2323,7 @@ const noUnknownClasses = defineRule({
|
|
|
2108
2323
|
messages: {
|
|
2109
2324
|
unknown: "\"{{className}}\" is not a valid Tailwind class.",
|
|
2110
2325
|
unknownWithSuggestion: "\"{{className}}\" is not a valid Tailwind class. Did you mean \"{{suggestion}}\"?",
|
|
2326
|
+
missingPrefix: "\"{{className}}\" needs the \"{{prefix}}:\" prefix to produce CSS. Did you mean \"{{suggestion}}\"?",
|
|
2111
2327
|
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\".",
|
|
2112
2328
|
...DS_UNAVAILABLE_MESSAGE
|
|
2113
2329
|
}
|
|
@@ -2123,8 +2339,14 @@ const noUnknownClasses = defineRule({
|
|
|
2123
2339
|
if (allowlist.has(className)) return true;
|
|
2124
2340
|
return ignorePrefixes.some((prefix) => className.startsWith(prefix));
|
|
2125
2341
|
}
|
|
2126
|
-
function
|
|
2127
|
-
|
|
2342
|
+
function strippedUtility(className) {
|
|
2343
|
+
const { utility, variant } = splitUtilityAndVariant(className);
|
|
2344
|
+
const { bare, position } = splitImportant(utility);
|
|
2345
|
+
return {
|
|
2346
|
+
variant,
|
|
2347
|
+
bare,
|
|
2348
|
+
position
|
|
2349
|
+
};
|
|
2128
2350
|
}
|
|
2129
2351
|
function check(locations) {
|
|
2130
2352
|
if (locations.length === 0) return;
|
|
@@ -2136,10 +2358,36 @@ const noUnknownClasses = defineRule({
|
|
|
2136
2358
|
const classes = split.classes;
|
|
2137
2359
|
for (const cls of classes) {
|
|
2138
2360
|
if (shouldIgnore(cls)) continue;
|
|
2139
|
-
const
|
|
2140
|
-
if (
|
|
2141
|
-
|
|
2142
|
-
|
|
2361
|
+
const validity = cache.classValidity(cls);
|
|
2362
|
+
if (validity === "valid") continue;
|
|
2363
|
+
const { variant, bare, position } = strippedUtility(cls);
|
|
2364
|
+
if (DEPRECATED_MAP[bare]) continue;
|
|
2365
|
+
if (validity === "missing-prefix") {
|
|
2366
|
+
const fixed = `${cache.prefix}:${cls}`;
|
|
2367
|
+
const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? fixed : c));
|
|
2368
|
+
context.report({
|
|
2369
|
+
node: loc.node,
|
|
2370
|
+
messageId: "missingPrefix",
|
|
2371
|
+
data: {
|
|
2372
|
+
className: cls,
|
|
2373
|
+
prefix: cache.prefix,
|
|
2374
|
+
suggestion: fixed
|
|
2375
|
+
},
|
|
2376
|
+
suggest: [{
|
|
2377
|
+
messageId: "suggestReplace",
|
|
2378
|
+
data: {
|
|
2379
|
+
className: cls,
|
|
2380
|
+
replacement: fixed
|
|
2381
|
+
},
|
|
2382
|
+
fix(fixer) {
|
|
2383
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
2384
|
+
}
|
|
2385
|
+
}]
|
|
2386
|
+
});
|
|
2387
|
+
continue;
|
|
2388
|
+
}
|
|
2389
|
+
const suggestionBare = findBestSuggestion(bare, cache.validClasses);
|
|
2390
|
+
const suggestion = suggestionBare ? variant + reattachImportant(suggestionBare, position) : null;
|
|
2143
2391
|
if (suggestion) {
|
|
2144
2392
|
const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? suggestion : c));
|
|
2145
2393
|
context.report({
|
|
@@ -2299,7 +2547,7 @@ const noConflictingClasses = defineRule({
|
|
|
2299
2547
|
}],
|
|
2300
2548
|
defaultOptions: [{}],
|
|
2301
2549
|
messages: {
|
|
2302
|
-
conflict: "\"{{classA}}\" and \"{{classB}}\" affect {{properties}}.
|
|
2550
|
+
conflict: "\"{{classA}}\" and \"{{classB}}\" both affect {{properties}}. Only one applies — which wins depends on the generated stylesheet order, not the attribute order. Remove one.",
|
|
2303
2551
|
...DS_UNAVAILABLE_MESSAGE
|
|
2304
2552
|
}
|
|
2305
2553
|
},
|
|
@@ -2332,9 +2580,11 @@ const noConflictingClasses = defineRule({
|
|
|
2332
2580
|
const propsA = propsMap.get(classA) ?? [];
|
|
2333
2581
|
for (let j = i + 1; j < variantClasses.length; j++) {
|
|
2334
2582
|
const classB = variantClasses[j];
|
|
2583
|
+
if (classA === classB) continue;
|
|
2335
2584
|
const propsB = propsMap.get(classB) ?? [];
|
|
2336
2585
|
if (shouldSkipPair(classA, classB, propsA, propsB)) continue;
|
|
2337
|
-
const
|
|
2586
|
+
const propsBSet = new Set(propsB);
|
|
2587
|
+
const overlap = propsA.filter((p) => propsBSet.has(p));
|
|
2338
2588
|
if (overlap.length > 0) {
|
|
2339
2589
|
const propList = overlap.length <= 3 ? `"${overlap.join("\", \"")}"` : `${overlap.length} CSS properties`;
|
|
2340
2590
|
context.report({
|
|
@@ -2343,8 +2593,7 @@ const noConflictingClasses = defineRule({
|
|
|
2343
2593
|
data: {
|
|
2344
2594
|
classA,
|
|
2345
2595
|
classB,
|
|
2346
|
-
properties: propList
|
|
2347
|
-
winner: classB
|
|
2596
|
+
properties: propList
|
|
2348
2597
|
}
|
|
2349
2598
|
});
|
|
2350
2599
|
}
|
|
@@ -2376,16 +2625,104 @@ const noConflictingClasses = defineRule({
|
|
|
2376
2625
|
*/
|
|
2377
2626
|
const BUFFER_SIZE = 4 * 1024 * 1024;
|
|
2378
2627
|
const HEADER_INTS = 4;
|
|
2628
|
+
const LENGTH_OFFSET = HEADER_INTS * 4;
|
|
2379
2629
|
const DATA_OFFSET = 20;
|
|
2380
2630
|
const INIT_TIMEOUT = 6e4;
|
|
2381
2631
|
const REQUEST_TIMEOUT = 3e4;
|
|
2632
|
+
/**
|
|
2633
|
+
* Build the worker script shared by `sort-service` and `canonicalize-service`.
|
|
2634
|
+
* Owns the entire SharedArrayBuffer protocol (offsets derived from the same
|
|
2635
|
+
* constants the host uses, so they can't drift), the design-system load with
|
|
2636
|
+
* error propagation (DS-M4: the real cause is written into the buffer so the
|
|
2637
|
+
* host can surface it, not a generic "failed to load"), the ready signal, and
|
|
2638
|
+
* the request loop. `handlerExpr` is a function expression `(ds, request) =>
|
|
2639
|
+
* result` — the only part that differs between services.
|
|
2640
|
+
*/
|
|
2641
|
+
function makeWorkerScript(handlerExpr) {
|
|
2642
|
+
return `
|
|
2643
|
+
const { workerData } = require('worker_threads');
|
|
2644
|
+
async function main() {
|
|
2645
|
+
const { sharedBuffer, cssPath } = workerData;
|
|
2646
|
+
const control = new Int32Array(sharedBuffer, 0, ${HEADER_INTS});
|
|
2647
|
+
const lengthView = new DataView(sharedBuffer, ${LENGTH_OFFSET}, 4);
|
|
2648
|
+
const dataArea = new Uint8Array(sharedBuffer, ${DATA_OFFSET});
|
|
2649
|
+
|
|
2650
|
+
// On load failure, write the real cause into the data region so the host can
|
|
2651
|
+
// report it instead of a bare "failed to load the design system".
|
|
2652
|
+
function signalLoadError(e) {
|
|
2653
|
+
try {
|
|
2654
|
+
const msg = Buffer.from(String((e && e.message) || e || 'unknown design-system load error'), 'utf-8');
|
|
2655
|
+
const n = Math.min(msg.length, dataArea.length);
|
|
2656
|
+
dataArea.set(msg.subarray(0, n), 0);
|
|
2657
|
+
lengthView.setUint32(0, n);
|
|
2658
|
+
} catch {}
|
|
2659
|
+
Atomics.store(control, 2, -1);
|
|
2660
|
+
Atomics.notify(control, 2);
|
|
2661
|
+
}
|
|
2662
|
+
|
|
2663
|
+
let ds;
|
|
2664
|
+
try {
|
|
2665
|
+
const { __unstable__loadDesignSystem } = require(workerData.tailwindNodePath);
|
|
2666
|
+
const { readFileSync } = require('fs');
|
|
2667
|
+
const { dirname } = require('path');
|
|
2668
|
+
const css = readFileSync(cssPath, 'utf-8');
|
|
2669
|
+
ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
|
|
2670
|
+
} catch (e) {
|
|
2671
|
+
signalLoadError(e);
|
|
2672
|
+
return;
|
|
2673
|
+
}
|
|
2674
|
+
|
|
2675
|
+
Atomics.store(control, 2, 1);
|
|
2676
|
+
Atomics.notify(control, 2);
|
|
2677
|
+
|
|
2678
|
+
const handler = ${handlerExpr};
|
|
2679
|
+
|
|
2680
|
+
while (true) {
|
|
2681
|
+
Atomics.wait(control, 0, 0);
|
|
2682
|
+
const len = lengthView.getUint32(0);
|
|
2683
|
+
const requestStr = Buffer.from(dataArea.slice(0, len)).toString('utf-8');
|
|
2684
|
+
Atomics.store(control, 0, 0);
|
|
2685
|
+
|
|
2686
|
+
let response;
|
|
2687
|
+
try {
|
|
2688
|
+
const request = JSON.parse(requestStr);
|
|
2689
|
+
const result = handler(ds, request);
|
|
2690
|
+
response = Buffer.from(JSON.stringify(result), 'utf-8');
|
|
2691
|
+
} catch {
|
|
2692
|
+
response = Buffer.from('null', 'utf-8');
|
|
2693
|
+
}
|
|
2694
|
+
|
|
2695
|
+
// DS-M6: if the response doesn't fit the shared buffer, reply with a
|
|
2696
|
+
// sentinel the host reads as a rejected request, instead of letting
|
|
2697
|
+
// dataArea.set throw and kill the worker (which would hang the caller
|
|
2698
|
+
// until the request timeout and then report a misleading timeout).
|
|
2699
|
+
if (response.length > dataArea.length) {
|
|
2700
|
+
response = Buffer.from('null', 'utf-8');
|
|
2701
|
+
}
|
|
2702
|
+
|
|
2703
|
+
dataArea.set(response, 0);
|
|
2704
|
+
lengthView.setUint32(0, response.length);
|
|
2705
|
+
Atomics.store(control, 1, 1);
|
|
2706
|
+
Atomics.notify(control, 1);
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
main().catch(() => {});
|
|
2710
|
+
`;
|
|
2711
|
+
}
|
|
2382
2712
|
var DesignSystemWorker = class {
|
|
2383
2713
|
opts;
|
|
2384
2714
|
ready = null;
|
|
2385
2715
|
lastError = null;
|
|
2716
|
+
lastErrorCssPath = null;
|
|
2386
2717
|
constructor(opts) {
|
|
2387
2718
|
this.opts = opts;
|
|
2388
2719
|
}
|
|
2720
|
+
/** Record an error as sticky for `cssPath` and return it for `throw`. */
|
|
2721
|
+
remember(cssPath, err) {
|
|
2722
|
+
this.lastError = err;
|
|
2723
|
+
this.lastErrorCssPath = cssPath;
|
|
2724
|
+
return err;
|
|
2725
|
+
}
|
|
2389
2726
|
/**
|
|
2390
2727
|
* Ensure the worker is running and pointed at `cssPath`. Returns the
|
|
2391
2728
|
* ready state. Throws `SortServiceError` on any failure (init timeout,
|
|
@@ -2393,14 +2730,12 @@ var DesignSystemWorker = class {
|
|
|
2393
2730
|
* cssPath rethrow without retrying.
|
|
2394
2731
|
*/
|
|
2395
2732
|
ensure(cssPath) {
|
|
2396
|
-
if (this.lastError && this.
|
|
2733
|
+
if (this.lastError && this.lastErrorCssPath === cssPath) throw this.lastError;
|
|
2397
2734
|
if (this.ready && this.ready.cssPath === cssPath) return this.ready;
|
|
2398
2735
|
if (this.ready) this.cleanup();
|
|
2399
2736
|
this.lastError = null;
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
throw this.lastError;
|
|
2403
|
-
}
|
|
2737
|
+
this.lastErrorCssPath = null;
|
|
2738
|
+
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."));
|
|
2404
2739
|
const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
|
|
2405
2740
|
const controlArray = new Int32Array(sharedBuffer, 0, HEADER_INTS);
|
|
2406
2741
|
const lengthView = new DataView(sharedBuffer, HEADER_INTS * 4, 4);
|
|
@@ -2416,22 +2751,22 @@ var DesignSystemWorker = class {
|
|
|
2416
2751
|
}
|
|
2417
2752
|
});
|
|
2418
2753
|
} catch (cause) {
|
|
2419
|
-
this.
|
|
2420
|
-
throw this.lastError;
|
|
2754
|
+
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 }));
|
|
2421
2755
|
}
|
|
2422
2756
|
worker.unref();
|
|
2423
2757
|
worker.on("error", (err) => {
|
|
2424
2758
|
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 });
|
|
2759
|
+
this.lastErrorCssPath = cssPath;
|
|
2425
2760
|
});
|
|
2426
2761
|
if (Atomics.wait(controlArray, 2, 0, INIT_TIMEOUT) === "timed-out") {
|
|
2427
|
-
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.");
|
|
2428
2762
|
this.terminateWorker(worker);
|
|
2429
|
-
throw this.
|
|
2763
|
+
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."));
|
|
2430
2764
|
}
|
|
2431
2765
|
if (controlArray[2] === -1) {
|
|
2432
|
-
|
|
2766
|
+
const len = lengthView.getUint32(0);
|
|
2767
|
+
const detail = len > 0 ? Buffer.from(dataArea.slice(0, len)).toString("utf-8") : "";
|
|
2433
2768
|
this.terminateWorker(worker);
|
|
2434
|
-
throw this.
|
|
2769
|
+
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."));
|
|
2435
2770
|
}
|
|
2436
2771
|
this.ready = {
|
|
2437
2772
|
worker,
|
|
@@ -2455,9 +2790,8 @@ var DesignSystemWorker = class {
|
|
|
2455
2790
|
Atomics.store(state.controlArray, 0, 1);
|
|
2456
2791
|
Atomics.notify(state.controlArray, 0);
|
|
2457
2792
|
if (Atomics.wait(state.controlArray, 1, 0, REQUEST_TIMEOUT) === "timed-out") {
|
|
2458
|
-
this.lastError = new SortServiceError(`${this.opts.serviceName} worker request timed out after ${REQUEST_TIMEOUT}ms.`, "Raise settings.tailwindcss.timeout if your machine is slow.");
|
|
2459
2793
|
this.cleanup();
|
|
2460
|
-
throw this.
|
|
2794
|
+
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."));
|
|
2461
2795
|
}
|
|
2462
2796
|
const responseLen = state.lengthView.getUint32(0);
|
|
2463
2797
|
const responseStr = Buffer.from(state.dataArea.slice(0, responseLen)).toString("utf-8");
|
|
@@ -2466,20 +2800,19 @@ var DesignSystemWorker = class {
|
|
|
2466
2800
|
try {
|
|
2467
2801
|
parsed = JSON.parse(responseStr);
|
|
2468
2802
|
} catch (cause) {
|
|
2469
|
-
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 });
|
|
2470
2803
|
this.cleanup();
|
|
2471
|
-
throw this.
|
|
2804
|
+
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 }));
|
|
2472
2805
|
}
|
|
2473
2806
|
if (parsed === null) {
|
|
2474
|
-
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.");
|
|
2475
2807
|
this.cleanup();
|
|
2476
|
-
throw this.
|
|
2808
|
+
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."));
|
|
2477
2809
|
}
|
|
2478
2810
|
return parsed;
|
|
2479
2811
|
}
|
|
2480
2812
|
reset() {
|
|
2481
2813
|
this.cleanup();
|
|
2482
2814
|
this.lastError = null;
|
|
2815
|
+
this.lastErrorCssPath = null;
|
|
2483
2816
|
}
|
|
2484
2817
|
cleanup() {
|
|
2485
2818
|
if (this.ready) {
|
|
@@ -2511,60 +2844,14 @@ var DesignSystemWorker = class {
|
|
|
2511
2844
|
* subsequent lookup is O(1).
|
|
2512
2845
|
*/
|
|
2513
2846
|
const canonWorker = new DesignSystemWorker({
|
|
2514
|
-
workerScript: `
|
|
2515
|
-
const {
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
let ds;
|
|
2524
|
-
try {
|
|
2525
|
-
const { __unstable__loadDesignSystem } = require(workerData.tailwindNodePath);
|
|
2526
|
-
const { readFileSync } = require('fs');
|
|
2527
|
-
const { dirname } = require('path');
|
|
2528
|
-
const css = readFileSync(cssPath, 'utf-8');
|
|
2529
|
-
ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
|
|
2530
|
-
} catch {
|
|
2531
|
-
Atomics.store(control, 2, -1);
|
|
2532
|
-
Atomics.notify(control, 2);
|
|
2533
|
-
return;
|
|
2534
|
-
}
|
|
2535
|
-
|
|
2536
|
-
Atomics.store(control, 2, 1);
|
|
2537
|
-
Atomics.notify(control, 2);
|
|
2538
|
-
|
|
2539
|
-
while (true) {
|
|
2540
|
-
Atomics.wait(control, 0, 0);
|
|
2541
|
-
const len = lengthView.getUint32(0);
|
|
2542
|
-
const requestStr = Buffer.from(dataArea.slice(0, len)).toString('utf-8');
|
|
2543
|
-
Atomics.store(control, 0, 0);
|
|
2544
|
-
|
|
2545
|
-
let response;
|
|
2546
|
-
try {
|
|
2547
|
-
const { classes, rem } = JSON.parse(requestStr);
|
|
2548
|
-
const options = rem ? { rem } : undefined;
|
|
2549
|
-
// canonicalizeCandidates deduplicates its input, so we must call it
|
|
2550
|
-
// one class at a time to preserve order/length. See sync-loader.ts.
|
|
2551
|
-
const result = classes.map((cls) => {
|
|
2552
|
-
const r = ds.canonicalizeCandidates([cls], options);
|
|
2553
|
-
return r[0] ?? cls;
|
|
2554
|
-
});
|
|
2555
|
-
response = Buffer.from(JSON.stringify(result), 'utf-8');
|
|
2556
|
-
} catch {
|
|
2557
|
-
response = Buffer.from('null', 'utf-8');
|
|
2558
|
-
}
|
|
2559
|
-
|
|
2560
|
-
dataArea.set(response, 0);
|
|
2561
|
-
lengthView.setUint32(0, response.length);
|
|
2562
|
-
Atomics.store(control, 1, 1);
|
|
2563
|
-
Atomics.notify(control, 1);
|
|
2564
|
-
}
|
|
2565
|
-
}
|
|
2566
|
-
main();
|
|
2567
|
-
`,
|
|
2847
|
+
workerScript: makeWorkerScript(`(ds, request) => {
|
|
2848
|
+
const { classes, rem } = request;
|
|
2849
|
+
const options = rem ? { rem } : undefined;
|
|
2850
|
+
return classes.map((cls) => {
|
|
2851
|
+
const r = ds.canonicalizeCandidates([cls], options);
|
|
2852
|
+
return r[0] ?? cls;
|
|
2853
|
+
});
|
|
2854
|
+
}`),
|
|
2568
2855
|
serviceName: "canonicalize"
|
|
2569
2856
|
});
|
|
2570
2857
|
/**
|
|
@@ -2609,7 +2896,7 @@ function canonicalizeClassesSync(cssPath, classes, rem) {
|
|
|
2609
2896
|
for (let k = 0; k < uniqueMissing.length; k++) freshByClass.set(uniqueMissing[k], fresh[k]);
|
|
2610
2897
|
for (let j = 0; j < missing.length; j++) {
|
|
2611
2898
|
const cls = missing[j];
|
|
2612
|
-
const value = freshByClass.get(cls) ?? cls;
|
|
2899
|
+
const value = roundRemValue(freshByClass.get(cls) ?? cls);
|
|
2613
2900
|
canonCache.set(cachePrefix + cls, value);
|
|
2614
2901
|
out[missingIdx[j]] = value;
|
|
2615
2902
|
}
|
|
@@ -2701,62 +2988,17 @@ const enforceCanonical = defineRule({
|
|
|
2701
2988
|
* Atomics.wait, fail-loud, sticky lastError) lives in `./ds-worker.ts`.
|
|
2702
2989
|
*/
|
|
2703
2990
|
const sortWorker = new DesignSystemWorker({
|
|
2704
|
-
workerScript: `
|
|
2705
|
-
const
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
const { __unstable__loadDesignSystem } = require(workerData.tailwindNodePath);
|
|
2716
|
-
const { readFileSync } = require('fs');
|
|
2717
|
-
const { dirname } = require('path');
|
|
2718
|
-
const css = readFileSync(cssPath, 'utf-8');
|
|
2719
|
-
ds = await __unstable__loadDesignSystem(css, { base: dirname(cssPath) });
|
|
2720
|
-
} catch {
|
|
2721
|
-
Atomics.store(control, 2, -1);
|
|
2722
|
-
Atomics.notify(control, 2);
|
|
2723
|
-
return;
|
|
2724
|
-
}
|
|
2725
|
-
|
|
2726
|
-
Atomics.store(control, 2, 1);
|
|
2727
|
-
Atomics.notify(control, 2);
|
|
2728
|
-
|
|
2729
|
-
while (true) {
|
|
2730
|
-
Atomics.wait(control, 0, 0);
|
|
2731
|
-
const len = lengthView.getUint32(0);
|
|
2732
|
-
const requestStr = Buffer.from(dataArea.slice(0, len)).toString('utf-8');
|
|
2733
|
-
Atomics.store(control, 0, 0);
|
|
2734
|
-
|
|
2735
|
-
let response;
|
|
2736
|
-
try {
|
|
2737
|
-
const classes = JSON.parse(requestStr);
|
|
2738
|
-
const ordered = ds.getClassOrder(classes);
|
|
2739
|
-
const sorted = [...ordered]
|
|
2740
|
-
.sort((a, b) => {
|
|
2741
|
-
if (a[1] === null && b[1] === null) return 0;
|
|
2742
|
-
if (a[1] === null) return -1;
|
|
2743
|
-
if (b[1] === null) return 1;
|
|
2744
|
-
return a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0;
|
|
2745
|
-
})
|
|
2746
|
-
.map(([name]) => name);
|
|
2747
|
-
response = Buffer.from(JSON.stringify(sorted), 'utf-8');
|
|
2748
|
-
} catch {
|
|
2749
|
-
response = Buffer.from('null', 'utf-8');
|
|
2750
|
-
}
|
|
2751
|
-
|
|
2752
|
-
dataArea.set(response, 0);
|
|
2753
|
-
lengthView.setUint32(0, response.length);
|
|
2754
|
-
Atomics.store(control, 1, 1);
|
|
2755
|
-
Atomics.notify(control, 1);
|
|
2756
|
-
}
|
|
2757
|
-
}
|
|
2758
|
-
main();
|
|
2759
|
-
`,
|
|
2991
|
+
workerScript: makeWorkerScript(`(ds, classes) => {
|
|
2992
|
+
const ordered = ds.getClassOrder(classes);
|
|
2993
|
+
return [...ordered]
|
|
2994
|
+
.sort((a, b) => {
|
|
2995
|
+
if (a[1] === null && b[1] === null) return 0;
|
|
2996
|
+
if (a[1] === null) return -1;
|
|
2997
|
+
if (b[1] === null) return 1;
|
|
2998
|
+
return a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0;
|
|
2999
|
+
})
|
|
3000
|
+
.map(([name]) => name);
|
|
3001
|
+
}`),
|
|
2760
3002
|
serviceName: "sort"
|
|
2761
3003
|
});
|
|
2762
3004
|
/**
|
|
@@ -2808,13 +3050,9 @@ const enforceSortOrder = defineRule({
|
|
|
2808
3050
|
}
|
|
2809
3051
|
function sortStrict(classes) {
|
|
2810
3052
|
const groups = /* @__PURE__ */ new Map();
|
|
2811
|
-
const groupOrder = [];
|
|
2812
3053
|
for (const cls of classes) {
|
|
2813
3054
|
const { variant } = splitUtilityAndVariant(cls);
|
|
2814
|
-
if (!groups.has(variant))
|
|
2815
|
-
groups.set(variant, []);
|
|
2816
|
-
groupOrder.push(variant);
|
|
2817
|
-
}
|
|
3055
|
+
if (!groups.has(variant)) groups.set(variant, []);
|
|
2818
3056
|
groups.get(variant).push(cls);
|
|
2819
3057
|
}
|
|
2820
3058
|
for (const [, groupClasses] of groups) {
|
|
@@ -2830,7 +3068,10 @@ const enforceSortOrder = defineRule({
|
|
|
2830
3068
|
groupClasses.length = 0;
|
|
2831
3069
|
for (const [name] of ordered) groupClasses.push(name);
|
|
2832
3070
|
}
|
|
2833
|
-
const
|
|
3071
|
+
const stripKey = (k) => cache.prefix && k.startsWith(cache.prefix + ":") ? k.slice(cache.prefix.length + 1) : k;
|
|
3072
|
+
const sortedGroupKeys = [...groups.keys()].sort((ka, kb) => {
|
|
3073
|
+
const a = stripKey(ka);
|
|
3074
|
+
const b = stripKey(kb);
|
|
2834
3075
|
if (a === "" && b !== "") return -1;
|
|
2835
3076
|
if (a !== "" && b === "") return 1;
|
|
2836
3077
|
if (a === "" && b === "") return 0;
|
|
@@ -2993,26 +3234,6 @@ const enforceShorthand = defineRule({
|
|
|
2993
3234
|
}
|
|
2994
3235
|
});
|
|
2995
3236
|
//#endregion
|
|
2996
|
-
//#region src/utils/allowlist.ts
|
|
2997
|
-
/**
|
|
2998
|
-
* Shared regex-allowlist helpers used by rules that accept an `allowlist`
|
|
2999
|
-
* option of regex source strings (currently enforce-logical / enforce-physical).
|
|
3000
|
-
*
|
|
3001
|
-
* Invalid regex sources are skipped rather than thrown so a typo in one
|
|
3002
|
-
* pattern doesn't blow up the entire lint run.
|
|
3003
|
-
*/
|
|
3004
|
-
function compileRegexList(patterns) {
|
|
3005
|
-
if (!patterns || patterns.length === 0) return [];
|
|
3006
|
-
const compiled = [];
|
|
3007
|
-
for (const p of patterns) try {
|
|
3008
|
-
compiled.push(new RegExp(p));
|
|
3009
|
-
} catch {}
|
|
3010
|
-
return compiled;
|
|
3011
|
-
}
|
|
3012
|
-
function matchesAny(value, list) {
|
|
3013
|
-
return list.some((re) => re.test(value));
|
|
3014
|
-
}
|
|
3015
|
-
//#endregion
|
|
3016
3237
|
//#region src/rules/enforce-logical.ts
|
|
3017
3238
|
const LOGICAL_PHYSICAL_SCHEMA = {
|
|
3018
3239
|
type: "object",
|
|
@@ -3153,9 +3374,14 @@ function createDirectionalMapper(context, opts) {
|
|
|
3153
3374
|
if (matchesAny(cls, allowlist)) return null;
|
|
3154
3375
|
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
3155
3376
|
const { bare: bareUtility, position } = splitImportant(utility);
|
|
3377
|
+
const negative = bareUtility.startsWith("-");
|
|
3378
|
+
const core = negative ? bareUtility.slice(1) : bareUtility;
|
|
3156
3379
|
for (const { from, to, axis } of opts.mappings) {
|
|
3157
3380
|
if (direction !== "both" && direction !== axis) continue;
|
|
3158
|
-
if (
|
|
3381
|
+
if (core === from || core.startsWith(`${from}-`)) {
|
|
3382
|
+
const suffix = core.slice(from.length);
|
|
3383
|
+
return `${variant}${reattachImportant(`${negative ? "-" : ""}${to}${suffix}`, position)}`;
|
|
3384
|
+
}
|
|
3159
3385
|
}
|
|
3160
3386
|
return null;
|
|
3161
3387
|
}
|
|
@@ -3298,10 +3524,16 @@ const noRestrictedClasses = defineRule({
|
|
|
3298
3524
|
createOnce(context) {
|
|
3299
3525
|
const getConfig = createLazyOptions(context, (o) => ({
|
|
3300
3526
|
restrictedClasses: new Set(o?.classes ?? []),
|
|
3301
|
-
patterns: (o?.patterns ?? []).
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3527
|
+
patterns: (o?.patterns ?? []).flatMap((p) => {
|
|
3528
|
+
try {
|
|
3529
|
+
return [{
|
|
3530
|
+
regex: new RegExp(p.pattern),
|
|
3531
|
+
message: p.message
|
|
3532
|
+
}];
|
|
3533
|
+
} catch {
|
|
3534
|
+
return [];
|
|
3535
|
+
}
|
|
3536
|
+
})
|
|
3305
3537
|
}));
|
|
3306
3538
|
function check(locations) {
|
|
3307
3539
|
const { restrictedClasses, patterns } = getConfig();
|
|
@@ -3430,6 +3662,7 @@ const enforceConsistentImportantPosition = defineRule({
|
|
|
3430
3662
|
});
|
|
3431
3663
|
//#endregion
|
|
3432
3664
|
//#region src/rules/enforce-negative-arbitrary-values.ts
|
|
3665
|
+
const SIMPLE_DIMENSION = /^\d*\.?\d+[a-z%]*$/;
|
|
3433
3666
|
function fixClass(cls) {
|
|
3434
3667
|
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
3435
3668
|
const hasImportantPrefix = utility.startsWith("!");
|
|
@@ -3442,6 +3675,7 @@ function fixClass(cls) {
|
|
|
3442
3675
|
if (bracketClose === -1 || bracketClose < bracketOpen) return null;
|
|
3443
3676
|
const innerValue = bare.slice(bracketOpen + 1, bracketClose);
|
|
3444
3677
|
if (innerValue.startsWith("-")) return null;
|
|
3678
|
+
if (!SIMPLE_DIMENSION.test(innerValue)) return null;
|
|
3445
3679
|
const baseUtility = bare.slice(1, bracketOpen);
|
|
3446
3680
|
return `${variant}${hasImportantPrefix ? "!" : ""}${baseUtility}[-${innerValue}]${hasImportantSuffix ? "!" : ""}`;
|
|
3447
3681
|
}
|
|
@@ -3576,13 +3810,48 @@ const KNOWN_PREFIXES = [
|
|
|
3576
3810
|
"via",
|
|
3577
3811
|
"to"
|
|
3578
3812
|
];
|
|
3813
|
+
const PROPERTY_GROUP_BY_UTILITY = {};
|
|
3814
|
+
for (const u of [
|
|
3815
|
+
"block",
|
|
3816
|
+
"inline-block",
|
|
3817
|
+
"inline",
|
|
3818
|
+
"flex",
|
|
3819
|
+
"inline-flex",
|
|
3820
|
+
"grid",
|
|
3821
|
+
"inline-grid",
|
|
3822
|
+
"flow-root",
|
|
3823
|
+
"contents",
|
|
3824
|
+
"table",
|
|
3825
|
+
"inline-table",
|
|
3826
|
+
"table-caption",
|
|
3827
|
+
"table-cell",
|
|
3828
|
+
"table-row",
|
|
3829
|
+
"table-row-group",
|
|
3830
|
+
"table-header-group",
|
|
3831
|
+
"table-footer-group",
|
|
3832
|
+
"table-column",
|
|
3833
|
+
"table-column-group",
|
|
3834
|
+
"list-item",
|
|
3835
|
+
"hidden"
|
|
3836
|
+
]) PROPERTY_GROUP_BY_UTILITY[u] = "display";
|
|
3837
|
+
for (const u of [
|
|
3838
|
+
"static",
|
|
3839
|
+
"fixed",
|
|
3840
|
+
"absolute",
|
|
3841
|
+
"relative",
|
|
3842
|
+
"sticky"
|
|
3843
|
+
]) PROPERTY_GROUP_BY_UTILITY[u] = "position";
|
|
3579
3844
|
/**
|
|
3580
|
-
*
|
|
3581
|
-
*
|
|
3845
|
+
* Maps a utility to a key identifying the CSS property it sets, so a base and a
|
|
3846
|
+
* variant class for the same property group together. Exact-match equivalence
|
|
3847
|
+
* groups (display, position) win; otherwise fall back to the prefix heuristic
|
|
3848
|
+
* (e.g. "bg" from "bg-gray-900", "text" from "text-white").
|
|
3582
3849
|
*/
|
|
3583
3850
|
function getUtilityPrefix(utility) {
|
|
3584
3851
|
let u = splitImportant(utility).bare;
|
|
3585
3852
|
if (u.startsWith("-")) u = u.slice(1);
|
|
3853
|
+
const group = PROPERTY_GROUP_BY_UTILITY[u];
|
|
3854
|
+
if (group) return group;
|
|
3586
3855
|
for (const prefix of KNOWN_PREFIXES) if (u === prefix || u.startsWith(`${prefix}-`)) return prefix;
|
|
3587
3856
|
const dashIdx = u.indexOf("-");
|
|
3588
3857
|
return dashIdx >= 0 ? u.slice(0, dashIdx) : u;
|
|
@@ -3690,13 +3959,10 @@ const noHardcodedColors = defineRule({
|
|
|
3690
3959
|
docs: { description: "Disallow hardcoded color values in Tailwind CSS classes" },
|
|
3691
3960
|
schema: [{
|
|
3692
3961
|
type: "object",
|
|
3693
|
-
properties: {
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
items: { type: "string" }
|
|
3698
|
-
}
|
|
3699
|
-
},
|
|
3962
|
+
properties: { allow: {
|
|
3963
|
+
type: "array",
|
|
3964
|
+
items: { type: "string" }
|
|
3965
|
+
} },
|
|
3700
3966
|
additionalProperties: false
|
|
3701
3967
|
}],
|
|
3702
3968
|
defaultOptions: [{ allow: [] }],
|
|
@@ -3728,24 +3994,6 @@ const noHardcodedColors = defineRule({
|
|
|
3728
3994
|
});
|
|
3729
3995
|
//#endregion
|
|
3730
3996
|
//#region src/rules/no-contradicting-variants.ts
|
|
3731
|
-
const TARGET_CHANGING_VARIANTS = new Set([
|
|
3732
|
-
"after",
|
|
3733
|
-
"before",
|
|
3734
|
-
"file",
|
|
3735
|
-
"placeholder",
|
|
3736
|
-
"marker",
|
|
3737
|
-
"backdrop",
|
|
3738
|
-
"selection",
|
|
3739
|
-
"first-line",
|
|
3740
|
-
"first-letter"
|
|
3741
|
-
]);
|
|
3742
|
-
function changesTarget(variant) {
|
|
3743
|
-
if (TARGET_CHANGING_VARIANTS.has(variant)) return true;
|
|
3744
|
-
if (variant === "*" || variant === "**") return true;
|
|
3745
|
-
if (variant.startsWith("[") && variant.endsWith("]")) return true;
|
|
3746
|
-
if (variant.startsWith("*:")) return true;
|
|
3747
|
-
return false;
|
|
3748
|
-
}
|
|
3749
3997
|
const noContradictingVariants = defineRule({
|
|
3750
3998
|
meta: {
|
|
3751
3999
|
type: "suggestion",
|
|
@@ -3780,18 +4028,6 @@ const noContradictingVariants = defineRule({
|
|
|
3780
4028
|
});
|
|
3781
4029
|
//#endregion
|
|
3782
4030
|
//#region src/rules/consistent-variant-order.ts
|
|
3783
|
-
const PSEUDO_ELEMENTS = new Set([
|
|
3784
|
-
"before",
|
|
3785
|
-
"after",
|
|
3786
|
-
"file",
|
|
3787
|
-
"placeholder",
|
|
3788
|
-
"selection",
|
|
3789
|
-
"marker",
|
|
3790
|
-
"backdrop",
|
|
3791
|
-
"first-line",
|
|
3792
|
-
"first-letter",
|
|
3793
|
-
"details-content"
|
|
3794
|
-
]);
|
|
3795
4031
|
const DEFAULT_VARIANT_ORDER = [
|
|
3796
4032
|
"*",
|
|
3797
4033
|
"**",
|
|
@@ -3890,17 +4126,12 @@ const consistentVariantOrder = defineRule({
|
|
|
3890
4126
|
},
|
|
3891
4127
|
createOnce(context) {
|
|
3892
4128
|
const getDS = createLazyLoader(context);
|
|
3893
|
-
const
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
dsCache = getDS().cache;
|
|
3897
|
-
} catch (err) {
|
|
3898
|
-
if (!isFatalError(err)) throw err;
|
|
3899
|
-
}
|
|
3900
|
-
if (o?.order) {
|
|
4129
|
+
const getOptions = createLazyOptions(context, (o) => ({ order: o?.order }));
|
|
4130
|
+
function buildPriority(order, dsCache) {
|
|
4131
|
+
if (order) {
|
|
3901
4132
|
const map = /* @__PURE__ */ new Map();
|
|
3902
|
-
for (let i = 0; i <
|
|
3903
|
-
const fallback =
|
|
4133
|
+
for (let i = 0; i < order.length; i++) map.set(order[i], i);
|
|
4134
|
+
const fallback = order.length;
|
|
3904
4135
|
return (v) => map.get(v) ?? fallback;
|
|
3905
4136
|
}
|
|
3906
4137
|
if (dsCache && dsCache.hasVariantOrder()) {
|
|
@@ -3911,20 +4142,66 @@ const consistentVariantOrder = defineRule({
|
|
|
3911
4142
|
for (let i = 0; i < DEFAULT_VARIANT_ORDER.length; i++) map.set(DEFAULT_VARIANT_ORDER[i], i);
|
|
3912
4143
|
const fallback = DEFAULT_VARIANT_ORDER.length;
|
|
3913
4144
|
return (v) => map.get(v) ?? fallback;
|
|
3914
|
-
}
|
|
4145
|
+
}
|
|
4146
|
+
const priorityByEntry = /* @__PURE__ */ new Map();
|
|
4147
|
+
const prefixByEntry = /* @__PURE__ */ new Map();
|
|
4148
|
+
function resolveForFile() {
|
|
4149
|
+
let dsCache = null;
|
|
4150
|
+
let entryKey = "";
|
|
4151
|
+
try {
|
|
4152
|
+
const ds = getDS();
|
|
4153
|
+
dsCache = ds.cache;
|
|
4154
|
+
entryKey = ds.entryPoint;
|
|
4155
|
+
} catch (err) {
|
|
4156
|
+
if (!isFatalError(err)) throw err;
|
|
4157
|
+
}
|
|
4158
|
+
let priorityOf = priorityByEntry.get(entryKey);
|
|
4159
|
+
if (!priorityOf) {
|
|
4160
|
+
priorityOf = buildPriority(getOptions().order, dsCache);
|
|
4161
|
+
priorityByEntry.set(entryKey, priorityOf);
|
|
4162
|
+
}
|
|
4163
|
+
let prefix = prefixByEntry.get(entryKey);
|
|
4164
|
+
if (prefix === void 0) {
|
|
4165
|
+
prefix = dsCache?.prefix ?? "";
|
|
4166
|
+
prefixByEntry.set(entryKey, prefix);
|
|
4167
|
+
}
|
|
4168
|
+
return {
|
|
4169
|
+
priorityOf,
|
|
4170
|
+
prefix
|
|
4171
|
+
};
|
|
4172
|
+
}
|
|
3915
4173
|
function reorderClass(cls) {
|
|
3916
|
-
const
|
|
4174
|
+
const { priorityOf, prefix } = resolveForFile();
|
|
4175
|
+
let pfx = "";
|
|
4176
|
+
let body = cls;
|
|
4177
|
+
if (prefix && cls.startsWith(prefix + ":")) {
|
|
4178
|
+
pfx = prefix + ":";
|
|
4179
|
+
body = cls.slice(prefix.length + 1);
|
|
4180
|
+
}
|
|
4181
|
+
const variants = extractVariants(body);
|
|
3917
4182
|
if (variants.length < 2) return null;
|
|
3918
|
-
const priorityOf = getPriority();
|
|
3919
|
-
const sorted = [...variants].sort((a, b) => priorityOf(a) - priorityOf(b));
|
|
3920
|
-
const nonPseudo = [];
|
|
3921
4183
|
const pseudo = [];
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
4184
|
+
const rest = [];
|
|
4185
|
+
for (const v of variants) if (isPseudoElementVariant(v)) pseudo.push(v);
|
|
4186
|
+
else rest.push(v);
|
|
4187
|
+
const reorderedRest = [];
|
|
4188
|
+
let segment = [];
|
|
4189
|
+
const flushSegment = () => {
|
|
4190
|
+
if (segment.length === 0) return;
|
|
4191
|
+
segment.sort((a, b) => priorityOf(a) - priorityOf(b));
|
|
4192
|
+
reorderedRest.push(...segment);
|
|
4193
|
+
segment = [];
|
|
4194
|
+
};
|
|
4195
|
+
for (const v of rest) if (isSelectorBarrier(v)) {
|
|
4196
|
+
flushSegment();
|
|
4197
|
+
reorderedRest.push(v);
|
|
4198
|
+
} else segment.push(v);
|
|
4199
|
+
flushSegment();
|
|
4200
|
+
pseudo.sort((a, b) => priorityOf(a) - priorityOf(b));
|
|
4201
|
+
const final = [...reorderedRest, ...pseudo];
|
|
3925
4202
|
if (variants.every((v, i) => v === final[i])) return null;
|
|
3926
|
-
const utility = extractUtility(
|
|
3927
|
-
return final.join(":") + ":" + utility;
|
|
4203
|
+
const utility = extractUtility(body);
|
|
4204
|
+
return pfx + final.join(":") + ":" + utility;
|
|
3928
4205
|
}
|
|
3929
4206
|
function check(locations) {
|
|
3930
4207
|
for (const loc of locations) {
|
|
@@ -4198,5 +4475,3 @@ const plugin = definePlugin({
|
|
|
4198
4475
|
});
|
|
4199
4476
|
//#endregion
|
|
4200
4477
|
export { plugin as default };
|
|
4201
|
-
|
|
4202
|
-
//# sourceMappingURL=index.mjs.map
|