oxlint-tailwindcss 0.6.3 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -5
- package/dist/index.cjs +273 -33
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +359 -116
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -7
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:
|
|
@@ -824,7 +842,7 @@ The class parser correctly handles:
|
|
|
824
842
|
|
|
825
843
|
## Known limitations
|
|
826
844
|
|
|
827
|
-
- **`enforce-canonical`**:
|
|
845
|
+
- **`enforce-canonical`**: Named classes are canonicalized via the precomputed map (covers everything in `getClassList()` plus a curated list of legacy v3 spellings like `break-words`, `flex-grow`, `start-N`, `bg-gradient-to-*`). Arbitrary/CSS-var forms (`p-[2px]`, `bg-(--c)`) are canonicalized dynamically via the worker. Some valid v4 classes that don't appear in `getClassList()` and have no canonical rewrite (e.g. `border-1` is valid as a dynamic numeric value but isn't enumerated) are left untouched.
|
|
828
846
|
- **`no-conflicting-classes`**: Uses exact CSS property name matching. Shorthand vs longhand conflicts (e.g., `p-4` vs `px-2` where `padding` conflicts with `padding-left`) are not detected.
|
|
829
847
|
- **`no-dark-without-light`**: Groups by utility prefix heuristic. May not perfectly match all multi-part utility prefixes.
|
|
830
848
|
- **`no-unnecessary-arbitrary-value`**: Only detects equivalences for classes with a single CSS property. Multi-property utilities may have arbitrary forms that aren't detected.
|
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
|
|
|
@@ -952,6 +1024,47 @@ async function main() {
|
|
|
952
1024
|
}
|
|
953
1025
|
}
|
|
954
1026
|
|
|
1027
|
+
// Legacy v3 classes that produce valid CSS in v4 but are not enumerated by
|
|
1028
|
+
// getClassList(). Tailwind's canonicalizeCandidates() still rewrites them to
|
|
1029
|
+
// their v4 equivalent, so we feed them in explicitly. Without this pass,
|
|
1030
|
+
// classes like \`break-words\` would be invisible to enforce-canonical
|
|
1031
|
+
// (issue #16).
|
|
1032
|
+
// - Fixed renames mirror the internal v3->v4 map in tailwindcss/canonicalize.
|
|
1033
|
+
// - Pattern renames (start-* -> inset-s-*, end-* -> inset-e-*) are derived
|
|
1034
|
+
// from the inset-{s,e}-* utilities present in validClasses so we cover
|
|
1035
|
+
// every numeric/named value the design system exposes.
|
|
1036
|
+
const legacyCandidates = [
|
|
1037
|
+
'order-none',
|
|
1038
|
+
'break-words',
|
|
1039
|
+
'overflow-ellipsis',
|
|
1040
|
+
'flex-grow', 'flex-grow-0', 'flex-grow-1',
|
|
1041
|
+
'flex-shrink', 'flex-shrink-0', 'flex-shrink-1',
|
|
1042
|
+
'decoration-clone', 'decoration-slice',
|
|
1043
|
+
'bg-gradient-to-t', 'bg-gradient-to-tr', 'bg-gradient-to-r', 'bg-gradient-to-br',
|
|
1044
|
+
'bg-gradient-to-b', 'bg-gradient-to-bl', 'bg-gradient-to-l', 'bg-gradient-to-tl',
|
|
1045
|
+
];
|
|
1046
|
+
for (const cls of validClasses) {
|
|
1047
|
+
if (cls.startsWith('inset-s-')) legacyCandidates.push('start-' + cls.slice(8));
|
|
1048
|
+
else if (cls.startsWith('-inset-s-')) legacyCandidates.push('-start-' + cls.slice(9));
|
|
1049
|
+
else if (cls.startsWith('inset-e-')) legacyCandidates.push('end-' + cls.slice(8));
|
|
1050
|
+
else if (cls.startsWith('-inset-e-')) legacyCandidates.push('-end-' + cls.slice(9));
|
|
1051
|
+
}
|
|
1052
|
+
const legacyToProcess = legacyCandidates.filter(cls => !validSet.has(cls));
|
|
1053
|
+
if (legacyToProcess.length > 0) {
|
|
1054
|
+
const legacyCssResults = ds.candidatesToCss(legacyToProcess);
|
|
1055
|
+
for (let i = 0; i < legacyToProcess.length; i++) {
|
|
1056
|
+
if (legacyCssResults[i] == null) continue;
|
|
1057
|
+
const cls = legacyToProcess[i];
|
|
1058
|
+
const result = ds.canonicalizeCandidates([cls]);
|
|
1059
|
+
if (result[0] && result[0] !== cls) {
|
|
1060
|
+
canonical[cls] = result[0];
|
|
1061
|
+
}
|
|
1062
|
+
// Mark as valid so no-unknown-classes doesn't flag legacy spellings.
|
|
1063
|
+
validClasses.push(cls);
|
|
1064
|
+
validSet.add(cls);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
955
1068
|
// Sort order — include extra candidates so bare utilities (rounded, blur, etc.) get order
|
|
956
1069
|
const allForOrder = [...classNames];
|
|
957
1070
|
for (const cls of validClasses) {
|
|
@@ -1119,7 +1232,7 @@ async function main() {
|
|
|
1119
1232
|
main().catch(e => { process.stderr.write(e.message); process.exit(1); });
|
|
1120
1233
|
`;
|
|
1121
1234
|
const CACHE_DIR = (0, node_path.join)((0, node_os.tmpdir)(), "oxlint-tailwindcss");
|
|
1122
|
-
const CACHE_VERSION =
|
|
1235
|
+
const CACHE_VERSION = 13;
|
|
1123
1236
|
/**
|
|
1124
1237
|
* Two-level disk cache for monorepo deduplication:
|
|
1125
1238
|
*
|
|
@@ -1171,20 +1284,24 @@ function loadDesignSystemSync(cssPath, timeout) {
|
|
|
1171
1284
|
} catch {}
|
|
1172
1285
|
return cached;
|
|
1173
1286
|
}
|
|
1287
|
+
const tailwindNodePath = require.resolve("@tailwindcss/node");
|
|
1174
1288
|
const stdout = (0, node_child_process.execFileSync)(process.execPath, ["-e", PRECOMPUTE_SCRIPT], {
|
|
1175
1289
|
encoding: "utf-8",
|
|
1176
1290
|
timeout: timeout ?? 3e4,
|
|
1177
1291
|
maxBuffer: 50 * 1024 * 1024,
|
|
1178
1292
|
env: {
|
|
1179
1293
|
...process.env,
|
|
1180
|
-
TAILWIND_CSS_PATH: resolvedPath
|
|
1294
|
+
TAILWIND_CSS_PATH: resolvedPath,
|
|
1295
|
+
TAILWIND_NODE_PATH: tailwindNodePath
|
|
1181
1296
|
},
|
|
1182
1297
|
cwd: (0, node_path.dirname)(resolvedPath)
|
|
1183
1298
|
});
|
|
1184
1299
|
writeCacheFiles(contentCachePath, mtimeIndexPath, contentHash, stdout);
|
|
1185
1300
|
return JSON.parse(stdout);
|
|
1186
1301
|
} catch (error) {
|
|
1187
|
-
|
|
1302
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
1303
|
+
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.`);
|
|
1304
|
+
else console.error(`[oxlint-tailwindcss] Failed to load design system from "${resolvedPath}":`, msg);
|
|
1188
1305
|
return null;
|
|
1189
1306
|
}
|
|
1190
1307
|
}
|
|
@@ -1556,7 +1673,8 @@ const noDeprecatedClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1556
1673
|
function check(locations) {
|
|
1557
1674
|
const dsResult = getDS();
|
|
1558
1675
|
for (const loc of locations) {
|
|
1559
|
-
const
|
|
1676
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
1677
|
+
const classes = split.classes;
|
|
1560
1678
|
const offending = [];
|
|
1561
1679
|
for (const cls of classes) {
|
|
1562
1680
|
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
@@ -1577,7 +1695,7 @@ const noDeprecatedClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1577
1695
|
}
|
|
1578
1696
|
if (offending.length === 0) continue;
|
|
1579
1697
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
1580
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
1698
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
1581
1699
|
for (let i = 0; i < offending.length; i++) {
|
|
1582
1700
|
const { cls, replacement } = offending[i];
|
|
1583
1701
|
if (i === 0) context.report({
|
|
@@ -1678,7 +1796,8 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1678
1796
|
if (!ds) return;
|
|
1679
1797
|
const { cache } = ds;
|
|
1680
1798
|
for (const loc of locations) {
|
|
1681
|
-
const
|
|
1799
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
1800
|
+
const classes = split.classes;
|
|
1682
1801
|
for (const cls of classes) {
|
|
1683
1802
|
if (shouldIgnore(cls)) continue;
|
|
1684
1803
|
const stripped = stripModifiers(cls);
|
|
@@ -1686,7 +1805,7 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1686
1805
|
if (DEPRECATED_MAP[stripped]) continue;
|
|
1687
1806
|
const suggestion = findBestSuggestion(stripped, cache.validClasses);
|
|
1688
1807
|
if (suggestion) {
|
|
1689
|
-
const fixedValue = classes.map((c) => c === cls ? suggestion : c)
|
|
1808
|
+
const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? suggestion : c));
|
|
1690
1809
|
context.report({
|
|
1691
1810
|
node: loc.node,
|
|
1692
1811
|
messageId: "unknownWithSuggestion",
|
|
@@ -2079,7 +2198,8 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
|
2079
2198
|
if (!ds) return;
|
|
2080
2199
|
const { cache, entryPoint } = ds;
|
|
2081
2200
|
for (const loc of locations) {
|
|
2082
|
-
const
|
|
2201
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2202
|
+
const classes = split.classes;
|
|
2083
2203
|
const canonicals = Array.from({ length: classes.length });
|
|
2084
2204
|
const arbitraryIdx = [];
|
|
2085
2205
|
const arbitrary = [];
|
|
@@ -2099,7 +2219,7 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
|
2099
2219
|
if (canonical === cls) continue;
|
|
2100
2220
|
if (firstNonCanonical) {
|
|
2101
2221
|
firstNonCanonical = false;
|
|
2102
|
-
const fixedValue =
|
|
2222
|
+
const fixedValue = rebuildClassString(split, canonicals);
|
|
2103
2223
|
context.report({
|
|
2104
2224
|
node: loc.node,
|
|
2105
2225
|
messageId: "nonCanonical",
|
|
@@ -2112,7 +2232,7 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
|
2112
2232
|
}
|
|
2113
2233
|
});
|
|
2114
2234
|
} else {
|
|
2115
|
-
const fixedValue =
|
|
2235
|
+
const fixedValue = rebuildClassString(split, canonicals);
|
|
2116
2236
|
context.report({
|
|
2117
2237
|
node: loc.node,
|
|
2118
2238
|
messageId: "nonCanonical",
|
|
@@ -2391,7 +2511,8 @@ const enforceSortOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
2391
2511
|
return result;
|
|
2392
2512
|
}
|
|
2393
2513
|
for (const loc of locations) {
|
|
2394
|
-
const
|
|
2514
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2515
|
+
const classes = split.classes;
|
|
2395
2516
|
if (classes.length < 2) continue;
|
|
2396
2517
|
const sortedNames = mode === "strict" ? sortStrict(classes) : sortDefault(classes);
|
|
2397
2518
|
if (classes.every((name, i) => name === sortedNames[i])) continue;
|
|
@@ -2399,7 +2520,7 @@ const enforceSortOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
2399
2520
|
node: loc.node,
|
|
2400
2521
|
messageId: "unsorted",
|
|
2401
2522
|
fix(fixer) {
|
|
2402
|
-
return fixer.replaceTextRange(loc.range, preserveSpaces(loc,
|
|
2523
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, rebuildClassString(split, sortedNames)));
|
|
2403
2524
|
}
|
|
2404
2525
|
});
|
|
2405
2526
|
}
|
|
@@ -2485,7 +2606,8 @@ const enforceShorthand = (0, _oxlint_plugins.defineRule)({
|
|
|
2485
2606
|
createOnce(context) {
|
|
2486
2607
|
function check(locations) {
|
|
2487
2608
|
for (const loc of locations) {
|
|
2488
|
-
const
|
|
2609
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2610
|
+
const classes = split.classes;
|
|
2489
2611
|
if (classes.length < 2) continue;
|
|
2490
2612
|
const classSet = new Set(classes);
|
|
2491
2613
|
const values = /* @__PURE__ */ new Set();
|
|
@@ -2514,7 +2636,7 @@ const enforceShorthand = (0, _oxlint_plugins.defineRule)({
|
|
|
2514
2636
|
replacement: `${importantStart}${rule.replacement}${importantEnd}`
|
|
2515
2637
|
},
|
|
2516
2638
|
fix(fixer) {
|
|
2517
|
-
return fixer.replaceTextRange(loc.range, preserveSpaces(loc,
|
|
2639
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, rebuildClassString(split, remaining)));
|
|
2518
2640
|
}
|
|
2519
2641
|
});
|
|
2520
2642
|
}
|
|
@@ -2572,7 +2694,8 @@ const enforceLogical = (0, _oxlint_plugins.defineRule)({
|
|
|
2572
2694
|
}
|
|
2573
2695
|
function check(locations) {
|
|
2574
2696
|
for (const loc of locations) {
|
|
2575
|
-
const
|
|
2697
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2698
|
+
const classes = split.classes;
|
|
2576
2699
|
const offending = [];
|
|
2577
2700
|
for (const cls of classes) {
|
|
2578
2701
|
const converted = convertClass(cls);
|
|
@@ -2583,7 +2706,7 @@ const enforceLogical = (0, _oxlint_plugins.defineRule)({
|
|
|
2583
2706
|
}
|
|
2584
2707
|
if (offending.length === 0) continue;
|
|
2585
2708
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
2586
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
2709
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
2587
2710
|
for (let i = 0; i < offending.length; i++) {
|
|
2588
2711
|
const { cls, replacement } = offending[i];
|
|
2589
2712
|
if (i === 0) context.report({
|
|
@@ -2651,7 +2774,8 @@ const enforcePhysical = (0, _oxlint_plugins.defineRule)({
|
|
|
2651
2774
|
}
|
|
2652
2775
|
function check(locations) {
|
|
2653
2776
|
for (const loc of locations) {
|
|
2654
|
-
const
|
|
2777
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
2778
|
+
const classes = split.classes;
|
|
2655
2779
|
const offending = [];
|
|
2656
2780
|
for (const cls of classes) {
|
|
2657
2781
|
const converted = convertClass(cls);
|
|
@@ -2662,7 +2786,7 @@ const enforcePhysical = (0, _oxlint_plugins.defineRule)({
|
|
|
2662
2786
|
}
|
|
2663
2787
|
if (offending.length === 0) continue;
|
|
2664
2788
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
2665
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
2789
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
2666
2790
|
for (let i = 0; i < offending.length; i++) {
|
|
2667
2791
|
const { cls, replacement } = offending[i];
|
|
2668
2792
|
if (i === 0) context.report({
|
|
@@ -2905,7 +3029,8 @@ const enforceConsistentImportantPosition = (0, _oxlint_plugins.defineRule)({
|
|
|
2905
3029
|
function check(locations) {
|
|
2906
3030
|
const position = getPosition();
|
|
2907
3031
|
for (const loc of locations) {
|
|
2908
|
-
const
|
|
3032
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
3033
|
+
const classes = split.classes;
|
|
2909
3034
|
const offending = [];
|
|
2910
3035
|
for (const cls of classes) {
|
|
2911
3036
|
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
@@ -2917,7 +3042,7 @@ const enforceConsistentImportantPosition = (0, _oxlint_plugins.defineRule)({
|
|
|
2917
3042
|
}
|
|
2918
3043
|
if (offending.length === 0) continue;
|
|
2919
3044
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
2920
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
3045
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
2921
3046
|
for (let i = 0; i < offending.length; i++) {
|
|
2922
3047
|
const { cls, replacement } = offending[i];
|
|
2923
3048
|
if (i === 0) context.report({
|
|
@@ -2991,7 +3116,8 @@ const enforceNegativeArbitraryValues = (0, _oxlint_plugins.defineRule)({
|
|
|
2991
3116
|
createOnce(context) {
|
|
2992
3117
|
function check(locations) {
|
|
2993
3118
|
for (const loc of locations) {
|
|
2994
|
-
const
|
|
3119
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
3120
|
+
const classes = split.classes;
|
|
2995
3121
|
const offending = [];
|
|
2996
3122
|
for (const cls of classes) {
|
|
2997
3123
|
const fixed = fixClass(cls);
|
|
@@ -3002,7 +3128,7 @@ const enforceNegativeArbitraryValues = (0, _oxlint_plugins.defineRule)({
|
|
|
3002
3128
|
}
|
|
3003
3129
|
if (offending.length === 0) continue;
|
|
3004
3130
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
3005
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
3131
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
3006
3132
|
for (let i = 0; i < offending.length; i++) {
|
|
3007
3133
|
const { cls, replacement } = offending[i];
|
|
3008
3134
|
if (i === 0) context.report({
|
|
@@ -3096,7 +3222,8 @@ const enforceConsistentVariableSyntax = (0, _oxlint_plugins.defineRule)({
|
|
|
3096
3222
|
function check(locations) {
|
|
3097
3223
|
const syntax = getSyntax();
|
|
3098
3224
|
for (const loc of locations) {
|
|
3099
|
-
const
|
|
3225
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
3226
|
+
const classes = split.classes;
|
|
3100
3227
|
const offending = [];
|
|
3101
3228
|
for (const cls of classes) {
|
|
3102
3229
|
const converted = convertClass(cls, syntax);
|
|
@@ -3107,7 +3234,7 @@ const enforceConsistentVariableSyntax = (0, _oxlint_plugins.defineRule)({
|
|
|
3107
3234
|
}
|
|
3108
3235
|
if (offending.length === 0) continue;
|
|
3109
3236
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
3110
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
3237
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
3111
3238
|
const messageId = syntax === "shorthand" ? "useShorthand" : "useExplicit";
|
|
3112
3239
|
for (let i = 0; i < offending.length; i++) {
|
|
3113
3240
|
const { cls, replacement } = offending[i];
|
|
@@ -3568,7 +3695,8 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
3568
3695
|
}
|
|
3569
3696
|
function check(locations) {
|
|
3570
3697
|
for (const loc of locations) {
|
|
3571
|
-
const
|
|
3698
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
3699
|
+
const classes = split.classes;
|
|
3572
3700
|
const offending = [];
|
|
3573
3701
|
for (const cls of classes) {
|
|
3574
3702
|
const fixed = reorderClass(cls);
|
|
@@ -3579,7 +3707,7 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
3579
3707
|
}
|
|
3580
3708
|
if (offending.length === 0) continue;
|
|
3581
3709
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
3582
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
3710
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
3583
3711
|
for (let i = 0; i < offending.length; i++) {
|
|
3584
3712
|
const { cls, replacement } = offending[i];
|
|
3585
3713
|
if (i === 0) context.report({
|
|
@@ -3720,7 +3848,8 @@ const noUnnecessaryArbitraryValue = (0, _oxlint_plugins.defineRule)({
|
|
|
3720
3848
|
if (!ds) return;
|
|
3721
3849
|
const { cache } = ds;
|
|
3722
3850
|
for (const loc of locations) {
|
|
3723
|
-
const
|
|
3851
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
3852
|
+
const classes = split.classes;
|
|
3724
3853
|
const offending = [];
|
|
3725
3854
|
for (const cls of classes) {
|
|
3726
3855
|
if (!hasArbitraryValue(cls)) continue;
|
|
@@ -3737,7 +3866,7 @@ const noUnnecessaryArbitraryValue = (0, _oxlint_plugins.defineRule)({
|
|
|
3737
3866
|
}
|
|
3738
3867
|
if (offending.length === 0) continue;
|
|
3739
3868
|
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
3740
|
-
const fixedValue = classes.map((cls) => replacements.get(cls) ?? cls)
|
|
3869
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
3741
3870
|
for (let i = 0; i < offending.length; i++) {
|
|
3742
3871
|
const { cls, replacement } = offending[i];
|
|
3743
3872
|
if (i === 0) context.report({
|
|
@@ -3776,6 +3905,116 @@ const noUnnecessaryArbitraryValue = (0, _oxlint_plugins.defineRule)({
|
|
|
3776
3905
|
}
|
|
3777
3906
|
});
|
|
3778
3907
|
//#endregion
|
|
3908
|
+
//#region src/rules/prefer-theme-tokens.ts
|
|
3909
|
+
/**
|
|
3910
|
+
* Match `prefix-(--name)` or `prefix-(--name)/modifier`.
|
|
3911
|
+
* Captures: 1=prefix, 2=variable name, 3=optional `/modifier` (kept verbatim).
|
|
3912
|
+
*/
|
|
3913
|
+
const PAREN_VAR_RE = /^(.+?)-\(--([\w-]+)\)(\/[^/\s]+)?$/;
|
|
3914
|
+
/**
|
|
3915
|
+
* Match `prefix-[var(--name)]` or `prefix-[var(--name)]/modifier`.
|
|
3916
|
+
* Captures: 1=prefix, 2=variable name, 3=optional `/modifier`.
|
|
3917
|
+
*/
|
|
3918
|
+
const BRACKET_VAR_RE = /^(.+?)-\[var\(--([\w-]+)\)\](\/[^/\s]+)?$/;
|
|
3919
|
+
function detectRawVariable(utility) {
|
|
3920
|
+
const paren = PAREN_VAR_RE.exec(utility);
|
|
3921
|
+
if (paren) return {
|
|
3922
|
+
prefix: paren[1],
|
|
3923
|
+
varName: paren[2],
|
|
3924
|
+
modifier: paren[3] ?? ""
|
|
3925
|
+
};
|
|
3926
|
+
const bracket = BRACKET_VAR_RE.exec(utility);
|
|
3927
|
+
if (bracket) return {
|
|
3928
|
+
prefix: bracket[1],
|
|
3929
|
+
varName: bracket[2],
|
|
3930
|
+
modifier: bracket[3] ?? ""
|
|
3931
|
+
};
|
|
3932
|
+
return null;
|
|
3933
|
+
}
|
|
3934
|
+
const preferThemeTokens = (0, _oxlint_plugins.defineRule)({
|
|
3935
|
+
meta: {
|
|
3936
|
+
type: "suggestion",
|
|
3937
|
+
docs: { description: "Prefer named theme-token utilities over raw CSS variable references when a matching utility exists" },
|
|
3938
|
+
fixable: "code",
|
|
3939
|
+
schema: [{
|
|
3940
|
+
type: "object",
|
|
3941
|
+
properties: { entryPoint: { type: "string" } },
|
|
3942
|
+
additionalProperties: false
|
|
3943
|
+
}],
|
|
3944
|
+
hasSuggestions: true,
|
|
3945
|
+
messages: {
|
|
3946
|
+
preferNamed: "\"{{className}}\" can be written as \"{{replacement}}\". Use the named theme token.",
|
|
3947
|
+
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
|
|
3948
|
+
}
|
|
3949
|
+
},
|
|
3950
|
+
createOnce(context) {
|
|
3951
|
+
const getDS = createLazyLoader(context);
|
|
3952
|
+
function check(locations) {
|
|
3953
|
+
const ds = getDS();
|
|
3954
|
+
if (!ds) return;
|
|
3955
|
+
const { cache } = ds;
|
|
3956
|
+
for (const loc of locations) {
|
|
3957
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
3958
|
+
const classes = split.classes;
|
|
3959
|
+
const offending = [];
|
|
3960
|
+
for (const cls of classes) {
|
|
3961
|
+
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
3962
|
+
const hasImportantPrefix = utility.startsWith("!");
|
|
3963
|
+
const hasImportantSuffix = !hasImportantPrefix && utility.endsWith("!");
|
|
3964
|
+
const bareUtility = hasImportantPrefix ? utility.slice(1) : hasImportantSuffix ? utility.slice(0, -1) : utility;
|
|
3965
|
+
const match = detectRawVariable(bareUtility);
|
|
3966
|
+
if (!match) continue;
|
|
3967
|
+
const candidate = `${match.prefix}-${match.varName}${match.modifier}`;
|
|
3968
|
+
if (!cache.isValid(candidate)) continue;
|
|
3969
|
+
const namedEquivalent = cache.getNamedEquivalent(bareUtility);
|
|
3970
|
+
if (namedEquivalent && namedEquivalent === `${match.prefix}-${match.varName}`) continue;
|
|
3971
|
+
const replacement = variant + (hasImportantPrefix ? "!" : "") + candidate + (hasImportantSuffix ? "!" : "");
|
|
3972
|
+
offending.push({
|
|
3973
|
+
cls,
|
|
3974
|
+
replacement
|
|
3975
|
+
});
|
|
3976
|
+
}
|
|
3977
|
+
if (offending.length === 0) continue;
|
|
3978
|
+
const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
|
|
3979
|
+
const fixedValue = rebuildClassString(split, classes.map((cls) => replacements.get(cls) ?? cls));
|
|
3980
|
+
for (let i = 0; i < offending.length; i++) {
|
|
3981
|
+
const { cls, replacement } = offending[i];
|
|
3982
|
+
if (i === 0) context.report({
|
|
3983
|
+
node: loc.node,
|
|
3984
|
+
messageId: "preferNamed",
|
|
3985
|
+
data: {
|
|
3986
|
+
className: cls,
|
|
3987
|
+
replacement
|
|
3988
|
+
},
|
|
3989
|
+
fix(fixer) {
|
|
3990
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
3991
|
+
}
|
|
3992
|
+
});
|
|
3993
|
+
else context.report({
|
|
3994
|
+
node: loc.node,
|
|
3995
|
+
messageId: "preferNamed",
|
|
3996
|
+
data: {
|
|
3997
|
+
className: cls,
|
|
3998
|
+
replacement
|
|
3999
|
+
},
|
|
4000
|
+
suggest: [{
|
|
4001
|
+
messageId: "suggestReplace",
|
|
4002
|
+
data: {
|
|
4003
|
+
className: cls,
|
|
4004
|
+
replacement
|
|
4005
|
+
},
|
|
4006
|
+
fix(fixer) {
|
|
4007
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
4008
|
+
}
|
|
4009
|
+
}]
|
|
4010
|
+
});
|
|
4011
|
+
}
|
|
4012
|
+
}
|
|
4013
|
+
}
|
|
4014
|
+
return createExtractorVisitors(context, check);
|
|
4015
|
+
}
|
|
4016
|
+
});
|
|
4017
|
+
//#endregion
|
|
3779
4018
|
//#region src/index.ts
|
|
3780
4019
|
const plugin = (0, _oxlint_plugins.definePlugin)({
|
|
3781
4020
|
meta: { name: "tailwindcss" },
|
|
@@ -3801,7 +4040,8 @@ const plugin = (0, _oxlint_plugins.definePlugin)({
|
|
|
3801
4040
|
"no-contradicting-variants": noContradictingVariants,
|
|
3802
4041
|
"consistent-variant-order": consistentVariantOrder,
|
|
3803
4042
|
"enforce-consistent-line-wrapping": enforceConsistentLineWrapping,
|
|
3804
|
-
"no-unnecessary-arbitrary-value": noUnnecessaryArbitraryValue
|
|
4043
|
+
"no-unnecessary-arbitrary-value": noUnnecessaryArbitraryValue,
|
|
4044
|
+
"prefer-theme-tokens": preferThemeTokens
|
|
3805
4045
|
}
|
|
3806
4046
|
});
|
|
3807
4047
|
//#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"}
|