oxlint-tailwindcss 0.1.3 → 0.1.4
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 +42 -74
- package/dist/index.cjs +72 -24
- package/dist/index.mjs +72 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,16 +64,35 @@ The plugin auto-detects your Tailwind CSS entry point. No configuration needed i
|
|
|
64
64
|
The plugin searches for a CSS file containing a Tailwind import signal (`@import "tailwindcss"`, `@import 'tailwindcss'`, `@import tailwindcss`, `@tailwind base`) in these locations, walking upward from the linted file:
|
|
65
65
|
|
|
66
66
|
```
|
|
67
|
-
src/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
style.css styles/globals.css app/globals.css
|
|
71
|
-
assets/css/tailwind.css
|
|
67
|
+
src/{name}.css {name}.css app/{name}.css
|
|
68
|
+
styles/{name}.css style/{name}.css css/{name}.css
|
|
69
|
+
assets/{name}.css assets/css/{name}.css resources/css/{name}.css
|
|
72
70
|
```
|
|
73
71
|
|
|
72
|
+
Where `{name}` is one of: `app`, `globals`, `global`, `style`, `styles`, `index`, `main`, `tailwind`, `tailwindcss`.
|
|
73
|
+
|
|
74
74
|
The search is monorepo-aware — it stops at `package.json` boundaries so each package resolves its own Tailwind config.
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
If auto-detection doesn't find your CSS file, set `entryPoint` once in `settings`:
|
|
77
|
+
|
|
78
|
+
```jsonc
|
|
79
|
+
{
|
|
80
|
+
"jsPlugins": ["oxlint-tailwindcss"],
|
|
81
|
+
"settings": {
|
|
82
|
+
"tailwindcss": {
|
|
83
|
+
"entryPoint": "app/tailwind.css",
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
"rules": {
|
|
87
|
+
"tailwindcss/no-unknown-classes": "error",
|
|
88
|
+
// ...
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The design system is loaded once and shared across all rules.
|
|
94
|
+
|
|
95
|
+
You can also override per rule if needed:
|
|
77
96
|
|
|
78
97
|
```jsonc
|
|
79
98
|
{
|
|
@@ -83,6 +102,10 @@ To override auto-detection, pass `entryPoint` as an option:
|
|
|
83
102
|
}
|
|
84
103
|
```
|
|
85
104
|
|
|
105
|
+
Resolution order: rule option > `settings.tailwindcss.entryPoint` > auto-detect.
|
|
106
|
+
|
|
107
|
+
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.
|
|
108
|
+
|
|
86
109
|
## Supported patterns
|
|
87
110
|
|
|
88
111
|
The plugin extracts Tailwind classes from:
|
|
@@ -98,18 +121,10 @@ The plugin extracts Tailwind classes from:
|
|
|
98
121
|
// Ternaries
|
|
99
122
|
<div className={active ? "bg-blue-500" : "bg-gray-200"} />
|
|
100
123
|
|
|
101
|
-
// Utility functions
|
|
124
|
+
// Utility functions (cn, clsx, cx, cva, twMerge, twJoin, classnames, ctl, cc, clb, cnb, objstr)
|
|
102
125
|
cn("flex items-center", condition && "hidden")
|
|
103
126
|
clsx("flex", { "bg-red-500": isError })
|
|
104
127
|
twMerge("p-4", "p-2")
|
|
105
|
-
cx("flex", "items-center")
|
|
106
|
-
classnames("flex", "items-center")
|
|
107
|
-
ctl("flex items-center")
|
|
108
|
-
twJoin("flex", "items-center")
|
|
109
|
-
cc("flex", "items-center")
|
|
110
|
-
clb("flex", "items-center")
|
|
111
|
-
cnb("flex", "items-center")
|
|
112
|
-
objstr({ "flex": true, "items-center": true })
|
|
113
128
|
|
|
114
129
|
// cva() — full extraction: base, variants, compoundVariants
|
|
115
130
|
cva("flex items-center", {
|
|
@@ -164,7 +179,6 @@ Reports classes not recognized by Tailwind CSS. Includes typo suggestions.
|
|
|
164
179
|
|
|
165
180
|
| Option | Type | Description |
|
|
166
181
|
| ---------------- | ---------- | ------------------------------------- |
|
|
167
|
-
| `entryPoint` | `string` | Path to Tailwind CSS entry file |
|
|
168
182
|
| `allowlist` | `string[]` | Custom classes to allow |
|
|
169
183
|
| `ignorePrefixes` | `string[]` | Prefixes to ignore (e.g. `["data-"]`) |
|
|
170
184
|
|
|
@@ -204,12 +218,6 @@ Detects classes that set the same CSS property. Reports which property conflicts
|
|
|
204
218
|
|
|
205
219
|
> **Note:** Shorthand vs longhand conflicts (e.g., `p-4` vs `px-2`) are not currently detected. See [Known limitations](#known-limitations).
|
|
206
220
|
|
|
207
|
-
**Options:**
|
|
208
|
-
|
|
209
|
-
| Option | Type | Description |
|
|
210
|
-
| ------------ | -------- | ------------------------------- |
|
|
211
|
-
| `entryPoint` | `string` | Path to Tailwind CSS entry file |
|
|
212
|
-
|
|
213
221
|
**Requires design system.** No autofix.
|
|
214
222
|
|
|
215
223
|
---
|
|
@@ -294,21 +302,14 @@ Detects variant-prefixed classes that are redundant because the base class alrea
|
|
|
294
302
|
<div className="flex dark:flex" />
|
|
295
303
|
<div className="hidden hover:hidden" />
|
|
296
304
|
|
|
297
|
-
// ✅ OK — different values,
|
|
305
|
+
// ✅ OK — different values, both conditional, or different selector targets
|
|
298
306
|
<div className="text-white dark:text-black" />
|
|
299
|
-
<div className="bg-white hover:bg-blue-500" />
|
|
300
|
-
|
|
301
|
-
// ✅ OK — no base class, both are conditional
|
|
302
307
|
<div className="hover:flex dark:flex" />
|
|
303
|
-
|
|
304
|
-
// ✅ OK — pseudo-elements and child selectors target different elements
|
|
305
308
|
<div className="absolute after:absolute" />
|
|
306
309
|
<div className="shrink-0 [&>svg]:shrink-0" />
|
|
307
|
-
<div className="bg-transparent file:bg-transparent" />
|
|
308
|
-
<div className="flex *:data-[slot=value]:flex" />
|
|
309
310
|
```
|
|
310
311
|
|
|
311
|
-
Only
|
|
312
|
+
Only flags when the exact same utility exists both as base and with a conditional variant. Variants that change the selector target (pseudo-elements, child/descendant selectors, arbitrary selectors) are not flagged.
|
|
312
313
|
|
|
313
314
|
**No options.** **No autofix.**
|
|
314
315
|
|
|
@@ -327,12 +328,6 @@ Suggests the canonical form of a class when a shorter equivalent exists. Only kn
|
|
|
327
328
|
"-p-0" → "p-0"
|
|
328
329
|
```
|
|
329
330
|
|
|
330
|
-
**Options:**
|
|
331
|
-
|
|
332
|
-
| Option | Type | Description |
|
|
333
|
-
| ------------ | -------- | ------------------------------- |
|
|
334
|
-
| `entryPoint` | `string` | Path to Tailwind CSS entry file |
|
|
335
|
-
|
|
336
331
|
**Requires design system.** **Autofix:** Replaces with canonical form.
|
|
337
332
|
|
|
338
333
|
---
|
|
@@ -361,10 +356,9 @@ In `strict` mode, classes are grouped by variant prefix, sorted within each grou
|
|
|
361
356
|
|
|
362
357
|
**Options:**
|
|
363
358
|
|
|
364
|
-
| Option
|
|
365
|
-
|
|
|
366
|
-
| `
|
|
367
|
-
| `mode` | `"default"` \| `"strict"` | `"default"` | Sort mode |
|
|
359
|
+
| Option | Type | Default | Description |
|
|
360
|
+
| ------ | ------------------------- | ----------- | ----------- |
|
|
361
|
+
| `mode` | `"default"` \| `"strict"` | `"default"` | Sort mode |
|
|
368
362
|
|
|
369
363
|
**Requires design system.** **Autofix:** Reorders classes.
|
|
370
364
|
|
|
@@ -404,22 +398,7 @@ Converts physical properties to logical ones for LTR/RTL support.
|
|
|
404
398
|
"right-0" → "end-0"
|
|
405
399
|
```
|
|
406
400
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
| Physical | Logical |
|
|
410
|
-
| --------------------------- | --------------------------- |
|
|
411
|
-
| `ml` | `ms` |
|
|
412
|
-
| `mr` | `me` |
|
|
413
|
-
| `pl` | `ps` |
|
|
414
|
-
| `pr` | `pe` |
|
|
415
|
-
| `left` | `start` |
|
|
416
|
-
| `right` | `end` |
|
|
417
|
-
| `border-l` / `border-r` | `border-s` / `border-e` |
|
|
418
|
-
| `rounded-l` / `rounded-r` | `rounded-s` / `rounded-e` |
|
|
419
|
-
| `rounded-tl` / `rounded-tr` | `rounded-ss` / `rounded-se` |
|
|
420
|
-
| `rounded-bl` / `rounded-br` | `rounded-es` / `rounded-ee` |
|
|
421
|
-
| `scroll-ml` / `scroll-mr` | `scroll-ms` / `scroll-me` |
|
|
422
|
-
| `scroll-pl` / `scroll-pr` | `scroll-ps` / `scroll-pe` |
|
|
401
|
+
Also converts `border-l/r`, `rounded-l/r/tl/tr/bl/br`, and `scroll-ml/mr/pl/pr` to their logical equivalents.
|
|
423
402
|
|
|
424
403
|
**Autofix:** Replaces with logical equivalent.
|
|
425
404
|
|
|
@@ -506,18 +485,13 @@ Does NOT convert complex expressions — only simple `var(--name)` wrappers:
|
|
|
506
485
|
|
|
507
486
|
Enforces a consistent order for variant prefixes.
|
|
508
487
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
A user-specified `order` option always takes the highest priority, overriding both the design system and the static default.
|
|
512
|
-
|
|
513
|
-
Only checks classes with 2+ variants. Single-variant classes are always valid.
|
|
488
|
+
Uses the design system's variant order when available, falls back to a sensible static default. Only checks classes with 2+ variants.
|
|
514
489
|
|
|
515
490
|
**Options:**
|
|
516
491
|
|
|
517
|
-
| Option
|
|
518
|
-
|
|
|
519
|
-
| `
|
|
520
|
-
| `order` | `string[]` | (DS order or builtin order) | Custom variant priority list |
|
|
492
|
+
| Option | Type | Default | Description |
|
|
493
|
+
| ------- | ---------- | --------------------------- | ---------------------------- |
|
|
494
|
+
| `order` | `string[]` | (DS order or builtin order) | Custom variant priority list |
|
|
521
495
|
|
|
522
496
|
**Optionally uses design system.** **Autofix:** Reorders variants.
|
|
523
497
|
|
|
@@ -570,7 +544,7 @@ Warns when a class string exceeds the configured print width or classes-per-line
|
|
|
570
544
|
| `printWidth` | `number` | `80` | Max class string length |
|
|
571
545
|
| `classesPerLine` | `number` | | Max classes per line |
|
|
572
546
|
|
|
573
|
-
**
|
|
547
|
+
**Autofix:** Only for `classesPerLine` with template literals.
|
|
574
548
|
|
|
575
549
|
---
|
|
576
550
|
|
|
@@ -639,7 +613,7 @@ Flags hardcoded color values in arbitrary brackets. Encourages use of design tok
|
|
|
639
613
|
<div className="tracking-[0.5em]" />
|
|
640
614
|
```
|
|
641
615
|
|
|
642
|
-
Detects hex, rgb/rgba, hsl/hsla, oklch, oklab,
|
|
616
|
+
Detects hex, rgb/rgba, hsl/hsla, oklch, oklab, and other color function values inside `[...]` on color-related utility prefixes (`bg-`, `text-`, `border-`, `ring-`, `shadow-`, `fill-`, `stroke-`, etc.).
|
|
643
617
|
|
|
644
618
|
**Options:**
|
|
645
619
|
|
|
@@ -665,12 +639,6 @@ Detects arbitrary values that have a named Tailwind equivalent. The arbitrary fo
|
|
|
665
639
|
"bg-[#custom]"
|
|
666
640
|
```
|
|
667
641
|
|
|
668
|
-
**Options:**
|
|
669
|
-
|
|
670
|
-
| Option | Type | Description |
|
|
671
|
-
| ------------ | -------- | ------------------------------- |
|
|
672
|
-
| `entryPoint` | `string` | Path to Tailwind CSS entry file |
|
|
673
|
-
|
|
674
642
|
**Requires design system.** **Autofix:** Replaces with named class.
|
|
675
643
|
|
|
676
644
|
---
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
let _oxlint_plugins = require("@oxlint/plugins");
|
|
2
2
|
let node_child_process = require("node:child_process");
|
|
3
|
-
let
|
|
3
|
+
let node_crypto = require("node:crypto");
|
|
4
4
|
let node_fs = require("node:fs");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
let node_os = require("node:os");
|
|
5
7
|
//#region src/utils/extractors.ts
|
|
6
8
|
/**
|
|
7
9
|
* Preserves leading/trailing spaces in fixed class strings for template literals.
|
|
@@ -694,9 +696,18 @@ async function main() {
|
|
|
694
696
|
}
|
|
695
697
|
main().catch(e => { process.stderr.write(e.message); process.exit(1); });
|
|
696
698
|
`;
|
|
699
|
+
const CACHE_DIR = (0, node_path.join)((0, node_os.tmpdir)(), "oxlint-tailwindcss");
|
|
700
|
+
function getCachePath(cssPath, mtime) {
|
|
701
|
+
return (0, node_path.join)(CACHE_DIR, `${(0, node_crypto.createHash)("md5").update(`${cssPath}:${mtime}`).digest("hex")}.json`);
|
|
702
|
+
}
|
|
697
703
|
function loadDesignSystemSync(cssPath) {
|
|
698
704
|
const resolvedPath = (0, node_path.resolve)(cssPath);
|
|
699
705
|
try {
|
|
706
|
+
const mtime = (0, node_fs.statSync)(resolvedPath).mtimeMs;
|
|
707
|
+
const cachePath = getCachePath(resolvedPath, mtime);
|
|
708
|
+
if ((0, node_fs.existsSync)(cachePath)) try {
|
|
709
|
+
return JSON.parse((0, node_fs.readFileSync)(cachePath, "utf-8"));
|
|
710
|
+
} catch {}
|
|
700
711
|
const stdout = (0, node_child_process.execFileSync)(process.execPath, ["-e", PRECOMPUTE_SCRIPT], {
|
|
701
712
|
encoding: "utf-8",
|
|
702
713
|
timeout: 3e4,
|
|
@@ -707,6 +718,10 @@ function loadDesignSystemSync(cssPath) {
|
|
|
707
718
|
},
|
|
708
719
|
cwd: (0, node_path.dirname)(resolvedPath)
|
|
709
720
|
});
|
|
721
|
+
try {
|
|
722
|
+
(0, node_fs.mkdirSync)(CACHE_DIR, { recursive: true });
|
|
723
|
+
(0, node_fs.writeFileSync)(cachePath, stdout);
|
|
724
|
+
} catch {}
|
|
710
725
|
return JSON.parse(stdout);
|
|
711
726
|
} catch (error) {
|
|
712
727
|
console.error(`[oxlint-tailwindcss] Failed to load design system from "${resolvedPath}":`, error instanceof Error ? error.message : error);
|
|
@@ -715,21 +730,29 @@ function loadDesignSystemSync(cssPath) {
|
|
|
715
730
|
}
|
|
716
731
|
//#endregion
|
|
717
732
|
//#region src/design-system/auto-detect.ts
|
|
718
|
-
const
|
|
719
|
-
"src
|
|
720
|
-
"
|
|
721
|
-
"
|
|
722
|
-
"
|
|
723
|
-
"
|
|
724
|
-
"
|
|
725
|
-
"
|
|
726
|
-
"
|
|
727
|
-
"
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
"app
|
|
731
|
-
"
|
|
733
|
+
const CANDIDATE_DIRS = [
|
|
734
|
+
"src",
|
|
735
|
+
".",
|
|
736
|
+
"app",
|
|
737
|
+
"styles",
|
|
738
|
+
"style",
|
|
739
|
+
"css",
|
|
740
|
+
"assets",
|
|
741
|
+
"assets/css",
|
|
742
|
+
"resources/css"
|
|
743
|
+
];
|
|
744
|
+
const CANDIDATE_NAMES = [
|
|
745
|
+
"app",
|
|
746
|
+
"globals",
|
|
747
|
+
"global",
|
|
748
|
+
"style",
|
|
749
|
+
"styles",
|
|
750
|
+
"index",
|
|
751
|
+
"main",
|
|
752
|
+
"tailwind",
|
|
753
|
+
"tailwindcss"
|
|
732
754
|
];
|
|
755
|
+
const CANDIDATE_PATHS = CANDIDATE_DIRS.flatMap((dir) => CANDIDATE_NAMES.map((name) => dir === "." ? `${name}.css` : `${dir}/${name}.css`));
|
|
733
756
|
const TAILWIND_SIGNALS = [
|
|
734
757
|
"@import \"tailwindcss\"",
|
|
735
758
|
"@import 'tailwindcss'",
|
|
@@ -776,12 +799,24 @@ function autoDetectEntryPoint(filePath) {
|
|
|
776
799
|
//#region src/design-system/loader.ts
|
|
777
800
|
let singleton = null;
|
|
778
801
|
/**
|
|
802
|
+
* Extracts `entryPoint` from `context.settings.tailwindcss`.
|
|
803
|
+
*/
|
|
804
|
+
function entryPointFromSettings(settings) {
|
|
805
|
+
const tw = settings?.tailwindcss;
|
|
806
|
+
if (tw && typeof tw === "object" && "entryPoint" in tw) {
|
|
807
|
+
const ep = tw.entryPoint;
|
|
808
|
+
if (typeof ep === "string") return ep;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
779
812
|
* Returns the design system cache, loading synchronously on first call.
|
|
780
813
|
* Uses execFileSync internally to bridge the async Tailwind API.
|
|
781
814
|
* All rules receive the SAME instance.
|
|
815
|
+
*
|
|
816
|
+
* Resolution order: rule option `entryPoint` > `settings.tailwindcss.entryPoint` > auto-detect.
|
|
782
817
|
*/
|
|
783
|
-
function getLoadedDesignSystem(entryPoint) {
|
|
784
|
-
const cssPath = entryPoint ?? singleton?.path ?? autoDetectEntryPoint();
|
|
818
|
+
function getLoadedDesignSystem(entryPoint, settings) {
|
|
819
|
+
const cssPath = entryPoint ?? entryPointFromSettings(settings) ?? singleton?.path ?? autoDetectEntryPoint();
|
|
785
820
|
if (!cssPath) return null;
|
|
786
821
|
const resolvedPath = (0, node_path.resolve)(cssPath);
|
|
787
822
|
try {
|
|
@@ -824,6 +859,19 @@ function safeOptions(context) {
|
|
|
824
859
|
return;
|
|
825
860
|
}
|
|
826
861
|
}
|
|
862
|
+
/**
|
|
863
|
+
* Safely read context.settings.
|
|
864
|
+
*
|
|
865
|
+
* Like `safeOptions`, `context.settings` may not be accessible in `createOnce()`.
|
|
866
|
+
* The try/catch handles that gracefully.
|
|
867
|
+
*/
|
|
868
|
+
function safeSettings(context) {
|
|
869
|
+
try {
|
|
870
|
+
return context.settings ?? void 0;
|
|
871
|
+
} catch {
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
827
875
|
//#endregion
|
|
828
876
|
//#region src/rules/no-unknown-classes.ts
|
|
829
877
|
const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
@@ -852,7 +900,7 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
852
900
|
},
|
|
853
901
|
createOnce(context) {
|
|
854
902
|
const options = safeOptions(context);
|
|
855
|
-
const result = getLoadedDesignSystem(options?.entryPoint);
|
|
903
|
+
const result = getLoadedDesignSystem(options?.entryPoint, safeSettings(context));
|
|
856
904
|
if (!result) return {};
|
|
857
905
|
const { cache } = result;
|
|
858
906
|
const allowlist = new Set(options?.allowlist ?? []);
|
|
@@ -920,7 +968,7 @@ const noConflictingClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
920
968
|
messages: { conflict: "\"{{classA}}\" and \"{{classB}}\" affect {{properties}}. \"{{winner}}\" takes precedence (appears later)." }
|
|
921
969
|
},
|
|
922
970
|
createOnce(context) {
|
|
923
|
-
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint);
|
|
971
|
+
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint, safeSettings(context));
|
|
924
972
|
if (!result) return {};
|
|
925
973
|
const { cache } = result;
|
|
926
974
|
function check(locations) {
|
|
@@ -1007,7 +1055,7 @@ const noDeprecatedClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
1007
1055
|
messages: { deprecated: "\"{{className}}\" is deprecated in Tailwind v4. Use \"{{replacement}}\" instead." }
|
|
1008
1056
|
},
|
|
1009
1057
|
createOnce(context) {
|
|
1010
|
-
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint);
|
|
1058
|
+
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint, safeSettings(context));
|
|
1011
1059
|
function check(locations) {
|
|
1012
1060
|
for (const loc of locations) {
|
|
1013
1061
|
const classes = splitClasses(loc.value);
|
|
@@ -1066,7 +1114,7 @@ const enforceCanonical = (0, _oxlint_plugins.defineRule)({
|
|
|
1066
1114
|
messages: { nonCanonical: "\"{{className}}\" can be written as \"{{canonical}}\". Use the canonical form." }
|
|
1067
1115
|
},
|
|
1068
1116
|
createOnce(context) {
|
|
1069
|
-
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint);
|
|
1117
|
+
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint, safeSettings(context));
|
|
1070
1118
|
if (!result) return {};
|
|
1071
1119
|
const { cache } = result;
|
|
1072
1120
|
function check(locations) {
|
|
@@ -1140,7 +1188,7 @@ const enforceSortOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
1140
1188
|
messages: { unsorted: "Tailwind classes are not in the recommended order." }
|
|
1141
1189
|
},
|
|
1142
1190
|
createOnce(context) {
|
|
1143
|
-
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint);
|
|
1191
|
+
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint, safeSettings(context));
|
|
1144
1192
|
if (!result) return {};
|
|
1145
1193
|
const { cache } = result;
|
|
1146
1194
|
let _mode = null;
|
|
@@ -2276,7 +2324,7 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
2276
2324
|
messages: { wrongOrder: "\"{{className}}\" has variants in wrong order. Use \"{{replacement}}\" instead." }
|
|
2277
2325
|
},
|
|
2278
2326
|
createOnce(context) {
|
|
2279
|
-
const dsCache = getLoadedDesignSystem()?.cache ?? null;
|
|
2327
|
+
const dsCache = getLoadedDesignSystem(void 0, safeSettings(context))?.cache ?? null;
|
|
2280
2328
|
let _config = null;
|
|
2281
2329
|
function getConfig() {
|
|
2282
2330
|
if (_config === null) {
|
|
@@ -2485,7 +2533,7 @@ const noUnnecessaryArbitraryValue = (0, _oxlint_plugins.defineRule)({
|
|
|
2485
2533
|
messages: { unnecessaryArbitrary: "\"{{className}}\" can be written as \"{{replacement}}\". Use the named class instead." }
|
|
2486
2534
|
},
|
|
2487
2535
|
createOnce(context) {
|
|
2488
|
-
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint);
|
|
2536
|
+
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint, safeSettings(context));
|
|
2489
2537
|
if (!result) return {};
|
|
2490
2538
|
const { cache } = result;
|
|
2491
2539
|
function check(locations) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { definePlugin, defineRule } from "@oxlint/plugins";
|
|
2
2
|
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
3
5
|
import { dirname, join, resolve } from "node:path";
|
|
4
|
-
import {
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
5
7
|
//#region src/utils/extractors.ts
|
|
6
8
|
/**
|
|
7
9
|
* Preserves leading/trailing spaces in fixed class strings for template literals.
|
|
@@ -694,9 +696,18 @@ async function main() {
|
|
|
694
696
|
}
|
|
695
697
|
main().catch(e => { process.stderr.write(e.message); process.exit(1); });
|
|
696
698
|
`;
|
|
699
|
+
const CACHE_DIR = join(tmpdir(), "oxlint-tailwindcss");
|
|
700
|
+
function getCachePath(cssPath, mtime) {
|
|
701
|
+
return join(CACHE_DIR, `${createHash("md5").update(`${cssPath}:${mtime}`).digest("hex")}.json`);
|
|
702
|
+
}
|
|
697
703
|
function loadDesignSystemSync(cssPath) {
|
|
698
704
|
const resolvedPath = resolve(cssPath);
|
|
699
705
|
try {
|
|
706
|
+
const mtime = statSync(resolvedPath).mtimeMs;
|
|
707
|
+
const cachePath = getCachePath(resolvedPath, mtime);
|
|
708
|
+
if (existsSync(cachePath)) try {
|
|
709
|
+
return JSON.parse(readFileSync(cachePath, "utf-8"));
|
|
710
|
+
} catch {}
|
|
700
711
|
const stdout = execFileSync(process.execPath, ["-e", PRECOMPUTE_SCRIPT], {
|
|
701
712
|
encoding: "utf-8",
|
|
702
713
|
timeout: 3e4,
|
|
@@ -707,6 +718,10 @@ function loadDesignSystemSync(cssPath) {
|
|
|
707
718
|
},
|
|
708
719
|
cwd: dirname(resolvedPath)
|
|
709
720
|
});
|
|
721
|
+
try {
|
|
722
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
723
|
+
writeFileSync(cachePath, stdout);
|
|
724
|
+
} catch {}
|
|
710
725
|
return JSON.parse(stdout);
|
|
711
726
|
} catch (error) {
|
|
712
727
|
console.error(`[oxlint-tailwindcss] Failed to load design system from "${resolvedPath}":`, error instanceof Error ? error.message : error);
|
|
@@ -715,21 +730,29 @@ function loadDesignSystemSync(cssPath) {
|
|
|
715
730
|
}
|
|
716
731
|
//#endregion
|
|
717
732
|
//#region src/design-system/auto-detect.ts
|
|
718
|
-
const
|
|
719
|
-
"src
|
|
720
|
-
"
|
|
721
|
-
"
|
|
722
|
-
"
|
|
723
|
-
"
|
|
724
|
-
"
|
|
725
|
-
"
|
|
726
|
-
"
|
|
727
|
-
"
|
|
728
|
-
"style.css",
|
|
729
|
-
"styles/globals.css",
|
|
730
|
-
"app/globals.css",
|
|
731
|
-
"assets/css/tailwind.css"
|
|
733
|
+
const CANDIDATE_DIRS = [
|
|
734
|
+
"src",
|
|
735
|
+
".",
|
|
736
|
+
"app",
|
|
737
|
+
"styles",
|
|
738
|
+
"style",
|
|
739
|
+
"css",
|
|
740
|
+
"assets",
|
|
741
|
+
"assets/css",
|
|
742
|
+
"resources/css"
|
|
732
743
|
];
|
|
744
|
+
const CANDIDATE_NAMES = [
|
|
745
|
+
"app",
|
|
746
|
+
"globals",
|
|
747
|
+
"global",
|
|
748
|
+
"style",
|
|
749
|
+
"styles",
|
|
750
|
+
"index",
|
|
751
|
+
"main",
|
|
752
|
+
"tailwind",
|
|
753
|
+
"tailwindcss"
|
|
754
|
+
];
|
|
755
|
+
const CANDIDATE_PATHS = CANDIDATE_DIRS.flatMap((dir) => CANDIDATE_NAMES.map((name) => dir === "." ? `${name}.css` : `${dir}/${name}.css`));
|
|
733
756
|
const TAILWIND_SIGNALS = [
|
|
734
757
|
"@import \"tailwindcss\"",
|
|
735
758
|
"@import 'tailwindcss'",
|
|
@@ -776,12 +799,24 @@ function autoDetectEntryPoint(filePath) {
|
|
|
776
799
|
//#region src/design-system/loader.ts
|
|
777
800
|
let singleton = null;
|
|
778
801
|
/**
|
|
802
|
+
* Extracts `entryPoint` from `context.settings.tailwindcss`.
|
|
803
|
+
*/
|
|
804
|
+
function entryPointFromSettings(settings) {
|
|
805
|
+
const tw = settings?.tailwindcss;
|
|
806
|
+
if (tw && typeof tw === "object" && "entryPoint" in tw) {
|
|
807
|
+
const ep = tw.entryPoint;
|
|
808
|
+
if (typeof ep === "string") return ep;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
779
812
|
* Returns the design system cache, loading synchronously on first call.
|
|
780
813
|
* Uses execFileSync internally to bridge the async Tailwind API.
|
|
781
814
|
* All rules receive the SAME instance.
|
|
815
|
+
*
|
|
816
|
+
* Resolution order: rule option `entryPoint` > `settings.tailwindcss.entryPoint` > auto-detect.
|
|
782
817
|
*/
|
|
783
|
-
function getLoadedDesignSystem(entryPoint) {
|
|
784
|
-
const cssPath = entryPoint ?? singleton?.path ?? autoDetectEntryPoint();
|
|
818
|
+
function getLoadedDesignSystem(entryPoint, settings) {
|
|
819
|
+
const cssPath = entryPoint ?? entryPointFromSettings(settings) ?? singleton?.path ?? autoDetectEntryPoint();
|
|
785
820
|
if (!cssPath) return null;
|
|
786
821
|
const resolvedPath = resolve(cssPath);
|
|
787
822
|
try {
|
|
@@ -824,6 +859,19 @@ function safeOptions(context) {
|
|
|
824
859
|
return;
|
|
825
860
|
}
|
|
826
861
|
}
|
|
862
|
+
/**
|
|
863
|
+
* Safely read context.settings.
|
|
864
|
+
*
|
|
865
|
+
* Like `safeOptions`, `context.settings` may not be accessible in `createOnce()`.
|
|
866
|
+
* The try/catch handles that gracefully.
|
|
867
|
+
*/
|
|
868
|
+
function safeSettings(context) {
|
|
869
|
+
try {
|
|
870
|
+
return context.settings ?? void 0;
|
|
871
|
+
} catch {
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
827
875
|
//#endregion
|
|
828
876
|
//#region src/rules/no-unknown-classes.ts
|
|
829
877
|
const noUnknownClasses = defineRule({
|
|
@@ -852,7 +900,7 @@ const noUnknownClasses = defineRule({
|
|
|
852
900
|
},
|
|
853
901
|
createOnce(context) {
|
|
854
902
|
const options = safeOptions(context);
|
|
855
|
-
const result = getLoadedDesignSystem(options?.entryPoint);
|
|
903
|
+
const result = getLoadedDesignSystem(options?.entryPoint, safeSettings(context));
|
|
856
904
|
if (!result) return {};
|
|
857
905
|
const { cache } = result;
|
|
858
906
|
const allowlist = new Set(options?.allowlist ?? []);
|
|
@@ -920,7 +968,7 @@ const noConflictingClasses = defineRule({
|
|
|
920
968
|
messages: { conflict: "\"{{classA}}\" and \"{{classB}}\" affect {{properties}}. \"{{winner}}\" takes precedence (appears later)." }
|
|
921
969
|
},
|
|
922
970
|
createOnce(context) {
|
|
923
|
-
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint);
|
|
971
|
+
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint, safeSettings(context));
|
|
924
972
|
if (!result) return {};
|
|
925
973
|
const { cache } = result;
|
|
926
974
|
function check(locations) {
|
|
@@ -1007,7 +1055,7 @@ const noDeprecatedClasses = defineRule({
|
|
|
1007
1055
|
messages: { deprecated: "\"{{className}}\" is deprecated in Tailwind v4. Use \"{{replacement}}\" instead." }
|
|
1008
1056
|
},
|
|
1009
1057
|
createOnce(context) {
|
|
1010
|
-
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint);
|
|
1058
|
+
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint, safeSettings(context));
|
|
1011
1059
|
function check(locations) {
|
|
1012
1060
|
for (const loc of locations) {
|
|
1013
1061
|
const classes = splitClasses(loc.value);
|
|
@@ -1066,7 +1114,7 @@ const enforceCanonical = defineRule({
|
|
|
1066
1114
|
messages: { nonCanonical: "\"{{className}}\" can be written as \"{{canonical}}\". Use the canonical form." }
|
|
1067
1115
|
},
|
|
1068
1116
|
createOnce(context) {
|
|
1069
|
-
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint);
|
|
1117
|
+
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint, safeSettings(context));
|
|
1070
1118
|
if (!result) return {};
|
|
1071
1119
|
const { cache } = result;
|
|
1072
1120
|
function check(locations) {
|
|
@@ -1140,7 +1188,7 @@ const enforceSortOrder = defineRule({
|
|
|
1140
1188
|
messages: { unsorted: "Tailwind classes are not in the recommended order." }
|
|
1141
1189
|
},
|
|
1142
1190
|
createOnce(context) {
|
|
1143
|
-
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint);
|
|
1191
|
+
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint, safeSettings(context));
|
|
1144
1192
|
if (!result) return {};
|
|
1145
1193
|
const { cache } = result;
|
|
1146
1194
|
let _mode = null;
|
|
@@ -2276,7 +2324,7 @@ const consistentVariantOrder = defineRule({
|
|
|
2276
2324
|
messages: { wrongOrder: "\"{{className}}\" has variants in wrong order. Use \"{{replacement}}\" instead." }
|
|
2277
2325
|
},
|
|
2278
2326
|
createOnce(context) {
|
|
2279
|
-
const dsCache = getLoadedDesignSystem()?.cache ?? null;
|
|
2327
|
+
const dsCache = getLoadedDesignSystem(void 0, safeSettings(context))?.cache ?? null;
|
|
2280
2328
|
let _config = null;
|
|
2281
2329
|
function getConfig() {
|
|
2282
2330
|
if (_config === null) {
|
|
@@ -2485,7 +2533,7 @@ const noUnnecessaryArbitraryValue = defineRule({
|
|
|
2485
2533
|
messages: { unnecessaryArbitrary: "\"{{className}}\" can be written as \"{{replacement}}\". Use the named class instead." }
|
|
2486
2534
|
},
|
|
2487
2535
|
createOnce(context) {
|
|
2488
|
-
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint);
|
|
2536
|
+
const result = getLoadedDesignSystem(safeOptions(context)?.entryPoint, safeSettings(context));
|
|
2489
2537
|
if (!result) return {};
|
|
2490
2538
|
const { cache } = result;
|
|
2491
2539
|
function check(locations) {
|