oxlint-tailwindcss 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -3
- package/dist/index.cjs +55 -7
- package/dist/index.mjs +55 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# oxlint-tailwindcss
|
|
2
2
|
|
|
3
|
-
22 Tailwind CSS linting rules for [oxlint](https://oxc.rs/docs/guide/usage/linter). Built for Tailwind CSS v4 with
|
|
3
|
+
22 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
|
|
|
7
7
|
## Highlights
|
|
8
8
|
|
|
9
|
-
- **
|
|
9
|
+
- **Works out of the box** — Auto-detects your Tailwind CSS entry point. Fully configurable when needed.
|
|
10
10
|
- **Fast** — Native oxlint plugin with a shared design system cache. Loads once, used by all rules.
|
|
11
11
|
- **Tailwind CSS v4** — Designed for v4 from day one.
|
|
12
12
|
- **Typo suggestions** — `itms-center` → "Did you mean `items-center`?"
|
|
@@ -75,7 +75,7 @@ assets/{name}.css assets/css/{name}.css resources/css/{name}.css
|
|
|
75
75
|
|
|
76
76
|
Where `{name}` is one of: `app`, `globals`, `global`, `style`, `styles`, `index`, `main`, `tailwind`, `tailwindcss`.
|
|
77
77
|
|
|
78
|
-
The search is monorepo-aware — it stops at `package.json` boundaries so each package resolves its own Tailwind config.
|
|
78
|
+
The search is monorepo-aware — it stops at `package.json` boundaries so each package resolves its own Tailwind config. If the signal isn't found directly in the CSS file, the auto-detector follows `@import` statements one level deep — supporting both relative paths and package imports (e.g. `@import '@company/theme/tailwind.config.css'`).
|
|
79
79
|
|
|
80
80
|
If auto-detection doesn't find your CSS file, set `entryPoint` once in `settings`:
|
|
81
81
|
|
|
@@ -140,6 +140,25 @@ You can extend these defaults via `settings.tailwindcss`. All values are **addit
|
|
|
140
140
|
|
|
141
141
|
This applies to all 22 rules at once. For example, adding `"classNames"` to `attributes` makes every rule lint `<Input classNames={{ root: "..." }} />`.
|
|
142
142
|
|
|
143
|
+
To **remove** specific items from the built-in defaults, use `exclude`:
|
|
144
|
+
|
|
145
|
+
```jsonc
|
|
146
|
+
{
|
|
147
|
+
"settings": {
|
|
148
|
+
"tailwindcss": {
|
|
149
|
+
"exclude": {
|
|
150
|
+
// Stop scanning variables named "style" / "styles"
|
|
151
|
+
"variablePatterns": ["^styles?$"],
|
|
152
|
+
// Stop scanning a specific callee
|
|
153
|
+
"callees": ["objstr"],
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
For `variablePatterns`, exclusions match against the regex source (e.g. `"^styles?$"` removes the default `/^styles?$/` pattern).
|
|
161
|
+
|
|
143
162
|
## Supported patterns
|
|
144
163
|
|
|
145
164
|
The plugin extracts Tailwind classes from:
|
package/dist/index.cjs
CHANGED
|
@@ -42,9 +42,14 @@ const DEFAULT_EXTRACTOR_CONFIG = {
|
|
|
42
42
|
};
|
|
43
43
|
let _cachedConfig = null;
|
|
44
44
|
let _settingsResolved = false;
|
|
45
|
-
function mergeUnique(defaults, extras) {
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
function mergeUnique(defaults, extras, exclusions) {
|
|
46
|
+
let base = defaults;
|
|
47
|
+
if (exclusions && exclusions.length > 0) {
|
|
48
|
+
const excludeSet = new Set(exclusions);
|
|
49
|
+
base = base.filter((d) => !excludeSet.has(d));
|
|
50
|
+
}
|
|
51
|
+
if (!extras || extras.length === 0) return base;
|
|
52
|
+
const set = new Set(base);
|
|
48
53
|
for (const e of extras) set.add(e);
|
|
49
54
|
return [...set];
|
|
50
55
|
}
|
|
@@ -67,11 +72,14 @@ function getExtractorConfig(context) {
|
|
|
67
72
|
_cachedConfig = DEFAULT_EXTRACTOR_CONFIG;
|
|
68
73
|
return _cachedConfig;
|
|
69
74
|
}
|
|
75
|
+
const exclude = tw.exclude;
|
|
76
|
+
const excludedPatternSources = new Set(exclude?.variablePatterns ?? []);
|
|
77
|
+
const filteredPatterns = excludedPatternSources.size > 0 ? DEFAULT_EXTRACTOR_CONFIG.variablePatterns.filter((re) => !excludedPatternSources.has(re.source)) : DEFAULT_EXTRACTOR_CONFIG.variablePatterns;
|
|
70
78
|
_cachedConfig = {
|
|
71
|
-
attributes: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.attributes, tw.attributes),
|
|
72
|
-
callees: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.callees, tw.callees),
|
|
73
|
-
tags: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.tags, tw.tags),
|
|
74
|
-
variablePatterns: [...
|
|
79
|
+
attributes: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.attributes, tw.attributes, exclude?.attributes),
|
|
80
|
+
callees: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.callees, tw.callees, exclude?.callees),
|
|
81
|
+
tags: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.tags, tw.tags, exclude?.tags),
|
|
82
|
+
variablePatterns: [...filteredPatterns, ...(tw.variablePatterns ?? []).map((p) => new RegExp(p))]
|
|
75
83
|
};
|
|
76
84
|
return _cachedConfig;
|
|
77
85
|
}
|
|
@@ -1122,6 +1130,44 @@ function loadDesignSystemSync(cssPath) {
|
|
|
1122
1130
|
}
|
|
1123
1131
|
//#endregion
|
|
1124
1132
|
//#region src/design-system/auto-detect.ts
|
|
1133
|
+
const IMPORT_RE = /@import\s+['"]([^'"]+)['"]/g;
|
|
1134
|
+
/**
|
|
1135
|
+
* Resolves a CSS @import specifier to an absolute path.
|
|
1136
|
+
* Handles relative paths and package imports (walks up to node_modules).
|
|
1137
|
+
*/
|
|
1138
|
+
function resolveImport(specifier, baseDir) {
|
|
1139
|
+
if (specifier.startsWith(".")) return (0, node_path.resolve)(baseDir, specifier);
|
|
1140
|
+
let dir = baseDir;
|
|
1141
|
+
while (true) {
|
|
1142
|
+
const candidate = (0, node_path.join)(dir, "node_modules", specifier);
|
|
1143
|
+
if ((0, node_fs.existsSync)(candidate)) return candidate;
|
|
1144
|
+
const parent = (0, node_path.dirname)(dir);
|
|
1145
|
+
if (parent === dir) break;
|
|
1146
|
+
dir = parent;
|
|
1147
|
+
}
|
|
1148
|
+
return null;
|
|
1149
|
+
}
|
|
1150
|
+
/**
|
|
1151
|
+
* Checks if any @import in the CSS content points to a file containing a Tailwind signal.
|
|
1152
|
+
* Only follows ONE level of imports — no recursion.
|
|
1153
|
+
*/
|
|
1154
|
+
function hasTailwindSignalInImports(content, baseDir, signals) {
|
|
1155
|
+
IMPORT_RE.lastIndex = 0;
|
|
1156
|
+
let match;
|
|
1157
|
+
while ((match = IMPORT_RE.exec(content)) !== null) {
|
|
1158
|
+
const specifier = match[1];
|
|
1159
|
+
if (specifier === "tailwindcss") continue;
|
|
1160
|
+
const resolved = resolveImport(specifier, baseDir);
|
|
1161
|
+
if (!resolved) continue;
|
|
1162
|
+
try {
|
|
1163
|
+
const imported = (0, node_fs.readFileSync)(resolved, "utf-8");
|
|
1164
|
+
if (signals.some((signal) => imported.includes(signal))) return true;
|
|
1165
|
+
} catch {
|
|
1166
|
+
continue;
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
return false;
|
|
1170
|
+
}
|
|
1125
1171
|
const CANDIDATE_DIRS = [
|
|
1126
1172
|
"src",
|
|
1127
1173
|
".",
|
|
@@ -1164,6 +1210,7 @@ function autoDetectEntryPoint(filePath) {
|
|
|
1164
1210
|
try {
|
|
1165
1211
|
const content = (0, node_fs.readFileSync)(fullPath, "utf-8");
|
|
1166
1212
|
if (TAILWIND_SIGNALS.some((signal) => content.includes(signal))) return fullPath;
|
|
1213
|
+
if (hasTailwindSignalInImports(content, (0, node_path.dirname)(fullPath), TAILWIND_SIGNALS)) return fullPath;
|
|
1167
1214
|
} catch {
|
|
1168
1215
|
continue;
|
|
1169
1216
|
}
|
|
@@ -1177,6 +1224,7 @@ function autoDetectEntryPoint(filePath) {
|
|
|
1177
1224
|
try {
|
|
1178
1225
|
const content = (0, node_fs.readFileSync)(fullPath, "utf-8");
|
|
1179
1226
|
if (TAILWIND_SIGNALS.some((signal) => content.includes(signal))) return fullPath;
|
|
1227
|
+
if (hasTailwindSignalInImports(content, (0, node_path.dirname)(fullPath), TAILWIND_SIGNALS)) return fullPath;
|
|
1180
1228
|
} catch {
|
|
1181
1229
|
continue;
|
|
1182
1230
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -46,9 +46,14 @@ const DEFAULT_EXTRACTOR_CONFIG = {
|
|
|
46
46
|
};
|
|
47
47
|
let _cachedConfig = null;
|
|
48
48
|
let _settingsResolved = false;
|
|
49
|
-
function mergeUnique(defaults, extras) {
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
function mergeUnique(defaults, extras, exclusions) {
|
|
50
|
+
let base = defaults;
|
|
51
|
+
if (exclusions && exclusions.length > 0) {
|
|
52
|
+
const excludeSet = new Set(exclusions);
|
|
53
|
+
base = base.filter((d) => !excludeSet.has(d));
|
|
54
|
+
}
|
|
55
|
+
if (!extras || extras.length === 0) return base;
|
|
56
|
+
const set = new Set(base);
|
|
52
57
|
for (const e of extras) set.add(e);
|
|
53
58
|
return [...set];
|
|
54
59
|
}
|
|
@@ -71,11 +76,14 @@ function getExtractorConfig(context) {
|
|
|
71
76
|
_cachedConfig = DEFAULT_EXTRACTOR_CONFIG;
|
|
72
77
|
return _cachedConfig;
|
|
73
78
|
}
|
|
79
|
+
const exclude = tw.exclude;
|
|
80
|
+
const excludedPatternSources = new Set(exclude?.variablePatterns ?? []);
|
|
81
|
+
const filteredPatterns = excludedPatternSources.size > 0 ? DEFAULT_EXTRACTOR_CONFIG.variablePatterns.filter((re) => !excludedPatternSources.has(re.source)) : DEFAULT_EXTRACTOR_CONFIG.variablePatterns;
|
|
74
82
|
_cachedConfig = {
|
|
75
|
-
attributes: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.attributes, tw.attributes),
|
|
76
|
-
callees: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.callees, tw.callees),
|
|
77
|
-
tags: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.tags, tw.tags),
|
|
78
|
-
variablePatterns: [...
|
|
83
|
+
attributes: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.attributes, tw.attributes, exclude?.attributes),
|
|
84
|
+
callees: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.callees, tw.callees, exclude?.callees),
|
|
85
|
+
tags: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.tags, tw.tags, exclude?.tags),
|
|
86
|
+
variablePatterns: [...filteredPatterns, ...(tw.variablePatterns ?? []).map((p) => new RegExp(p))]
|
|
79
87
|
};
|
|
80
88
|
return _cachedConfig;
|
|
81
89
|
}
|
|
@@ -1126,6 +1134,44 @@ function loadDesignSystemSync(cssPath) {
|
|
|
1126
1134
|
}
|
|
1127
1135
|
//#endregion
|
|
1128
1136
|
//#region src/design-system/auto-detect.ts
|
|
1137
|
+
const IMPORT_RE = /@import\s+['"]([^'"]+)['"]/g;
|
|
1138
|
+
/**
|
|
1139
|
+
* Resolves a CSS @import specifier to an absolute path.
|
|
1140
|
+
* Handles relative paths and package imports (walks up to node_modules).
|
|
1141
|
+
*/
|
|
1142
|
+
function resolveImport(specifier, baseDir) {
|
|
1143
|
+
if (specifier.startsWith(".")) return resolve(baseDir, specifier);
|
|
1144
|
+
let dir = baseDir;
|
|
1145
|
+
while (true) {
|
|
1146
|
+
const candidate = join(dir, "node_modules", specifier);
|
|
1147
|
+
if (existsSync(candidate)) return candidate;
|
|
1148
|
+
const parent = dirname(dir);
|
|
1149
|
+
if (parent === dir) break;
|
|
1150
|
+
dir = parent;
|
|
1151
|
+
}
|
|
1152
|
+
return null;
|
|
1153
|
+
}
|
|
1154
|
+
/**
|
|
1155
|
+
* Checks if any @import in the CSS content points to a file containing a Tailwind signal.
|
|
1156
|
+
* Only follows ONE level of imports — no recursion.
|
|
1157
|
+
*/
|
|
1158
|
+
function hasTailwindSignalInImports(content, baseDir, signals) {
|
|
1159
|
+
IMPORT_RE.lastIndex = 0;
|
|
1160
|
+
let match;
|
|
1161
|
+
while ((match = IMPORT_RE.exec(content)) !== null) {
|
|
1162
|
+
const specifier = match[1];
|
|
1163
|
+
if (specifier === "tailwindcss") continue;
|
|
1164
|
+
const resolved = resolveImport(specifier, baseDir);
|
|
1165
|
+
if (!resolved) continue;
|
|
1166
|
+
try {
|
|
1167
|
+
const imported = readFileSync(resolved, "utf-8");
|
|
1168
|
+
if (signals.some((signal) => imported.includes(signal))) return true;
|
|
1169
|
+
} catch {
|
|
1170
|
+
continue;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
return false;
|
|
1174
|
+
}
|
|
1129
1175
|
const CANDIDATE_DIRS = [
|
|
1130
1176
|
"src",
|
|
1131
1177
|
".",
|
|
@@ -1168,6 +1214,7 @@ function autoDetectEntryPoint(filePath) {
|
|
|
1168
1214
|
try {
|
|
1169
1215
|
const content = readFileSync(fullPath, "utf-8");
|
|
1170
1216
|
if (TAILWIND_SIGNALS.some((signal) => content.includes(signal))) return fullPath;
|
|
1217
|
+
if (hasTailwindSignalInImports(content, dirname(fullPath), TAILWIND_SIGNALS)) return fullPath;
|
|
1171
1218
|
} catch {
|
|
1172
1219
|
continue;
|
|
1173
1220
|
}
|
|
@@ -1181,6 +1228,7 @@ function autoDetectEntryPoint(filePath) {
|
|
|
1181
1228
|
try {
|
|
1182
1229
|
const content = readFileSync(fullPath, "utf-8");
|
|
1183
1230
|
if (TAILWIND_SIGNALS.some((signal) => content.includes(signal))) return fullPath;
|
|
1231
|
+
if (hasTailwindSignalInImports(content, dirname(fullPath), TAILWIND_SIGNALS)) return fullPath;
|
|
1184
1232
|
} catch {
|
|
1185
1233
|
continue;
|
|
1186
1234
|
}
|