oxlint-tailwindcss 0.6.3 → 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 +231 -32
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +317 -115
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# oxlint-tailwindcss
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
23 Tailwind CSS linting rules for [oxlint](https://oxc.rs/docs/guide/usage/linter). Built for Tailwind CSS v4 with auto-detection, typo suggestions, and autofixes.
|
|
4
4
|
|
|
5
5
|
Read the story behind this plugin: [oxlint-tailwindcss: The Linting Plugin Tailwind v4 Needed](https://sergioazocar.com/en/blog/oxlint-tailwindcss-the-linting-plugin-tailwind-v4-needed)
|
|
6
6
|
|
|
@@ -13,7 +13,7 @@ Read the story behind this plugin: [oxlint-tailwindcss: The Linting Plugin Tailw
|
|
|
13
13
|
- **Typo suggestions** — `itms-center` → "Did you mean `items-center`?"
|
|
14
14
|
- **Conflict detection** — Shows exactly which CSS properties conflict and which class wins.
|
|
15
15
|
- **Lightweight** — Only 2 runtime dependencies: `@tailwindcss/node` and `tailwindcss`.
|
|
16
|
-
- **
|
|
16
|
+
- **23 rules** — Correctness, style, complexity, and restriction rules with autofixes where possible.
|
|
17
17
|
- **Variable detection** — Lints variables named `className`, `classes`, `style` automatically.
|
|
18
18
|
- **Customizable** — Extend class detection with custom attributes, callees, tags, and variable patterns.
|
|
19
19
|
- **Component class support** — Recognizes `@layer components { .btn {} }` in your CSS.
|
|
@@ -58,6 +58,7 @@ Add the plugin to your `.oxlintrc.json`:
|
|
|
58
58
|
"tailwindcss/no-arbitrary-value": "off",
|
|
59
59
|
"tailwindcss/no-hardcoded-colors": "warn",
|
|
60
60
|
"tailwindcss/no-unnecessary-arbitrary-value": "warn",
|
|
61
|
+
"tailwindcss/prefer-theme-tokens": "off",
|
|
61
62
|
},
|
|
62
63
|
}
|
|
63
64
|
```
|
|
@@ -187,7 +188,7 @@ Output:
|
|
|
187
188
|
[oxlint-tailwindcss] packages/admin/src/Dashboard.tsx → packages/admin/src/styles.css
|
|
188
189
|
```
|
|
189
190
|
|
|
190
|
-
If no entry point is found (neither configured nor auto-detected), rules that require the design system (`no-unknown-classes`, `no-conflicting-classes`, `no-deprecated-classes`, `enforce-canonical`, `enforce-sort-order`, `no-unnecessary-arbitrary-value`, `consistent-variant-order`) are silently disabled. All other rules work without it.
|
|
191
|
+
If no entry point is found (neither configured nor auto-detected), rules that require the design system (`no-unknown-classes`, `no-conflicting-classes`, `no-deprecated-classes`, `enforce-canonical`, `enforce-sort-order`, `no-unnecessary-arbitrary-value`, `prefer-theme-tokens`, `consistent-variant-order`) are silently disabled. All other rules work without it.
|
|
191
192
|
|
|
192
193
|
## Custom class detection
|
|
193
194
|
|
|
@@ -217,7 +218,7 @@ You can extend these defaults via `settings.tailwindcss`. All values are **addit
|
|
|
217
218
|
}
|
|
218
219
|
```
|
|
219
220
|
|
|
220
|
-
This applies to all
|
|
221
|
+
This applies to all 23 rules at once. For example, adding `"classNames"` to `attributes` makes every rule lint `<Input classNames={{ root: "..." }} />`.
|
|
221
222
|
|
|
222
223
|
To **remove** specific items from the built-in defaults, use `exclude`:
|
|
223
224
|
|
|
@@ -810,6 +811,23 @@ Detects arbitrary values that have a named Tailwind equivalent. The arbitrary fo
|
|
|
810
811
|
|
|
811
812
|
---
|
|
812
813
|
|
|
814
|
+
#### `prefer-theme-tokens`
|
|
815
|
+
|
|
816
|
+
Suggests replacing raw CSS variable references like `border-(--border)` or `bg-[var(--primary)]` with the equivalent named theme-token utility (`border-border`, `bg-primary`) when one exists in your design system.
|
|
817
|
+
|
|
818
|
+
Unlike `no-unnecessary-arbitrary-value`, this rule fires even when the named utility produces _different_ CSS — for example, in shadcn-style themes where `--color-border: hsl(var(--border))` wraps the raw variable. Useful to match the official Tailwind VS Code extension's `suggestCanonicalClasses` behavior. **Off by default** because the replacement may change observable CSS in those setups.
|
|
819
|
+
|
|
820
|
+
```tsx
|
|
821
|
+
// ❌ Bad → ✅ Fixed (when border-border is a valid utility)
|
|
822
|
+
"border-(--border)" → "border-border"
|
|
823
|
+
"bg-[var(--primary)]" → "bg-primary"
|
|
824
|
+
"hover:bg-(--primary)/80" → "hover:bg-primary/80"
|
|
825
|
+
```
|
|
826
|
+
|
|
827
|
+
**Requires design system.** **Autofix:** Replaces with named class.
|
|
828
|
+
|
|
829
|
+
---
|
|
830
|
+
|
|
813
831
|
## Edge cases
|
|
814
832
|
|
|
815
833
|
The class parser correctly handles:
|
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({
|
|
@@ -804,7 +872,11 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
804
872
|
* For arbitrary values (bg-[#123]) that aren't in the class list, we use heuristics.
|
|
805
873
|
*/
|
|
806
874
|
const PRECOMPUTE_SCRIPT = `
|
|
807
|
-
|
|
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);
|
|
808
880
|
const { readFileSync } = require('fs');
|
|
809
881
|
const { dirname, resolve } = require('path');
|
|
810
882
|
|
|
@@ -1171,20 +1243,24 @@ function loadDesignSystemSync(cssPath, timeout) {
|
|
|
1171
1243
|
} catch {}
|
|
1172
1244
|
return cached;
|
|
1173
1245
|
}
|
|
1246
|
+
const tailwindNodePath = require.resolve("@tailwindcss/node");
|
|
1174
1247
|
const stdout = (0, node_child_process.execFileSync)(process.execPath, ["-e", PRECOMPUTE_SCRIPT], {
|
|
1175
1248
|
encoding: "utf-8",
|
|
1176
1249
|
timeout: timeout ?? 3e4,
|
|
1177
1250
|
maxBuffer: 50 * 1024 * 1024,
|
|
1178
1251
|
env: {
|
|
1179
1252
|
...process.env,
|
|
1180
|
-
TAILWIND_CSS_PATH: resolvedPath
|
|
1253
|
+
TAILWIND_CSS_PATH: resolvedPath,
|
|
1254
|
+
TAILWIND_NODE_PATH: tailwindNodePath
|
|
1181
1255
|
},
|
|
1182
1256
|
cwd: (0, node_path.dirname)(resolvedPath)
|
|
1183
1257
|
});
|
|
1184
1258
|
writeCacheFiles(contentCachePath, mtimeIndexPath, contentHash, stdout);
|
|
1185
1259
|
return JSON.parse(stdout);
|
|
1186
1260
|
} catch (error) {
|
|
1187
|
-
|
|
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);
|
|
1188
1264
|
return null;
|
|
1189
1265
|
}
|
|
1190
1266
|
}
|
|
@@ -1556,7 +1632,8 @@ const noDeprecatedClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1556
1632
|
function check(locations) {
|
|
1557
1633
|
const dsResult = getDS();
|
|
1558
1634
|
for (const loc of locations) {
|
|
1559
|
-
const
|
|
1635
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
1636
|
+
const classes = split.classes;
|
|
1560
1637
|
const offending = [];
|
|
1561
1638
|
for (const cls of classes) {
|
|
1562
1639
|
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
@@ -1577,7 +1654,7 @@ const noDeprecatedClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1577
1654
|
}
|
|
1578
1655
|
if (offending.length === 0) continue;
|
|
1579
1656
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
1580
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
1657
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
1581
1658
|
for (let i = 0; i < offending.length; i++) {
|
|
1582
1659
|
const { cls, replacement } = offending[i];
|
|
1583
1660
|
if (i === 0) context.report({
|
|
@@ -1678,7 +1755,8 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1678
1755
|
if (!ds) return;
|
|
1679
1756
|
const { cache } = ds;
|
|
1680
1757
|
for (const loc of locations) {
|
|
1681
|
-
const
|
|
1758
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
1759
|
+
const classes = split.classes;
|
|
1682
1760
|
for (const cls of classes) {
|
|
1683
1761
|
if (shouldIgnore(cls)) continue;
|
|
1684
1762
|
const stripped = stripModifiers(cls);
|
|
@@ -1686,7 +1764,7 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1686
1764
|
if (DEPRECATED_MAP[stripped]) continue;
|
|
1687
1765
|
const suggestion = findBestSuggestion(stripped, cache.validClasses);
|
|
1688
1766
|
if (suggestion) {
|
|
1689
|
-
const fixedValue = classes.map((c) => c === cls ? suggestion : c)
|
|
1767
|
+
const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? suggestion : c));
|
|
1690
1768
|
context.report({
|
|
1691
1769
|
node: loc.node,
|
|
1692
1770
|
messageId: "unknownWithSuggestion",
|
|
@@ -2079,7 +2157,8 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
|
2079
2157
|
if (!ds) return;
|
|
2080
2158
|
const { cache, entryPoint } = ds;
|
|
2081
2159
|
for (const loc of locations) {
|
|
2082
|
-
const
|
|
2160
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2161
|
+
const classes = split.classes;
|
|
2083
2162
|
const canonicals = Array.from({ length: classes.length });
|
|
2084
2163
|
const arbitraryIdx = [];
|
|
2085
2164
|
const arbitrary = [];
|
|
@@ -2099,7 +2178,7 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
|
2099
2178
|
if (canonical === cls) continue;
|
|
2100
2179
|
if (firstNonCanonical) {
|
|
2101
2180
|
firstNonCanonical = false;
|
|
2102
|
-
const fixedValue =
|
|
2181
|
+
const fixedValue = rebuildClassString(split, canonicals);
|
|
2103
2182
|
context.report({
|
|
2104
2183
|
node: loc.node,
|
|
2105
2184
|
messageId: "nonCanonical",
|
|
@@ -2112,7 +2191,7 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
|
2112
2191
|
}
|
|
2113
2192
|
});
|
|
2114
2193
|
} else {
|
|
2115
|
-
const fixedValue =
|
|
2194
|
+
const fixedValue = rebuildClassString(split, canonicals);
|
|
2116
2195
|
context.report({
|
|
2117
2196
|
node: loc.node,
|
|
2118
2197
|
messageId: "nonCanonical",
|
|
@@ -2391,7 +2470,8 @@ const enforceSortOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
2391
2470
|
return result;
|
|
2392
2471
|
}
|
|
2393
2472
|
for (const loc of locations) {
|
|
2394
|
-
const
|
|
2473
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2474
|
+
const classes = split.classes;
|
|
2395
2475
|
if (classes.length < 2) continue;
|
|
2396
2476
|
const sortedNames = mode === "strict" ? sortStrict(classes) : sortDefault(classes);
|
|
2397
2477
|
if (classes.every((name, i) => name === sortedNames[i])) continue;
|
|
@@ -2399,7 +2479,7 @@ const enforceSortOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
2399
2479
|
node: loc.node,
|
|
2400
2480
|
messageId: "unsorted",
|
|
2401
2481
|
fix(fixer) {
|
|
2402
|
-
return fixer.replaceTextRange(loc.range, preserveSpaces(loc,
|
|
2482
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, rebuildClassString(split, sortedNames)));
|
|
2403
2483
|
}
|
|
2404
2484
|
});
|
|
2405
2485
|
}
|
|
@@ -2485,7 +2565,8 @@ const enforceShorthand = (0, _oxlint_plugins.defineRule)({
|
|
|
2485
2565
|
createOnce(context) {
|
|
2486
2566
|
function check(locations) {
|
|
2487
2567
|
for (const loc of locations) {
|
|
2488
|
-
const
|
|
2568
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2569
|
+
const classes = split.classes;
|
|
2489
2570
|
if (classes.length < 2) continue;
|
|
2490
2571
|
const classSet = new Set(classes);
|
|
2491
2572
|
const values = /* @__PURE__ */ new Set();
|
|
@@ -2514,7 +2595,7 @@ const enforceShorthand = (0, _oxlint_plugins.defineRule)({
|
|
|
2514
2595
|
replacement: `${importantStart}${rule.replacement}${importantEnd}`
|
|
2515
2596
|
},
|
|
2516
2597
|
fix(fixer) {
|
|
2517
|
-
return fixer.replaceTextRange(loc.range, preserveSpaces(loc,
|
|
2598
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, rebuildClassString(split, remaining)));
|
|
2518
2599
|
}
|
|
2519
2600
|
});
|
|
2520
2601
|
}
|
|
@@ -2572,7 +2653,8 @@ const enforceLogical = (0, _oxlint_plugins.defineRule)({
|
|
|
2572
2653
|
}
|
|
2573
2654
|
function check(locations) {
|
|
2574
2655
|
for (const loc of locations) {
|
|
2575
|
-
const
|
|
2656
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2657
|
+
const classes = split.classes;
|
|
2576
2658
|
const offending = [];
|
|
2577
2659
|
for (const cls of classes) {
|
|
2578
2660
|
const converted = convertClass(cls);
|
|
@@ -2583,7 +2665,7 @@ const enforceLogical = (0, _oxlint_plugins.defineRule)({
|
|
|
2583
2665
|
}
|
|
2584
2666
|
if (offending.length === 0) continue;
|
|
2585
2667
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
2586
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
2668
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
2587
2669
|
for (let i = 0; i < offending.length; i++) {
|
|
2588
2670
|
const { cls, replacement } = offending[i];
|
|
2589
2671
|
if (i === 0) context.report({
|
|
@@ -2651,7 +2733,8 @@ const enforcePhysical = (0, _oxlint_plugins.defineRule)({
|
|
|
2651
2733
|
}
|
|
2652
2734
|
function check(locations) {
|
|
2653
2735
|
for (const loc of locations) {
|
|
2654
|
-
const
|
|
2736
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2737
|
+
const classes = split.classes;
|
|
2655
2738
|
const offending = [];
|
|
2656
2739
|
for (const cls of classes) {
|
|
2657
2740
|
const converted = convertClass(cls);
|
|
@@ -2662,7 +2745,7 @@ const enforcePhysical = (0, _oxlint_plugins.defineRule)({
|
|
|
2662
2745
|
}
|
|
2663
2746
|
if (offending.length === 0) continue;
|
|
2664
2747
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
2665
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
2748
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
2666
2749
|
for (let i = 0; i < offending.length; i++) {
|
|
2667
2750
|
const { cls, replacement } = offending[i];
|
|
2668
2751
|
if (i === 0) context.report({
|
|
@@ -2905,7 +2988,8 @@ const enforceConsistentImportantPosition = (0, _oxlint_plugins.defineRule)({
|
|
|
2905
2988
|
function check(locations) {
|
|
2906
2989
|
const position = getPosition();
|
|
2907
2990
|
for (const loc of locations) {
|
|
2908
|
-
const
|
|
2991
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2992
|
+
const classes = split.classes;
|
|
2909
2993
|
const offending = [];
|
|
2910
2994
|
for (const cls of classes) {
|
|
2911
2995
|
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
@@ -2917,7 +3001,7 @@ const enforceConsistentImportantPosition = (0, _oxlint_plugins.defineRule)({
|
|
|
2917
3001
|
}
|
|
2918
3002
|
if (offending.length === 0) continue;
|
|
2919
3003
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
2920
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
3004
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
2921
3005
|
for (let i = 0; i < offending.length; i++) {
|
|
2922
3006
|
const { cls, replacement } = offending[i];
|
|
2923
3007
|
if (i === 0) context.report({
|
|
@@ -2991,7 +3075,8 @@ const enforceNegativeArbitraryValues = (0, _oxlint_plugins.defineRule)({
|
|
|
2991
3075
|
createOnce(context) {
|
|
2992
3076
|
function check(locations) {
|
|
2993
3077
|
for (const loc of locations) {
|
|
2994
|
-
const
|
|
3078
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
3079
|
+
const classes = split.classes;
|
|
2995
3080
|
const offending = [];
|
|
2996
3081
|
for (const cls of classes) {
|
|
2997
3082
|
const fixed = fixClass(cls);
|
|
@@ -3002,7 +3087,7 @@ const enforceNegativeArbitraryValues = (0, _oxlint_plugins.defineRule)({
|
|
|
3002
3087
|
}
|
|
3003
3088
|
if (offending.length === 0) continue;
|
|
3004
3089
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
3005
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
3090
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
3006
3091
|
for (let i = 0; i < offending.length; i++) {
|
|
3007
3092
|
const { cls, replacement } = offending[i];
|
|
3008
3093
|
if (i === 0) context.report({
|
|
@@ -3096,7 +3181,8 @@ const enforceConsistentVariableSyntax = (0, _oxlint_plugins.defineRule)({
|
|
|
3096
3181
|
function check(locations) {
|
|
3097
3182
|
const syntax = getSyntax();
|
|
3098
3183
|
for (const loc of locations) {
|
|
3099
|
-
const
|
|
3184
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
3185
|
+
const classes = split.classes;
|
|
3100
3186
|
const offending = [];
|
|
3101
3187
|
for (const cls of classes) {
|
|
3102
3188
|
const converted = convertClass(cls, syntax);
|
|
@@ -3107,7 +3193,7 @@ const enforceConsistentVariableSyntax = (0, _oxlint_plugins.defineRule)({
|
|
|
3107
3193
|
}
|
|
3108
3194
|
if (offending.length === 0) continue;
|
|
3109
3195
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
3110
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
3196
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
3111
3197
|
const messageId = syntax === "shorthand" ? "useShorthand" : "useExplicit";
|
|
3112
3198
|
for (let i = 0; i < offending.length; i++) {
|
|
3113
3199
|
const { cls, replacement } = offending[i];
|
|
@@ -3568,7 +3654,8 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
3568
3654
|
}
|
|
3569
3655
|
function check(locations) {
|
|
3570
3656
|
for (const loc of locations) {
|
|
3571
|
-
const
|
|
3657
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
3658
|
+
const classes = split.classes;
|
|
3572
3659
|
const offending = [];
|
|
3573
3660
|
for (const cls of classes) {
|
|
3574
3661
|
const fixed = reorderClass(cls);
|
|
@@ -3579,7 +3666,7 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
3579
3666
|
}
|
|
3580
3667
|
if (offending.length === 0) continue;
|
|
3581
3668
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
3582
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
3669
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
3583
3670
|
for (let i = 0; i < offending.length; i++) {
|
|
3584
3671
|
const { cls, replacement } = offending[i];
|
|
3585
3672
|
if (i === 0) context.report({
|
|
@@ -3720,7 +3807,8 @@ const noUnnecessaryArbitraryValue = (0, _oxlint_plugins.defineRule)({
|
|
|
3720
3807
|
if (!ds) return;
|
|
3721
3808
|
const { cache } = ds;
|
|
3722
3809
|
for (const loc of locations) {
|
|
3723
|
-
const
|
|
3810
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
3811
|
+
const classes = split.classes;
|
|
3724
3812
|
const offending = [];
|
|
3725
3813
|
for (const cls of classes) {
|
|
3726
3814
|
if (!hasArbitraryValue(cls)) continue;
|
|
@@ -3737,7 +3825,7 @@ const noUnnecessaryArbitraryValue = (0, _oxlint_plugins.defineRule)({
|
|
|
3737
3825
|
}
|
|
3738
3826
|
if (offending.length === 0) continue;
|
|
3739
3827
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
3740
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
3828
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
3741
3829
|
for (let i = 0; i < offending.length; i++) {
|
|
3742
3830
|
const { cls, replacement } = offending[i];
|
|
3743
3831
|
if (i === 0) context.report({
|
|
@@ -3776,6 +3864,116 @@ const noUnnecessaryArbitraryValue = (0, _oxlint_plugins.defineRule)({
|
|
|
3776
3864
|
}
|
|
3777
3865
|
});
|
|
3778
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
|
|
3779
3977
|
//#region src/index.ts
|
|
3780
3978
|
const plugin = (0, _oxlint_plugins.definePlugin)({
|
|
3781
3979
|
meta: { name: "tailwindcss" },
|
|
@@ -3801,7 +3999,8 @@ const plugin = (0, _oxlint_plugins.definePlugin)({
|
|
|
3801
3999
|
"no-contradicting-variants": noContradictingVariants,
|
|
3802
4000
|
"consistent-variant-order": consistentVariantOrder,
|
|
3803
4001
|
"enforce-consistent-line-wrapping": enforceConsistentLineWrapping,
|
|
3804
|
-
"no-unnecessary-arbitrary-value": noUnnecessaryArbitraryValue
|
|
4002
|
+
"no-unnecessary-arbitrary-value": noUnnecessaryArbitraryValue,
|
|
4003
|
+
"prefer-theme-tokens": preferThemeTokens
|
|
3805
4004
|
}
|
|
3806
4005
|
});
|
|
3807
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"}
|