oxlint-tailwindcss 0.6.2 → 0.7.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 +22 -4
- package/dist/index.cjs +318 -42
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +404 -125
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -363,6 +363,68 @@ function splitClasses(classString) {
|
|
|
363
363
|
if (current.length > 0) classes.push(current);
|
|
364
364
|
return classes;
|
|
365
365
|
}
|
|
366
|
+
function splitClassesWithSeparators(classString) {
|
|
367
|
+
const classes = [];
|
|
368
|
+
const separators = [];
|
|
369
|
+
let current = "";
|
|
370
|
+
let currentSep = "";
|
|
371
|
+
let bracketDepth = 0;
|
|
372
|
+
let inSingleQuote = false;
|
|
373
|
+
let inDoubleQuote = false;
|
|
374
|
+
for (let i = 0; i < classString.length; i++) {
|
|
375
|
+
const char = classString[i];
|
|
376
|
+
const prev = classString[i - 1];
|
|
377
|
+
if (bracketDepth > 0 && prev !== "\\") {
|
|
378
|
+
if (char === "'" && !inDoubleQuote) inSingleQuote = !inSingleQuote;
|
|
379
|
+
if (char === "\"" && !inSingleQuote) inDoubleQuote = !inDoubleQuote;
|
|
380
|
+
}
|
|
381
|
+
if (!inSingleQuote && !inDoubleQuote) {
|
|
382
|
+
if (char === "[") bracketDepth++;
|
|
383
|
+
if (char === "]") bracketDepth--;
|
|
384
|
+
}
|
|
385
|
+
if (/\s/.test(char) && bracketDepth === 0) {
|
|
386
|
+
if (current.length > 0) {
|
|
387
|
+
classes.push(current);
|
|
388
|
+
separators.push(currentSep);
|
|
389
|
+
current = "";
|
|
390
|
+
currentSep = "";
|
|
391
|
+
}
|
|
392
|
+
currentSep += char;
|
|
393
|
+
} else current += char;
|
|
394
|
+
}
|
|
395
|
+
if (current.length > 0) {
|
|
396
|
+
classes.push(current);
|
|
397
|
+
separators.push(currentSep);
|
|
398
|
+
currentSep = "";
|
|
399
|
+
}
|
|
400
|
+
separators.push(currentSep);
|
|
401
|
+
return {
|
|
402
|
+
classes,
|
|
403
|
+
separators
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Reconstruct a class string from a `ClassSplit` and a (possibly transformed)
|
|
408
|
+
* array of classes.
|
|
409
|
+
*
|
|
410
|
+
* - If `newClasses.length === split.classes.length` (1-to-1 transformation:
|
|
411
|
+
* canonicalize, sort, variant-order, etc.) every separator is preserved
|
|
412
|
+
* verbatim. This keeps multiline indentation intact.
|
|
413
|
+
* - If lengths differ (shorthand collapses pairs, no-duplicate removes dupes)
|
|
414
|
+
* the helper degrades gracefully: leading and trailing whitespace are
|
|
415
|
+
* preserved; classes are joined by the first internal separator that
|
|
416
|
+
* contains a newline, or a single space if none does.
|
|
417
|
+
*/
|
|
418
|
+
function rebuildClassString(split, newClasses) {
|
|
419
|
+
const { classes, separators } = split;
|
|
420
|
+
if (newClasses.length === classes.length) {
|
|
421
|
+
let result = separators[0];
|
|
422
|
+
for (let i = 0; i < newClasses.length; i++) result += newClasses[i] + separators[i + 1];
|
|
423
|
+
return result;
|
|
424
|
+
}
|
|
425
|
+
const join = separators.slice(1, -1).find((s) => s.includes("\n")) ?? " ";
|
|
426
|
+
return separators[0] + newClasses.join(join) + separators[separators.length - 1];
|
|
427
|
+
}
|
|
366
428
|
//#endregion
|
|
367
429
|
//#region src/rules/no-duplicate-classes.ts
|
|
368
430
|
const noDuplicateClasses = (0, _oxlint_plugins.defineRule)({
|
|
@@ -376,13 +438,14 @@ const noDuplicateClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
376
438
|
createOnce(context) {
|
|
377
439
|
function check(locations) {
|
|
378
440
|
for (const loc of locations) {
|
|
379
|
-
const
|
|
441
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
442
|
+
const classes = split.classes;
|
|
380
443
|
const seen = /* @__PURE__ */ new Set();
|
|
381
444
|
const duplicates = [];
|
|
382
445
|
for (const cls of classes) if (seen.has(cls)) duplicates.push(cls);
|
|
383
446
|
else seen.add(cls);
|
|
384
447
|
if (duplicates.length > 0) {
|
|
385
|
-
const fixed = [...new Set(classes)]
|
|
448
|
+
const fixed = rebuildClassString(split, [...new Set(classes)]);
|
|
386
449
|
for (const dup of duplicates) context.report({
|
|
387
450
|
node: loc.node,
|
|
388
451
|
messageId: "duplicate",
|
|
@@ -410,7 +473,12 @@ const noUnnecessaryWhitespace = (0, _oxlint_plugins.defineRule)({
|
|
|
410
473
|
createOnce(context) {
|
|
411
474
|
function check(locations) {
|
|
412
475
|
for (const loc of locations) {
|
|
413
|
-
let normalized = loc.value.
|
|
476
|
+
let normalized = loc.value.split("\n").map((line, i) => {
|
|
477
|
+
if (i === 0) return line.replace(/[ \t]+/g, " ");
|
|
478
|
+
const m = /^([ \t]*)([\s\S]*)$/.exec(line);
|
|
479
|
+
if (!m) return line.replace(/[ \t]+/g, " ");
|
|
480
|
+
return m[1] + m[2].replace(/[ \t]+/g, " ");
|
|
481
|
+
}).join("\n");
|
|
414
482
|
if (normalized.startsWith(" ") && !loc.preserveLeadingSpace) normalized = normalized.slice(1);
|
|
415
483
|
if (normalized.endsWith(" ") && !loc.preserveTrailingSpace) normalized = normalized.slice(0, -1);
|
|
416
484
|
if (normalized !== loc.value) context.report({
|
|
@@ -554,6 +622,20 @@ function hasArbitraryValue(cls) {
|
|
|
554
622
|
return utility.includes("[") && utility.includes("]");
|
|
555
623
|
}
|
|
556
624
|
/**
|
|
625
|
+
* Checks if a class's utility part contains dynamic value syntax: either
|
|
626
|
+
* arbitrary brackets (`w-[200px]`) or CSS variable shorthand (`bg-(--color)`).
|
|
627
|
+
*
|
|
628
|
+
* Unlike `hasArbitraryValue`, this also catches `(--var)` shorthand — both
|
|
629
|
+
* forms are what require the async Tailwind DS to canonicalize, because
|
|
630
|
+
* their value space is unbounded. Simple named classes (`flex`, `px-4`,
|
|
631
|
+
* even with variants like `[&>svg]:hover:flex`) can be canonicalized from
|
|
632
|
+
* the precomputed cache without touching the worker.
|
|
633
|
+
*/
|
|
634
|
+
function utilityHasDynamicValue(cls) {
|
|
635
|
+
const utility = extractUtility(cls);
|
|
636
|
+
return utility.includes("[") || utility.includes("(");
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
557
639
|
* Gets the arbitrary value from a class, or null if none.
|
|
558
640
|
* e.g. "w-[200px]" → "200px"
|
|
559
641
|
* "bg-[#ff0000]" → "#ff0000"
|
|
@@ -790,7 +872,11 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
790
872
|
* For arbitrary values (bg-[#123]) that aren't in the class list, we use heuristics.
|
|
791
873
|
*/
|
|
792
874
|
const PRECOMPUTE_SCRIPT = `
|
|
793
|
-
|
|
875
|
+
// Resolve @tailwindcss/node via an absolute path passed in by the parent
|
|
876
|
+
// process — bare-specifier lookup from this child's cwd fails under pnpm
|
|
877
|
+
// strict workspaces (the module lives under node_modules/.pnpm/... which
|
|
878
|
+
// is not on the resolution path from the consumer's project root).
|
|
879
|
+
const { __unstable__loadDesignSystem } = require(process.env.TAILWIND_NODE_PATH);
|
|
794
880
|
const { readFileSync } = require('fs');
|
|
795
881
|
const { dirname, resolve } = require('path');
|
|
796
882
|
|
|
@@ -1157,20 +1243,24 @@ function loadDesignSystemSync(cssPath, timeout) {
|
|
|
1157
1243
|
} catch {}
|
|
1158
1244
|
return cached;
|
|
1159
1245
|
}
|
|
1246
|
+
const tailwindNodePath = require.resolve("@tailwindcss/node");
|
|
1160
1247
|
const stdout = (0, node_child_process.execFileSync)(process.execPath, ["-e", PRECOMPUTE_SCRIPT], {
|
|
1161
1248
|
encoding: "utf-8",
|
|
1162
1249
|
timeout: timeout ?? 3e4,
|
|
1163
1250
|
maxBuffer: 50 * 1024 * 1024,
|
|
1164
1251
|
env: {
|
|
1165
1252
|
...process.env,
|
|
1166
|
-
TAILWIND_CSS_PATH: resolvedPath
|
|
1253
|
+
TAILWIND_CSS_PATH: resolvedPath,
|
|
1254
|
+
TAILWIND_NODE_PATH: tailwindNodePath
|
|
1167
1255
|
},
|
|
1168
1256
|
cwd: (0, node_path.dirname)(resolvedPath)
|
|
1169
1257
|
});
|
|
1170
1258
|
writeCacheFiles(contentCachePath, mtimeIndexPath, contentHash, stdout);
|
|
1171
1259
|
return JSON.parse(stdout);
|
|
1172
1260
|
} catch (error) {
|
|
1173
|
-
|
|
1261
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
1262
|
+
if (msg.includes("Cannot find module '@tailwindcss/node'")) console.error(`[oxlint-tailwindcss] Could not resolve '@tailwindcss/node' for "${resolvedPath}". If you are using pnpm with strict hoisting, add '@tailwindcss/node' as a direct devDependency, or upgrade oxlint-tailwindcss to >= 0.7.0 which resolves it from the plugin's own install location. DS-dependent rules will be skipped for this file.`);
|
|
1263
|
+
else console.error(`[oxlint-tailwindcss] Failed to load design system from "${resolvedPath}":`, msg);
|
|
1174
1264
|
return null;
|
|
1175
1265
|
}
|
|
1176
1266
|
}
|
|
@@ -1542,7 +1632,8 @@ const noDeprecatedClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1542
1632
|
function check(locations) {
|
|
1543
1633
|
const dsResult = getDS();
|
|
1544
1634
|
for (const loc of locations) {
|
|
1545
|
-
const
|
|
1635
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
1636
|
+
const classes = split.classes;
|
|
1546
1637
|
const offending = [];
|
|
1547
1638
|
for (const cls of classes) {
|
|
1548
1639
|
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
@@ -1563,7 +1654,7 @@ const noDeprecatedClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1563
1654
|
}
|
|
1564
1655
|
if (offending.length === 0) continue;
|
|
1565
1656
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
1566
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
1657
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
1567
1658
|
for (let i = 0; i < offending.length; i++) {
|
|
1568
1659
|
const { cls, replacement } = offending[i];
|
|
1569
1660
|
if (i === 0) context.report({
|
|
@@ -1664,7 +1755,8 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1664
1755
|
if (!ds) return;
|
|
1665
1756
|
const { cache } = ds;
|
|
1666
1757
|
for (const loc of locations) {
|
|
1667
|
-
const
|
|
1758
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
1759
|
+
const classes = split.classes;
|
|
1668
1760
|
for (const cls of classes) {
|
|
1669
1761
|
if (shouldIgnore(cls)) continue;
|
|
1670
1762
|
const stripped = stripModifiers(cls);
|
|
@@ -1672,7 +1764,7 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1672
1764
|
if (DEPRECATED_MAP[stripped]) continue;
|
|
1673
1765
|
const suggestion = findBestSuggestion(stripped, cache.validClasses);
|
|
1674
1766
|
if (suggestion) {
|
|
1675
|
-
const fixedValue = classes.map((c) => c === cls ? suggestion : c)
|
|
1767
|
+
const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? suggestion : c));
|
|
1676
1768
|
context.report({
|
|
1677
1769
|
node: loc.node,
|
|
1678
1770
|
messageId: "unknownWithSuggestion",
|
|
@@ -1806,12 +1898,24 @@ const noConflictingClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1806
1898
|
/**
|
|
1807
1899
|
* Persistent canonicalize service using worker_threads + SharedArrayBuffer.
|
|
1808
1900
|
*
|
|
1809
|
-
* Calls `ds.canonicalizeCandidates(
|
|
1901
|
+
* Calls `ds.canonicalizeCandidates([cls], { rem })` dynamically via a worker
|
|
1810
1902
|
* thread. Same pattern as sort-service.ts — loads the DS once, then accepts
|
|
1811
1903
|
* requests synchronously via Atomics.wait().
|
|
1812
1904
|
*
|
|
1813
1905
|
* This enables canonicalization of arbitrary user classes (e.g. `p-[2px]` → `p-0.5`)
|
|
1814
1906
|
* which can't be precomputed because the input space is infinite.
|
|
1907
|
+
*
|
|
1908
|
+
* ## Per-class cache (process-wide)
|
|
1909
|
+
*
|
|
1910
|
+
* Results are cached by `cssPath\0rem\0class`. The worker is invoked only for
|
|
1911
|
+
* cache misses. In practice the cache converges quickly — after the first few
|
|
1912
|
+
* files any given class has been seen, and every subsequent lookup is O(1).
|
|
1913
|
+
*
|
|
1914
|
+
* ## Per-class worker calls
|
|
1915
|
+
*
|
|
1916
|
+
* `ds.canonicalizeCandidates` deduplicates its input (see sync-loader.ts note),
|
|
1917
|
+
* so the worker MUST call it one class at a time to preserve input order/length.
|
|
1918
|
+
* The cache amortizes the per-call overhead.
|
|
1815
1919
|
*/
|
|
1816
1920
|
const BUFFER_SIZE$1 = 4 * 1024 * 1024;
|
|
1817
1921
|
const HEADER_INTS$1 = 4;
|
|
@@ -1856,7 +1960,12 @@ async function main() {
|
|
|
1856
1960
|
try {
|
|
1857
1961
|
const { classes, rem } = JSON.parse(requestStr);
|
|
1858
1962
|
const options = rem ? { rem } : undefined;
|
|
1859
|
-
|
|
1963
|
+
// canonicalizeCandidates deduplicates its input, so we must call it
|
|
1964
|
+
// one class at a time to preserve order/length. See sync-loader.ts.
|
|
1965
|
+
const result = classes.map((cls) => {
|
|
1966
|
+
const r = ds.canonicalizeCandidates([cls], options);
|
|
1967
|
+
return r[0] ?? cls;
|
|
1968
|
+
});
|
|
1860
1969
|
response = Buffer.from(JSON.stringify(result), 'utf-8');
|
|
1861
1970
|
} catch {
|
|
1862
1971
|
response = Buffer.from('null', 'utf-8');
|
|
@@ -1878,6 +1987,7 @@ let dataArea$1 = null;
|
|
|
1878
1987
|
let initialized$1 = false;
|
|
1879
1988
|
let available$1 = true;
|
|
1880
1989
|
let currentCssPath$1 = null;
|
|
1990
|
+
const canonCache = /* @__PURE__ */ new Map();
|
|
1881
1991
|
function ensureService$1(cssPath) {
|
|
1882
1992
|
if (initialized$1 && currentCssPath$1 === cssPath) return available$1;
|
|
1883
1993
|
if (initialized$1) {
|
|
@@ -1933,11 +2043,11 @@ function cleanup$1() {
|
|
|
1933
2043
|
}
|
|
1934
2044
|
}
|
|
1935
2045
|
/**
|
|
1936
|
-
*
|
|
1937
|
-
* Returns the canonicalized class array
|
|
2046
|
+
* Round-trip raw worker call for a batch of classes (no caching).
|
|
2047
|
+
* Returns the canonicalized class array (same length/order as input),
|
|
2048
|
+
* or null if the service is unavailable.
|
|
1938
2049
|
*/
|
|
1939
|
-
function
|
|
1940
|
-
if (!ensureService$1(cssPath)) return null;
|
|
2050
|
+
function callWorker(classes, rem) {
|
|
1941
2051
|
if (!controlArray$1 || !dataArea$1 || !lengthView$1) return null;
|
|
1942
2052
|
try {
|
|
1943
2053
|
const request = Buffer.from(JSON.stringify({
|
|
@@ -1964,6 +2074,43 @@ function canonicalizeClassesSync(cssPath, classes, rem) {
|
|
|
1964
2074
|
return null;
|
|
1965
2075
|
}
|
|
1966
2076
|
}
|
|
2077
|
+
/**
|
|
2078
|
+
* Canonicalize classes using the Tailwind CSS design system via worker thread.
|
|
2079
|
+
* Returns the canonicalized class array (same length/order as input), or null
|
|
2080
|
+
* if the service is unavailable.
|
|
2081
|
+
*
|
|
2082
|
+
* Uses a process-wide per-class cache: the worker is invoked only for classes
|
|
2083
|
+
* not already seen with this (cssPath, rem) combination.
|
|
2084
|
+
*/
|
|
2085
|
+
function canonicalizeClassesSync(cssPath, classes, rem) {
|
|
2086
|
+
if (!ensureService$1(cssPath)) return null;
|
|
2087
|
+
const out = Array.from({ length: classes.length });
|
|
2088
|
+
const missingIdx = [];
|
|
2089
|
+
const missing = [];
|
|
2090
|
+
const cachePrefix = `${cssPath}\0${rem ?? ""}\0`;
|
|
2091
|
+
for (let i = 0; i < classes.length; i++) {
|
|
2092
|
+
const key = cachePrefix + classes[i];
|
|
2093
|
+
const hit = canonCache.get(key);
|
|
2094
|
+
if (hit !== void 0) out[i] = hit;
|
|
2095
|
+
else {
|
|
2096
|
+
missingIdx.push(i);
|
|
2097
|
+
missing.push(classes[i]);
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
if (missing.length === 0) return out;
|
|
2101
|
+
const uniqueMissing = [...new Set(missing)];
|
|
2102
|
+
const fresh = callWorker(uniqueMissing, rem);
|
|
2103
|
+
if (!fresh || fresh.length !== uniqueMissing.length) return null;
|
|
2104
|
+
const freshByClass = /* @__PURE__ */ new Map();
|
|
2105
|
+
for (let k = 0; k < uniqueMissing.length; k++) freshByClass.set(uniqueMissing[k], fresh[k]);
|
|
2106
|
+
for (let j = 0; j < missing.length; j++) {
|
|
2107
|
+
const cls = missing[j];
|
|
2108
|
+
const value = freshByClass.get(cls) ?? cls;
|
|
2109
|
+
canonCache.set(cachePrefix + cls, value);
|
|
2110
|
+
out[missingIdx[j]] = value;
|
|
2111
|
+
}
|
|
2112
|
+
return out;
|
|
2113
|
+
}
|
|
1967
2114
|
//#endregion
|
|
1968
2115
|
//#region src/rules/enforce-canonical.ts
|
|
1969
2116
|
/**
|
|
@@ -2010,11 +2157,20 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
|
2010
2157
|
if (!ds) return;
|
|
2011
2158
|
const { cache, entryPoint } = ds;
|
|
2012
2159
|
for (const loc of locations) {
|
|
2013
|
-
const
|
|
2014
|
-
const
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2160
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2161
|
+
const classes = split.classes;
|
|
2162
|
+
const canonicals = Array.from({ length: classes.length });
|
|
2163
|
+
const arbitraryIdx = [];
|
|
2164
|
+
const arbitrary = [];
|
|
2165
|
+
for (let i = 0; i < classes.length; i++) if (utilityHasDynamicValue(classes[i])) {
|
|
2166
|
+
arbitraryIdx.push(i);
|
|
2167
|
+
arbitrary.push(classes[i]);
|
|
2168
|
+
} else canonicals[i] = cache.canonicalize(classes[i]);
|
|
2169
|
+
if (arbitrary.length > 0) {
|
|
2170
|
+
const dynamic = canonicalizeClassesSync(entryPoint, arbitrary, getRem());
|
|
2171
|
+
if (dynamic) for (let k = 0; k < arbitrary.length; k++) canonicals[arbitraryIdx[k]] = preserveImportantPosition(arbitrary[k], dynamic[k]);
|
|
2172
|
+
else for (let k = 0; k < arbitrary.length; k++) canonicals[arbitraryIdx[k]] = cache.canonicalize(arbitrary[k]);
|
|
2173
|
+
}
|
|
2018
2174
|
let firstNonCanonical = true;
|
|
2019
2175
|
for (let i = 0; i < classes.length; i++) {
|
|
2020
2176
|
const cls = classes[i];
|
|
@@ -2022,7 +2178,7 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
|
2022
2178
|
if (canonical === cls) continue;
|
|
2023
2179
|
if (firstNonCanonical) {
|
|
2024
2180
|
firstNonCanonical = false;
|
|
2025
|
-
const fixedValue =
|
|
2181
|
+
const fixedValue = rebuildClassString(split, canonicals);
|
|
2026
2182
|
context.report({
|
|
2027
2183
|
node: loc.node,
|
|
2028
2184
|
messageId: "nonCanonical",
|
|
@@ -2035,7 +2191,7 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
|
2035
2191
|
}
|
|
2036
2192
|
});
|
|
2037
2193
|
} else {
|
|
2038
|
-
const fixedValue =
|
|
2194
|
+
const fixedValue = rebuildClassString(split, canonicals);
|
|
2039
2195
|
context.report({
|
|
2040
2196
|
node: loc.node,
|
|
2041
2197
|
messageId: "nonCanonical",
|
|
@@ -2314,7 +2470,8 @@ const enforceSortOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
2314
2470
|
return result;
|
|
2315
2471
|
}
|
|
2316
2472
|
for (const loc of locations) {
|
|
2317
|
-
const
|
|
2473
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2474
|
+
const classes = split.classes;
|
|
2318
2475
|
if (classes.length < 2) continue;
|
|
2319
2476
|
const sortedNames = mode === "strict" ? sortStrict(classes) : sortDefault(classes);
|
|
2320
2477
|
if (classes.every((name, i) => name === sortedNames[i])) continue;
|
|
@@ -2322,7 +2479,7 @@ const enforceSortOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
2322
2479
|
node: loc.node,
|
|
2323
2480
|
messageId: "unsorted",
|
|
2324
2481
|
fix(fixer) {
|
|
2325
|
-
return fixer.replaceTextRange(loc.range, preserveSpaces(loc,
|
|
2482
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, rebuildClassString(split, sortedNames)));
|
|
2326
2483
|
}
|
|
2327
2484
|
});
|
|
2328
2485
|
}
|
|
@@ -2408,7 +2565,8 @@ const enforceShorthand = (0, _oxlint_plugins.defineRule)({
|
|
|
2408
2565
|
createOnce(context) {
|
|
2409
2566
|
function check(locations) {
|
|
2410
2567
|
for (const loc of locations) {
|
|
2411
|
-
const
|
|
2568
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2569
|
+
const classes = split.classes;
|
|
2412
2570
|
if (classes.length < 2) continue;
|
|
2413
2571
|
const classSet = new Set(classes);
|
|
2414
2572
|
const values = /* @__PURE__ */ new Set();
|
|
@@ -2437,7 +2595,7 @@ const enforceShorthand = (0, _oxlint_plugins.defineRule)({
|
|
|
2437
2595
|
replacement: `${importantStart}${rule.replacement}${importantEnd}`
|
|
2438
2596
|
},
|
|
2439
2597
|
fix(fixer) {
|
|
2440
|
-
return fixer.replaceTextRange(loc.range, preserveSpaces(loc,
|
|
2598
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, rebuildClassString(split, remaining)));
|
|
2441
2599
|
}
|
|
2442
2600
|
});
|
|
2443
2601
|
}
|
|
@@ -2495,7 +2653,8 @@ const enforceLogical = (0, _oxlint_plugins.defineRule)({
|
|
|
2495
2653
|
}
|
|
2496
2654
|
function check(locations) {
|
|
2497
2655
|
for (const loc of locations) {
|
|
2498
|
-
const
|
|
2656
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2657
|
+
const classes = split.classes;
|
|
2499
2658
|
const offending = [];
|
|
2500
2659
|
for (const cls of classes) {
|
|
2501
2660
|
const converted = convertClass(cls);
|
|
@@ -2506,7 +2665,7 @@ const enforceLogical = (0, _oxlint_plugins.defineRule)({
|
|
|
2506
2665
|
}
|
|
2507
2666
|
if (offending.length === 0) continue;
|
|
2508
2667
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
2509
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
2668
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
2510
2669
|
for (let i = 0; i < offending.length; i++) {
|
|
2511
2670
|
const { cls, replacement } = offending[i];
|
|
2512
2671
|
if (i === 0) context.report({
|
|
@@ -2574,7 +2733,8 @@ const enforcePhysical = (0, _oxlint_plugins.defineRule)({
|
|
|
2574
2733
|
}
|
|
2575
2734
|
function check(locations) {
|
|
2576
2735
|
for (const loc of locations) {
|
|
2577
|
-
const
|
|
2736
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2737
|
+
const classes = split.classes;
|
|
2578
2738
|
const offending = [];
|
|
2579
2739
|
for (const cls of classes) {
|
|
2580
2740
|
const converted = convertClass(cls);
|
|
@@ -2585,7 +2745,7 @@ const enforcePhysical = (0, _oxlint_plugins.defineRule)({
|
|
|
2585
2745
|
}
|
|
2586
2746
|
if (offending.length === 0) continue;
|
|
2587
2747
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
2588
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
2748
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
2589
2749
|
for (let i = 0; i < offending.length; i++) {
|
|
2590
2750
|
const { cls, replacement } = offending[i];
|
|
2591
2751
|
if (i === 0) context.report({
|
|
@@ -2828,7 +2988,8 @@ const enforceConsistentImportantPosition = (0, _oxlint_plugins.defineRule)({
|
|
|
2828
2988
|
function check(locations) {
|
|
2829
2989
|
const position = getPosition();
|
|
2830
2990
|
for (const loc of locations) {
|
|
2831
|
-
const
|
|
2991
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2992
|
+
const classes = split.classes;
|
|
2832
2993
|
const offending = [];
|
|
2833
2994
|
for (const cls of classes) {
|
|
2834
2995
|
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
@@ -2840,7 +3001,7 @@ const enforceConsistentImportantPosition = (0, _oxlint_plugins.defineRule)({
|
|
|
2840
3001
|
}
|
|
2841
3002
|
if (offending.length === 0) continue;
|
|
2842
3003
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
2843
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
3004
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
2844
3005
|
for (let i = 0; i < offending.length; i++) {
|
|
2845
3006
|
const { cls, replacement } = offending[i];
|
|
2846
3007
|
if (i === 0) context.report({
|
|
@@ -2914,7 +3075,8 @@ const enforceNegativeArbitraryValues = (0, _oxlint_plugins.defineRule)({
|
|
|
2914
3075
|
createOnce(context) {
|
|
2915
3076
|
function check(locations) {
|
|
2916
3077
|
for (const loc of locations) {
|
|
2917
|
-
const
|
|
3078
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
3079
|
+
const classes = split.classes;
|
|
2918
3080
|
const offending = [];
|
|
2919
3081
|
for (const cls of classes) {
|
|
2920
3082
|
const fixed = fixClass(cls);
|
|
@@ -2925,7 +3087,7 @@ const enforceNegativeArbitraryValues = (0, _oxlint_plugins.defineRule)({
|
|
|
2925
3087
|
}
|
|
2926
3088
|
if (offending.length === 0) continue;
|
|
2927
3089
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
2928
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
3090
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
2929
3091
|
for (let i = 0; i < offending.length; i++) {
|
|
2930
3092
|
const { cls, replacement } = offending[i];
|
|
2931
3093
|
if (i === 0) context.report({
|
|
@@ -3019,7 +3181,8 @@ const enforceConsistentVariableSyntax = (0, _oxlint_plugins.defineRule)({
|
|
|
3019
3181
|
function check(locations) {
|
|
3020
3182
|
const syntax = getSyntax();
|
|
3021
3183
|
for (const loc of locations) {
|
|
3022
|
-
const
|
|
3184
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
3185
|
+
const classes = split.classes;
|
|
3023
3186
|
const offending = [];
|
|
3024
3187
|
for (const cls of classes) {
|
|
3025
3188
|
const converted = convertClass(cls, syntax);
|
|
@@ -3030,7 +3193,7 @@ const enforceConsistentVariableSyntax = (0, _oxlint_plugins.defineRule)({
|
|
|
3030
3193
|
}
|
|
3031
3194
|
if (offending.length === 0) continue;
|
|
3032
3195
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
3033
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
3196
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
3034
3197
|
const messageId = syntax === "shorthand" ? "useShorthand" : "useExplicit";
|
|
3035
3198
|
for (let i = 0; i < offending.length; i++) {
|
|
3036
3199
|
const { cls, replacement } = offending[i];
|
|
@@ -3491,7 +3654,8 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
3491
3654
|
}
|
|
3492
3655
|
function check(locations) {
|
|
3493
3656
|
for (const loc of locations) {
|
|
3494
|
-
const
|
|
3657
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
3658
|
+
const classes = split.classes;
|
|
3495
3659
|
const offending = [];
|
|
3496
3660
|
for (const cls of classes) {
|
|
3497
3661
|
const fixed = reorderClass(cls);
|
|
@@ -3502,7 +3666,7 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
3502
3666
|
}
|
|
3503
3667
|
if (offending.length === 0) continue;
|
|
3504
3668
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
3505
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
3669
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
3506
3670
|
for (let i = 0; i < offending.length; i++) {
|
|
3507
3671
|
const { cls, replacement } = offending[i];
|
|
3508
3672
|
if (i === 0) context.report({
|
|
@@ -3643,7 +3807,8 @@ const noUnnecessaryArbitraryValue = (0, _oxlint_plugins.defineRule)({
|
|
|
3643
3807
|
if (!ds) return;
|
|
3644
3808
|
const { cache } = ds;
|
|
3645
3809
|
for (const loc of locations) {
|
|
3646
|
-
const
|
|
3810
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
3811
|
+
const classes = split.classes;
|
|
3647
3812
|
const offending = [];
|
|
3648
3813
|
for (const cls of classes) {
|
|
3649
3814
|
if (!hasArbitraryValue(cls)) continue;
|
|
@@ -3660,7 +3825,7 @@ const noUnnecessaryArbitraryValue = (0, _oxlint_plugins.defineRule)({
|
|
|
3660
3825
|
}
|
|
3661
3826
|
if (offending.length === 0) continue;
|
|
3662
3827
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
3663
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
3828
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
3664
3829
|
for (let i = 0; i < offending.length; i++) {
|
|
3665
3830
|
const { cls, replacement } = offending[i];
|
|
3666
3831
|
if (i === 0) context.report({
|
|
@@ -3699,6 +3864,116 @@ const noUnnecessaryArbitraryValue = (0, _oxlint_plugins.defineRule)({
|
|
|
3699
3864
|
}
|
|
3700
3865
|
});
|
|
3701
3866
|
//#endregion
|
|
3867
|
+
//#region src/rules/prefer-theme-tokens.ts
|
|
3868
|
+
/**
|
|
3869
|
+
* Match `prefix-(--name)` or `prefix-(--name)/modifier`.
|
|
3870
|
+
* Captures: 1=prefix, 2=variable name, 3=optional `/modifier` (kept verbatim).
|
|
3871
|
+
*/
|
|
3872
|
+
const PAREN_VAR_RE = /^(.+?)-\(--([\w-]+)\)(\/[^/\s]+)?$/;
|
|
3873
|
+
/**
|
|
3874
|
+
* Match `prefix-[var(--name)]` or `prefix-[var(--name)]/modifier`.
|
|
3875
|
+
* Captures: 1=prefix, 2=variable name, 3=optional `/modifier`.
|
|
3876
|
+
*/
|
|
3877
|
+
const BRACKET_VAR_RE = /^(.+?)-\[var\(--([\w-]+)\)\](\/[^/\s]+)?$/;
|
|
3878
|
+
function detectRawVariable(utility) {
|
|
3879
|
+
const paren = PAREN_VAR_RE.exec(utility);
|
|
3880
|
+
if (paren) return {
|
|
3881
|
+
prefix: paren[1],
|
|
3882
|
+
varName: paren[2],
|
|
3883
|
+
modifier: paren[3] ?? ""
|
|
3884
|
+
};
|
|
3885
|
+
const bracket = BRACKET_VAR_RE.exec(utility);
|
|
3886
|
+
if (bracket) return {
|
|
3887
|
+
prefix: bracket[1],
|
|
3888
|
+
varName: bracket[2],
|
|
3889
|
+
modifier: bracket[3] ?? ""
|
|
3890
|
+
};
|
|
3891
|
+
return null;
|
|
3892
|
+
}
|
|
3893
|
+
const preferThemeTokens = (0, _oxlint_plugins.defineRule)({
|
|
3894
|
+
meta: {
|
|
3895
|
+
type: "suggestion",
|
|
3896
|
+
docs: { description: "Prefer named theme-token utilities over raw CSS variable references when a matching utility exists" },
|
|
3897
|
+
fixable: "code",
|
|
3898
|
+
schema: [{
|
|
3899
|
+
type: "object",
|
|
3900
|
+
properties: { entryPoint: { type: "string" } },
|
|
3901
|
+
additionalProperties: false
|
|
3902
|
+
}],
|
|
3903
|
+
hasSuggestions: true,
|
|
3904
|
+
messages: {
|
|
3905
|
+
preferNamed: "\"{{className}}\" can be written as \"{{replacement}}\". Use the named theme token.",
|
|
3906
|
+
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
|
|
3907
|
+
}
|
|
3908
|
+
},
|
|
3909
|
+
createOnce(context) {
|
|
3910
|
+
const getDS = createLazyLoader(context);
|
|
3911
|
+
function check(locations) {
|
|
3912
|
+
const ds = getDS();
|
|
3913
|
+
if (!ds) return;
|
|
3914
|
+
const { cache } = ds;
|
|
3915
|
+
for (const loc of locations) {
|
|
3916
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
3917
|
+
const classes = split.classes;
|
|
3918
|
+
const offending = [];
|
|
3919
|
+
for (const cls of classes) {
|
|
3920
|
+
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
3921
|
+
const hasImportantPrefix = utility.startsWith("!");
|
|
3922
|
+
const hasImportantSuffix = !hasImportantPrefix && utility.endsWith("!");
|
|
3923
|
+
const bareUtility = hasImportantPrefix ? utility.slice(1) : hasImportantSuffix ? utility.slice(0, -1) : utility;
|
|
3924
|
+
const match = detectRawVariable(bareUtility);
|
|
3925
|
+
if (!match) continue;
|
|
3926
|
+
const candidate = `${match.prefix}-${match.varName}${match.modifier}`;
|
|
3927
|
+
if (!cache.isValid(candidate)) continue;
|
|
3928
|
+
const namedEquivalent = cache.getNamedEquivalent(bareUtility);
|
|
3929
|
+
if (namedEquivalent && namedEquivalent === `${match.prefix}-${match.varName}`) continue;
|
|
3930
|
+
const replacement = variant + (hasImportantPrefix ? "!" : "") + candidate + (hasImportantSuffix ? "!" : "");
|
|
3931
|
+
offending.push({
|
|
3932
|
+
cls,
|
|
3933
|
+
replacement
|
|
3934
|
+
});
|
|
3935
|
+
}
|
|
3936
|
+
if (offending.length === 0) continue;
|
|
3937
|
+
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
3938
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
3939
|
+
for (let i = 0; i < offending.length; i++) {
|
|
3940
|
+
const { cls, replacement } = offending[i];
|
|
3941
|
+
if (i === 0) context.report({
|
|
3942
|
+
node: loc.node,
|
|
3943
|
+
messageId: "preferNamed",
|
|
3944
|
+
data: {
|
|
3945
|
+
className: cls,
|
|
3946
|
+
replacement
|
|
3947
|
+
},
|
|
3948
|
+
fix(fixer) {
|
|
3949
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
3950
|
+
}
|
|
3951
|
+
});
|
|
3952
|
+
else context.report({
|
|
3953
|
+
node: loc.node,
|
|
3954
|
+
messageId: "preferNamed",
|
|
3955
|
+
data: {
|
|
3956
|
+
className: cls,
|
|
3957
|
+
replacement
|
|
3958
|
+
},
|
|
3959
|
+
suggest: [{
|
|
3960
|
+
messageId: "suggestReplace",
|
|
3961
|
+
data: {
|
|
3962
|
+
className: cls,
|
|
3963
|
+
replacement
|
|
3964
|
+
},
|
|
3965
|
+
fix(fixer) {
|
|
3966
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
3967
|
+
}
|
|
3968
|
+
}]
|
|
3969
|
+
});
|
|
3970
|
+
}
|
|
3971
|
+
}
|
|
3972
|
+
}
|
|
3973
|
+
return createExtractorVisitors(context, check);
|
|
3974
|
+
}
|
|
3975
|
+
});
|
|
3976
|
+
//#endregion
|
|
3702
3977
|
//#region src/index.ts
|
|
3703
3978
|
const plugin = (0, _oxlint_plugins.definePlugin)({
|
|
3704
3979
|
meta: { name: "tailwindcss" },
|
|
@@ -3724,7 +3999,8 @@ const plugin = (0, _oxlint_plugins.definePlugin)({
|
|
|
3724
3999
|
"no-contradicting-variants": noContradictingVariants,
|
|
3725
4000
|
"consistent-variant-order": consistentVariantOrder,
|
|
3726
4001
|
"enforce-consistent-line-wrapping": enforceConsistentLineWrapping,
|
|
3727
|
-
"no-unnecessary-arbitrary-value": noUnnecessaryArbitraryValue
|
|
4002
|
+
"no-unnecessary-arbitrary-value": noUnnecessaryArbitraryValue,
|
|
4003
|
+
"prefer-theme-tokens": preferThemeTokens
|
|
3728
4004
|
}
|
|
3729
4005
|
});
|
|
3730
4006
|
//#endregion
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;cAyBM,MAAA,EA2BJ,kBAAA,CA3BU,MAAA;AAAA"}
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;cAyBM,MAAA,EA2BJ,kBAAA,CA3BU,MAAA"}
|