oxlint-tailwindcss 1.9.0 → 1.10.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 +11 -0
- package/dist/index.cjs +54 -9
- package/dist/index.mjs +54 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,6 +61,7 @@ Add the plugin to your `.oxlintrc.json`:
|
|
|
61
61
|
"tailwindcss/no-conflicting-classes": "error",
|
|
62
62
|
"tailwindcss/no-deprecated-classes": "error",
|
|
63
63
|
"tailwindcss/no-unnecessary-whitespace": "error",
|
|
64
|
+
// These two only inspect literal class lists on native elements; cn()/twMerge() fragments and custom-component classNames are skipped (issue #117).
|
|
64
65
|
"tailwindcss/no-dark-without-light": "warn",
|
|
65
66
|
"tailwindcss/no-contradicting-variants": "warn",
|
|
66
67
|
// Style
|
|
@@ -476,6 +477,11 @@ Requires a base (light) utility when using the `dark:` variant on the same eleme
|
|
|
476
477
|
Groups by utility prefix (`bg-`, `text-`, `border-`, etc.) — only checks that a base utility of the
|
|
477
478
|
same type exists.
|
|
478
479
|
|
|
480
|
+
**Scope (issue #117):** only inspects literal class lists on **native host elements** (`<div>`,
|
|
481
|
+
`<input>`, …). Strings passed to `cn`/`twMerge`/`cva` or set on a custom component's `className` are
|
|
482
|
+
override fragments whose light base commonly lives in another module, so they are skipped to avoid
|
|
483
|
+
false positives.
|
|
484
|
+
|
|
479
485
|
**Options:**
|
|
480
486
|
|
|
481
487
|
| Option | Type | Default | Description |
|
|
@@ -507,6 +513,11 @@ Only flags when the exact same utility exists both as base and with a conditiona
|
|
|
507
513
|
that change the selector target (pseudo-elements, child/descendant selectors, arbitrary selectors)
|
|
508
514
|
are not flagged.
|
|
509
515
|
|
|
516
|
+
**Scope (issue #117):** only inspects literal class lists on **native host elements** (`<div>`,
|
|
517
|
+
`<button>`, …). Strings passed to `cn`/`twMerge`/`cva` or set on a custom component's `className`
|
|
518
|
+
are override fragments where the "redundant" variant is often load-bearing (it beats a same-group
|
|
519
|
+
class the component merges in), so they are skipped to avoid false positives.
|
|
520
|
+
|
|
510
521
|
**No options.** **No autofix.**
|
|
511
522
|
|
|
512
523
|
---
|
package/dist/index.cjs
CHANGED
|
@@ -90,6 +90,21 @@ function matchesAny(value, list) {
|
|
|
90
90
|
//#endregion
|
|
91
91
|
//#region src/utils/extractors.ts
|
|
92
92
|
/**
|
|
93
|
+
* Whether this string is the element's FINAL, self-contained class list — the
|
|
94
|
+
* only position where a RELATIONAL rule (one whose verdict for a class depends
|
|
95
|
+
* on the OTHER classes in the string) can decide safely. Everywhere else the
|
|
96
|
+
* string may be an override FRAGMENT merged at runtime — by `cn`/`twMerge`/
|
|
97
|
+
* `cva`, or inside a custom component — with classes contributed in another
|
|
98
|
+
* argument or another module, where claims like "the base already applies
|
|
99
|
+
* unconditionally" or "there is no light base" are undecidable without
|
|
100
|
+
* emulating tailwind-merge (issue #117). The two relational rules
|
|
101
|
+
* (`no-contradicting-variants`, `no-dark-without-light`) gate on this; it is
|
|
102
|
+
* the single home for that decision so it can't drift between them.
|
|
103
|
+
*/
|
|
104
|
+
function isFinalClassList(loc) {
|
|
105
|
+
return loc.origin === "jsx-native";
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
93
108
|
* Preserves leading/trailing spaces in fixed class strings for template literals.
|
|
94
109
|
* Without this, `h-3 w-3 ${x}` fixed to `size-3${x}` would break classes.
|
|
95
110
|
*/
|
|
@@ -191,6 +206,32 @@ function createExtractorVisitors(context, check) {
|
|
|
191
206
|
};
|
|
192
207
|
}
|
|
193
208
|
/**
|
|
209
|
+
* Stamps every location with its extraction origin and returns the array.
|
|
210
|
+
* Origin is set once at each of the 4 entry points, so the recursive
|
|
211
|
+
* `extractFromExpression` helpers stay origin-agnostic.
|
|
212
|
+
*/
|
|
213
|
+
function withOrigin(locations, origin) {
|
|
214
|
+
for (const loc of locations) loc.origin = origin;
|
|
215
|
+
return locations;
|
|
216
|
+
}
|
|
217
|
+
const NATIVE_JSX_TAG = /^[a-z]/;
|
|
218
|
+
/**
|
|
219
|
+
* Classifies the JSX host element of an attribute as a native (lowercase) host
|
|
220
|
+
* — where the `className` literal IS the element's final class list — or a
|
|
221
|
+
* custom component, where the string is opaque (it may be re-merged inside the
|
|
222
|
+
* component with `cva`/`twMerge`). Conservative: unknown parent shapes →
|
|
223
|
+
* component, so a relational rule under-reports rather than emitting a false
|
|
224
|
+
* positive.
|
|
225
|
+
*/
|
|
226
|
+
function jsxHostOrigin(node) {
|
|
227
|
+
const parent = node.parent;
|
|
228
|
+
if (parent && parent.type === "JSXOpeningElement") {
|
|
229
|
+
const elementName = parent.name;
|
|
230
|
+
if (elementName.type === "JSXIdentifier" && NATIVE_JSX_TAG.test(elementName.name)) return "jsx-native";
|
|
231
|
+
}
|
|
232
|
+
return "jsx-component";
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
194
235
|
* Extracts class locations from a JSXAttribute node.
|
|
195
236
|
* Handles: className="...", className={`...`}, className={cond ? "..." : "..."}
|
|
196
237
|
*/
|
|
@@ -198,15 +239,17 @@ function extractFromJSXAttribute(node, config = DEFAULT_EXTRACTOR_CONFIG) {
|
|
|
198
239
|
const name = node.name.type === "JSXIdentifier" ? node.name.name : void 0;
|
|
199
240
|
if (!name || !config.attributes.includes(name)) return [];
|
|
200
241
|
if (!node.value) return [];
|
|
242
|
+
const hostOrigin = jsxHostOrigin(node);
|
|
201
243
|
if (node.value.type === "Literal" && typeof node.value.value === "string") return [{
|
|
202
244
|
value: node.value.value,
|
|
203
245
|
node: node.value,
|
|
204
|
-
range: [node.value.range[0] + 1, node.value.range[1] - 1]
|
|
246
|
+
range: [node.value.range[0] + 1, node.value.range[1] - 1],
|
|
247
|
+
origin: hostOrigin
|
|
205
248
|
}];
|
|
206
249
|
if (node.value.type === "JSXExpressionContainer") {
|
|
207
250
|
const expr = node.value.expression;
|
|
208
|
-
if (expr.type === "ObjectExpression") return extractObjectValues(expr);
|
|
209
|
-
return extractFromExpression(expr);
|
|
251
|
+
if (expr.type === "ObjectExpression") return withOrigin(extractObjectValues(expr), "jsx-object");
|
|
252
|
+
return withOrigin(extractFromExpression(expr), hostOrigin);
|
|
210
253
|
}
|
|
211
254
|
return [];
|
|
212
255
|
}
|
|
@@ -217,12 +260,12 @@ function extractFromJSXAttribute(node, config = DEFAULT_EXTRACTOR_CONFIG) {
|
|
|
217
260
|
function extractFromCallExpression(node, config = DEFAULT_EXTRACTOR_CONFIG) {
|
|
218
261
|
const calleeName = getCalleeName(node.callee);
|
|
219
262
|
if (!calleeName || !config.callees.includes(calleeName)) return [];
|
|
220
|
-
if (calleeName === "cva") return extractFromCvaCall(node);
|
|
221
|
-
if (calleeName === "tv") return extractFromTvCall(node);
|
|
222
|
-
if (calleeName === "classed") return extractFromClassedCall(node);
|
|
263
|
+
if (calleeName === "cva") return withOrigin(extractFromCvaCall(node), "callee");
|
|
264
|
+
if (calleeName === "tv") return withOrigin(extractFromTvCall(node), "callee");
|
|
265
|
+
if (calleeName === "classed") return withOrigin(extractFromClassedCall(node), "callee");
|
|
223
266
|
const results = [];
|
|
224
267
|
for (const arg of node.arguments) extractFromExpression(arg, results);
|
|
225
|
-
return results;
|
|
268
|
+
return withOrigin(results, "callee");
|
|
226
269
|
}
|
|
227
270
|
/**
|
|
228
271
|
* Extracts class locations from a TaggedTemplateExpression (tw`...`).
|
|
@@ -230,7 +273,7 @@ function extractFromCallExpression(node, config = DEFAULT_EXTRACTOR_CONFIG) {
|
|
|
230
273
|
function extractFromTaggedTemplate(node, config = DEFAULT_EXTRACTOR_CONFIG) {
|
|
231
274
|
const tagName = getCalleeName(node.tag);
|
|
232
275
|
if (!tagName || !config.tags.includes(tagName)) return [];
|
|
233
|
-
return extractFromTemplateLiteral(node.quasi);
|
|
276
|
+
return withOrigin(extractFromTemplateLiteral(node.quasi), "template-tag");
|
|
234
277
|
}
|
|
235
278
|
/**
|
|
236
279
|
* Extracts class string values from an ObjectExpression in a JSX attribute.
|
|
@@ -367,7 +410,7 @@ function extractFromVariableDeclarator(node, config = DEFAULT_EXTRACTOR_CONFIG)
|
|
|
367
410
|
if (node.id.type !== "Identifier") return [];
|
|
368
411
|
if (!config.variablePatterns.some((p) => p.test(node.id.name))) return [];
|
|
369
412
|
if (!node.init) return [];
|
|
370
|
-
return extractFromExpression(node.init);
|
|
413
|
+
return withOrigin(extractFromExpression(node.init), "variable");
|
|
371
414
|
}
|
|
372
415
|
/**
|
|
373
416
|
* Walk an expression and append every class-bearing location to `out`.
|
|
@@ -6319,6 +6362,7 @@ const noDarkWithoutLight = defineRule({
|
|
|
6319
6362
|
const ds = softGetDS(getDS);
|
|
6320
6363
|
const cache = ds ? ds.cache : null;
|
|
6321
6364
|
for (const loc of locations) {
|
|
6365
|
+
if (!isFinalClassList(loc)) continue;
|
|
6322
6366
|
const classes = splitClasses(loc.value);
|
|
6323
6367
|
if (cache && ds) {
|
|
6324
6368
|
let unresolved = null;
|
|
@@ -6579,6 +6623,7 @@ const noContradictingVariants = defineRule({
|
|
|
6579
6623
|
function check(locations) {
|
|
6580
6624
|
const factsFor = variantFactsLookup();
|
|
6581
6625
|
for (const loc of locations) {
|
|
6626
|
+
if (!isFinalClassList(loc)) continue;
|
|
6582
6627
|
const classes = splitClasses(loc.value);
|
|
6583
6628
|
const baseUtilities = /* @__PURE__ */ new Set();
|
|
6584
6629
|
for (const cls of classes) if (extractVariants(cls).length === 0) baseUtilities.add(cls);
|
package/dist/index.mjs
CHANGED
|
@@ -94,6 +94,21 @@ function matchesAny(value, list) {
|
|
|
94
94
|
//#endregion
|
|
95
95
|
//#region src/utils/extractors.ts
|
|
96
96
|
/**
|
|
97
|
+
* Whether this string is the element's FINAL, self-contained class list — the
|
|
98
|
+
* only position where a RELATIONAL rule (one whose verdict for a class depends
|
|
99
|
+
* on the OTHER classes in the string) can decide safely. Everywhere else the
|
|
100
|
+
* string may be an override FRAGMENT merged at runtime — by `cn`/`twMerge`/
|
|
101
|
+
* `cva`, or inside a custom component — with classes contributed in another
|
|
102
|
+
* argument or another module, where claims like "the base already applies
|
|
103
|
+
* unconditionally" or "there is no light base" are undecidable without
|
|
104
|
+
* emulating tailwind-merge (issue #117). The two relational rules
|
|
105
|
+
* (`no-contradicting-variants`, `no-dark-without-light`) gate on this; it is
|
|
106
|
+
* the single home for that decision so it can't drift between them.
|
|
107
|
+
*/
|
|
108
|
+
function isFinalClassList(loc) {
|
|
109
|
+
return loc.origin === "jsx-native";
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
97
112
|
* Preserves leading/trailing spaces in fixed class strings for template literals.
|
|
98
113
|
* Without this, `h-3 w-3 ${x}` fixed to `size-3${x}` would break classes.
|
|
99
114
|
*/
|
|
@@ -195,6 +210,32 @@ function createExtractorVisitors(context, check) {
|
|
|
195
210
|
};
|
|
196
211
|
}
|
|
197
212
|
/**
|
|
213
|
+
* Stamps every location with its extraction origin and returns the array.
|
|
214
|
+
* Origin is set once at each of the 4 entry points, so the recursive
|
|
215
|
+
* `extractFromExpression` helpers stay origin-agnostic.
|
|
216
|
+
*/
|
|
217
|
+
function withOrigin(locations, origin) {
|
|
218
|
+
for (const loc of locations) loc.origin = origin;
|
|
219
|
+
return locations;
|
|
220
|
+
}
|
|
221
|
+
const NATIVE_JSX_TAG = /^[a-z]/;
|
|
222
|
+
/**
|
|
223
|
+
* Classifies the JSX host element of an attribute as a native (lowercase) host
|
|
224
|
+
* — where the `className` literal IS the element's final class list — or a
|
|
225
|
+
* custom component, where the string is opaque (it may be re-merged inside the
|
|
226
|
+
* component with `cva`/`twMerge`). Conservative: unknown parent shapes →
|
|
227
|
+
* component, so a relational rule under-reports rather than emitting a false
|
|
228
|
+
* positive.
|
|
229
|
+
*/
|
|
230
|
+
function jsxHostOrigin(node) {
|
|
231
|
+
const parent = node.parent;
|
|
232
|
+
if (parent && parent.type === "JSXOpeningElement") {
|
|
233
|
+
const elementName = parent.name;
|
|
234
|
+
if (elementName.type === "JSXIdentifier" && NATIVE_JSX_TAG.test(elementName.name)) return "jsx-native";
|
|
235
|
+
}
|
|
236
|
+
return "jsx-component";
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
198
239
|
* Extracts class locations from a JSXAttribute node.
|
|
199
240
|
* Handles: className="...", className={`...`}, className={cond ? "..." : "..."}
|
|
200
241
|
*/
|
|
@@ -202,15 +243,17 @@ function extractFromJSXAttribute(node, config = DEFAULT_EXTRACTOR_CONFIG) {
|
|
|
202
243
|
const name = node.name.type === "JSXIdentifier" ? node.name.name : void 0;
|
|
203
244
|
if (!name || !config.attributes.includes(name)) return [];
|
|
204
245
|
if (!node.value) return [];
|
|
246
|
+
const hostOrigin = jsxHostOrigin(node);
|
|
205
247
|
if (node.value.type === "Literal" && typeof node.value.value === "string") return [{
|
|
206
248
|
value: node.value.value,
|
|
207
249
|
node: node.value,
|
|
208
|
-
range: [node.value.range[0] + 1, node.value.range[1] - 1]
|
|
250
|
+
range: [node.value.range[0] + 1, node.value.range[1] - 1],
|
|
251
|
+
origin: hostOrigin
|
|
209
252
|
}];
|
|
210
253
|
if (node.value.type === "JSXExpressionContainer") {
|
|
211
254
|
const expr = node.value.expression;
|
|
212
|
-
if (expr.type === "ObjectExpression") return extractObjectValues(expr);
|
|
213
|
-
return extractFromExpression(expr);
|
|
255
|
+
if (expr.type === "ObjectExpression") return withOrigin(extractObjectValues(expr), "jsx-object");
|
|
256
|
+
return withOrigin(extractFromExpression(expr), hostOrigin);
|
|
214
257
|
}
|
|
215
258
|
return [];
|
|
216
259
|
}
|
|
@@ -221,12 +264,12 @@ function extractFromJSXAttribute(node, config = DEFAULT_EXTRACTOR_CONFIG) {
|
|
|
221
264
|
function extractFromCallExpression(node, config = DEFAULT_EXTRACTOR_CONFIG) {
|
|
222
265
|
const calleeName = getCalleeName(node.callee);
|
|
223
266
|
if (!calleeName || !config.callees.includes(calleeName)) return [];
|
|
224
|
-
if (calleeName === "cva") return extractFromCvaCall(node);
|
|
225
|
-
if (calleeName === "tv") return extractFromTvCall(node);
|
|
226
|
-
if (calleeName === "classed") return extractFromClassedCall(node);
|
|
267
|
+
if (calleeName === "cva") return withOrigin(extractFromCvaCall(node), "callee");
|
|
268
|
+
if (calleeName === "tv") return withOrigin(extractFromTvCall(node), "callee");
|
|
269
|
+
if (calleeName === "classed") return withOrigin(extractFromClassedCall(node), "callee");
|
|
227
270
|
const results = [];
|
|
228
271
|
for (const arg of node.arguments) extractFromExpression(arg, results);
|
|
229
|
-
return results;
|
|
272
|
+
return withOrigin(results, "callee");
|
|
230
273
|
}
|
|
231
274
|
/**
|
|
232
275
|
* Extracts class locations from a TaggedTemplateExpression (tw`...`).
|
|
@@ -234,7 +277,7 @@ function extractFromCallExpression(node, config = DEFAULT_EXTRACTOR_CONFIG) {
|
|
|
234
277
|
function extractFromTaggedTemplate(node, config = DEFAULT_EXTRACTOR_CONFIG) {
|
|
235
278
|
const tagName = getCalleeName(node.tag);
|
|
236
279
|
if (!tagName || !config.tags.includes(tagName)) return [];
|
|
237
|
-
return extractFromTemplateLiteral(node.quasi);
|
|
280
|
+
return withOrigin(extractFromTemplateLiteral(node.quasi), "template-tag");
|
|
238
281
|
}
|
|
239
282
|
/**
|
|
240
283
|
* Extracts class string values from an ObjectExpression in a JSX attribute.
|
|
@@ -371,7 +414,7 @@ function extractFromVariableDeclarator(node, config = DEFAULT_EXTRACTOR_CONFIG)
|
|
|
371
414
|
if (node.id.type !== "Identifier") return [];
|
|
372
415
|
if (!config.variablePatterns.some((p) => p.test(node.id.name))) return [];
|
|
373
416
|
if (!node.init) return [];
|
|
374
|
-
return extractFromExpression(node.init);
|
|
417
|
+
return withOrigin(extractFromExpression(node.init), "variable");
|
|
375
418
|
}
|
|
376
419
|
/**
|
|
377
420
|
* Walk an expression and append every class-bearing location to `out`.
|
|
@@ -6323,6 +6366,7 @@ const noDarkWithoutLight = defineRule({
|
|
|
6323
6366
|
const ds = softGetDS(getDS);
|
|
6324
6367
|
const cache = ds ? ds.cache : null;
|
|
6325
6368
|
for (const loc of locations) {
|
|
6369
|
+
if (!isFinalClassList(loc)) continue;
|
|
6326
6370
|
const classes = splitClasses(loc.value);
|
|
6327
6371
|
if (cache && ds) {
|
|
6328
6372
|
let unresolved = null;
|
|
@@ -6583,6 +6627,7 @@ const noContradictingVariants = defineRule({
|
|
|
6583
6627
|
function check(locations) {
|
|
6584
6628
|
const factsFor = variantFactsLookup();
|
|
6585
6629
|
for (const loc of locations) {
|
|
6630
|
+
if (!isFinalClassList(loc)) continue;
|
|
6586
6631
|
const classes = splitClasses(loc.value);
|
|
6587
6632
|
const baseUtilities = /* @__PURE__ */ new Set();
|
|
6588
6633
|
for (const cls of classes) if (extractVariants(cls).length === 0) baseUtilities.add(cls);
|