oxlint-tailwindcss 1.11.0 → 1.12.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 +30 -16
- package/dist/index.cjs +94 -31
- package/dist/index.mjs +94 -31
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
24 Tailwind CSS linting rules for [oxlint](https://oxc.rs/docs/guide/usage/linter). Built for
|
|
4
4
|
Tailwind CSS v4 with deterministic config, typo suggestions, and autofixes.
|
|
5
5
|
|
|
6
|
-
> **v1
|
|
6
|
+
> **v1** — Upgrading from v0.x? See the
|
|
7
7
|
> **[migration guide](https://oxlint-tailwindcss.pages.dev/migration/v0-to-v1)**. The headline
|
|
8
8
|
> change: `settings.tailwindcss.entryPoint` is now required.
|
|
9
9
|
|
|
@@ -222,17 +222,18 @@ Output:
|
|
|
222
222
|
|
|
223
223
|
If no entry point is configured, the DS-dependent rules (`no-unknown-classes`,
|
|
224
224
|
`no-conflicting-classes`, `enforce-canonical`, `enforce-sort-order`,
|
|
225
|
-
`no-unnecessary-arbitrary-value`, `prefer-theme-tokens`) emit a single
|
|
226
|
-
diagnostic per file with an actionable hint — no more silent skips.
|
|
227
|
-
tolerates a missing entryPoint (its static fallback is itself
|
|
228
|
-
`no-deprecated-classes`
|
|
229
|
-
map
|
|
225
|
+
`no-unnecessary-arbitrary-value`, `prefer-scale-token`, `prefer-theme-tokens`) emit a single
|
|
226
|
+
`designSystemUnavailable` diagnostic per file with an actionable hint — no more silent skips.
|
|
227
|
+
`consistent-variant-order` tolerates a missing entryPoint (its static fallback is itself
|
|
228
|
+
deterministic), and `no-deprecated-classes` tolerates one too — it falls back to a hardcoded v3→v4
|
|
229
|
+
rename map, and derives a richer map from the design system when an entry point is configured. All
|
|
230
|
+
non-DS rules work without an entry point.
|
|
230
231
|
|
|
231
232
|
## Custom class detection
|
|
232
233
|
|
|
233
234
|
By default the plugin detects Tailwind classes in `className`/`class` attributes, 14 utility
|
|
234
|
-
functions (`cn`, `clsx`, `cva`, `tv`, `classed`, etc.), `tw` tagged templates, and variables
|
|
235
|
-
`className`/`classes`/`style`.
|
|
235
|
+
functions (`cn`, `clsx`, `cva`, `tv`, `classed`, etc.), `tw` tagged templates, and variables whose
|
|
236
|
+
names match `className`/`classNames`/`classes`/`style`/`styles`.
|
|
236
237
|
|
|
237
238
|
You can extend these defaults via `settings.tailwindcss`. All values are **additive** — your custom
|
|
238
239
|
entries are appended to the built-in defaults:
|
|
@@ -528,6 +529,9 @@ unconditionally.
|
|
|
528
529
|
<div className="hover:flex dark:flex" />
|
|
529
530
|
<div className="absolute after:absolute" />
|
|
530
531
|
<div className="shrink-0 [&>svg]:shrink-0" />
|
|
532
|
+
|
|
533
|
+
// ✅ OK — responsive reset: lg:block restores display after md:hidden removed it
|
|
534
|
+
<div className="block md:hidden lg:block" />
|
|
531
535
|
```
|
|
532
536
|
|
|
533
537
|
Only flags when the exact same utility exists both as base and with a conditional variant. Variants
|
|
@@ -539,7 +543,14 @@ are not flagged.
|
|
|
539
543
|
are override fragments where the "redundant" variant is often load-bearing (it beats a same-group
|
|
540
544
|
class the component merges in), so they are skipped to avoid false positives.
|
|
541
545
|
|
|
542
|
-
**
|
|
546
|
+
**Responsive resets (issue #150):** the base only "applies unconditionally" if nothing else
|
|
547
|
+
overrides its property. A variant that re-establishes a property an intermediate class took away
|
|
548
|
+
(`lg:block` after `md:hidden`) is load-bearing and not flagged. With an `entryPoint` this uses the
|
|
549
|
+
CSS properties the design system reports (any property); without one it falls back to the closed
|
|
550
|
+
`display`/`visibility` groups.
|
|
551
|
+
|
|
552
|
+
**Options:** `entryPoint` (per-rule override of `settings.tailwindcss.entryPoint`; optional — the
|
|
553
|
+
rule is DS-optional and never reports a missing design system). **No autofix.**
|
|
543
554
|
|
|
544
555
|
---
|
|
545
556
|
|
|
@@ -705,8 +716,9 @@ Handles variants correctly — the `!` is placed on the utility, not the variant
|
|
|
705
716
|
| `position` | `"prefix"` \| `"suffix"` | `"suffix"` | Where to place the `!` modifier |
|
|
706
717
|
|
|
707
718
|
> **Note:** The default is `"suffix"` to match Tailwind CSS v4's canonical form. The prefix form
|
|
708
|
-
> (`!flex`) is
|
|
709
|
-
>
|
|
719
|
+
> (`!flex`) is the v3 spelling. `enforce-canonical` preserves whatever `!` position you write (it
|
|
720
|
+
> does not normalize it), so this rule is the single source of truth for `!` placement and the two
|
|
721
|
+
> never conflict.
|
|
710
722
|
|
|
711
723
|
**Autofix:** Moves `!` to the correct position.
|
|
712
724
|
|
|
@@ -827,12 +839,14 @@ Warns when a class string exceeds the configured print width or classes-per-line
|
|
|
827
839
|
|
|
828
840
|
**Options:**
|
|
829
841
|
|
|
830
|
-
| Option | Type
|
|
831
|
-
| ---------------- |
|
|
832
|
-
| `printWidth` | `number`
|
|
833
|
-
| `classesPerLine` | `number`
|
|
842
|
+
| Option | Type | Default | Description |
|
|
843
|
+
| ---------------- | ------------------------------------- | ----------- | ------------------------------------------------------------------- |
|
|
844
|
+
| `printWidth` | `number` | `80` | Max class string length |
|
|
845
|
+
| `classesPerLine` | `number` | | Max classes per line |
|
|
846
|
+
| `wrapLines` | `'overWidth' \| 'all'` | | Re-wrap lines: only over-width, or always into the canonical layout |
|
|
847
|
+
| `group` | `'newLine' \| 'emptyLine' \| 'never'` | `'newLine'` | How the `wrapLines: 'all'` layout separates variant groups |
|
|
834
848
|
|
|
835
|
-
**Autofix:**
|
|
849
|
+
**Autofix:** `classesPerLine` and `wrapLines` re-wrap template literals; `printWidth` is warn-only.
|
|
836
850
|
|
|
837
851
|
---
|
|
838
852
|
|
package/dist/index.cjs
CHANGED
|
@@ -897,6 +897,39 @@ function reattachImportant(bare, position) {
|
|
|
897
897
|
if (position === "suffix") return `${bare}!`;
|
|
898
898
|
return bare;
|
|
899
899
|
}
|
|
900
|
+
const EXPLICIT_VAR_RE = /^([a-z][a-z0-9-]*(?:-[a-z0-9]+)*)-\[var\((--[a-zA-Z0-9-]+)\)\]$/;
|
|
901
|
+
const SHORTHAND_VAR_RE = /^([a-z][a-z0-9-]*(?:-[a-z0-9]+)*)-\((--[a-zA-Z0-9-]+)\)$/;
|
|
902
|
+
/**
|
|
903
|
+
* Convert a class between the two CSS-variable syntaxes:
|
|
904
|
+
* `bg-[var(--x)]` (explicit) ↔ `bg-(--x)` (shorthand). Returns the converted
|
|
905
|
+
* class, or `null` when it isn't a simple single-variable utility.
|
|
906
|
+
*
|
|
907
|
+
* Deliberately narrow — it matches ONLY the bare-bracket form, so compound
|
|
908
|
+
* expressions (`bg-[color-mix(...)]`) and opacity-modifier forms
|
|
909
|
+
* (`text-[var(--c)]/90`, whose trailing `/90` fails the `$` anchor) return
|
|
910
|
+
* `null`. Variants and `!` position round-trip via `splitUtilityAndVariant` /
|
|
911
|
+
* `splitImportant`. This is the single set of classes over which
|
|
912
|
+
* `enforce-consistent-variable-syntax` (which owns the policy) and
|
|
913
|
+
* `enforce-canonical` (which cedes it) overlap, so both consume this one helper.
|
|
914
|
+
*/
|
|
915
|
+
function convertVarSyntax(cls, syntax) {
|
|
916
|
+
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
917
|
+
const { bare: bareUtility, position } = splitImportant(utility);
|
|
918
|
+
if (syntax === "shorthand") {
|
|
919
|
+
const match = EXPLICIT_VAR_RE.exec(bareUtility);
|
|
920
|
+
if (match) {
|
|
921
|
+
const [, prefix, varName] = match;
|
|
922
|
+
return `${variant}${reattachImportant(`${prefix}-(${varName})`, position)}`;
|
|
923
|
+
}
|
|
924
|
+
} else {
|
|
925
|
+
const match = SHORTHAND_VAR_RE.exec(bareUtility);
|
|
926
|
+
if (match) {
|
|
927
|
+
const [, prefix, varName] = match;
|
|
928
|
+
return `${variant}${reattachImportant(`${prefix}-[var(${varName})]`, position)}`;
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
return null;
|
|
932
|
+
}
|
|
900
933
|
/**
|
|
901
934
|
* Pseudo-element variants, as a static fallback for when no design system is
|
|
902
935
|
* configured. They select a generated box (`::before`, `::marker`, …) rather than
|
|
@@ -5273,7 +5306,13 @@ const enforceCanonical = defineRule({
|
|
|
5273
5306
|
if (!dynamic) return;
|
|
5274
5307
|
for (let k = 0; k < arbitrary.length; k++) {
|
|
5275
5308
|
const { canonical, safe } = dynamic[k];
|
|
5276
|
-
|
|
5309
|
+
const idx = arbitraryIdx[k];
|
|
5310
|
+
if (!safe) {
|
|
5311
|
+
canonicals[idx] = arbitrary[k];
|
|
5312
|
+
continue;
|
|
5313
|
+
}
|
|
5314
|
+
const preserved = preserveImportantPosition(arbitrary[k], canonical);
|
|
5315
|
+
canonicals[idx] = convertVarSyntax(arbitrary[k], "shorthand") === preserved ? arbitrary[k] : preserved;
|
|
5277
5316
|
}
|
|
5278
5317
|
}
|
|
5279
5318
|
reportClassReplacements(context, loc, split, classes, classes.flatMap((cls, i) => canonicals[i] === cls ? [] : [{
|
|
@@ -6197,7 +6236,7 @@ const noArbitraryValue = defineRule({
|
|
|
6197
6236
|
const enforceConsistentImportantPosition = defineRule({
|
|
6198
6237
|
meta: {
|
|
6199
6238
|
type: "suggestion",
|
|
6200
|
-
docs: { description: "Enforce consistent position of the important (!) modifier. Default: suffix (Tailwind v4 canonical form).
|
|
6239
|
+
docs: { description: "Enforce consistent position of the important (!) modifier. Default: suffix (Tailwind v4 canonical form). This rule is the single source of truth for ! placement — enforce-canonical preserves the position you wrote, so the two never conflict." },
|
|
6201
6240
|
fixable: "code",
|
|
6202
6241
|
schema: [{
|
|
6203
6242
|
type: "object",
|
|
@@ -6295,26 +6334,6 @@ const enforceNegativeArbitraryValues = defineRule({
|
|
|
6295
6334
|
});
|
|
6296
6335
|
//#endregion
|
|
6297
6336
|
//#region src/rules/enforce-consistent-variable-syntax.ts
|
|
6298
|
-
const EXPLICIT_VAR_RE = /^([a-z][a-z0-9-]*(?:-[a-z0-9]+)*)-\[var\((--[a-zA-Z0-9-]+)\)\]$/;
|
|
6299
|
-
const SHORTHAND_VAR_RE = /^([a-z][a-z0-9-]*(?:-[a-z0-9]+)*)-\((--[a-zA-Z0-9-]+)\)$/;
|
|
6300
|
-
function convertClass(cls, syntax) {
|
|
6301
|
-
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
6302
|
-
const { bare: bareUtility, position } = splitImportant(utility);
|
|
6303
|
-
if (syntax === "shorthand") {
|
|
6304
|
-
const match = EXPLICIT_VAR_RE.exec(bareUtility);
|
|
6305
|
-
if (match) {
|
|
6306
|
-
const [, prefix, varName] = match;
|
|
6307
|
-
return `${variant}${reattachImportant(`${prefix}-(${varName})`, position)}`;
|
|
6308
|
-
}
|
|
6309
|
-
} else {
|
|
6310
|
-
const match = SHORTHAND_VAR_RE.exec(bareUtility);
|
|
6311
|
-
if (match) {
|
|
6312
|
-
const [, prefix, varName] = match;
|
|
6313
|
-
return `${variant}${reattachImportant(`${prefix}-[var(${varName})]`, position)}`;
|
|
6314
|
-
}
|
|
6315
|
-
}
|
|
6316
|
-
return null;
|
|
6317
|
-
}
|
|
6318
6337
|
const enforceConsistentVariableSyntax = defineRule({
|
|
6319
6338
|
meta: {
|
|
6320
6339
|
type: "suggestion",
|
|
@@ -6344,7 +6363,7 @@ const enforceConsistentVariableSyntax = defineRule({
|
|
|
6344
6363
|
for (const loc of locations) {
|
|
6345
6364
|
const split = splitClassesWithSeparators(loc.value);
|
|
6346
6365
|
const offending = split.classes.flatMap((cls) => {
|
|
6347
|
-
const converted =
|
|
6366
|
+
const converted = convertVarSyntax(cls, syntax);
|
|
6348
6367
|
return converted ? [{
|
|
6349
6368
|
cls,
|
|
6350
6369
|
replacement: converted
|
|
@@ -6703,6 +6722,32 @@ const noHardcodedColors = defineRule({
|
|
|
6703
6722
|
});
|
|
6704
6723
|
//#endregion
|
|
6705
6724
|
//#region src/rules/no-contradicting-variants.ts
|
|
6725
|
+
const STATIC_PROP_GROUPS = /* @__PURE__ */ new Map([
|
|
6726
|
+
["block", "display"],
|
|
6727
|
+
["inline-block", "display"],
|
|
6728
|
+
["inline", "display"],
|
|
6729
|
+
["flex", "display"],
|
|
6730
|
+
["inline-flex", "display"],
|
|
6731
|
+
["grid", "display"],
|
|
6732
|
+
["inline-grid", "display"],
|
|
6733
|
+
["table", "display"],
|
|
6734
|
+
["inline-table", "display"],
|
|
6735
|
+
["table-caption", "display"],
|
|
6736
|
+
["table-cell", "display"],
|
|
6737
|
+
["table-column", "display"],
|
|
6738
|
+
["table-column-group", "display"],
|
|
6739
|
+
["table-footer-group", "display"],
|
|
6740
|
+
["table-header-group", "display"],
|
|
6741
|
+
["table-row-group", "display"],
|
|
6742
|
+
["table-row", "display"],
|
|
6743
|
+
["flow-root", "display"],
|
|
6744
|
+
["contents", "display"],
|
|
6745
|
+
["list-item", "display"],
|
|
6746
|
+
["hidden", "display"],
|
|
6747
|
+
["visible", "visibility"],
|
|
6748
|
+
["invisible", "visibility"],
|
|
6749
|
+
["collapse", "visibility"]
|
|
6750
|
+
]);
|
|
6706
6751
|
const noContradictingVariants = defineRule({
|
|
6707
6752
|
meta: {
|
|
6708
6753
|
type: "suggestion",
|
|
@@ -6717,24 +6762,42 @@ const noContradictingVariants = defineRule({
|
|
|
6717
6762
|
},
|
|
6718
6763
|
createOnce(context) {
|
|
6719
6764
|
const getDS = createLazyLoader(context);
|
|
6720
|
-
function variantFactsLookup() {
|
|
6721
|
-
const ds = softGetDS(getDS);
|
|
6722
|
-
if (!ds) return () => void 0;
|
|
6723
|
-
return (variant) => ds.cache.getVariantFacts(variant);
|
|
6724
|
-
}
|
|
6725
6765
|
function check(locations) {
|
|
6726
|
-
const
|
|
6766
|
+
const ds = softGetDS(getDS);
|
|
6767
|
+
const cache = ds ? ds.cache : null;
|
|
6768
|
+
const factsFor = (v) => ds ? ds.cache.getVariantFacts(v) : void 0;
|
|
6769
|
+
const propsOf = (bare) => {
|
|
6770
|
+
if (cache) {
|
|
6771
|
+
const props = cache.getCssProperties(bare);
|
|
6772
|
+
if (props.length > 0) return props;
|
|
6773
|
+
}
|
|
6774
|
+
const group = STATIC_PROP_GROUPS.get(bare);
|
|
6775
|
+
return group ? [group] : [];
|
|
6776
|
+
};
|
|
6727
6777
|
for (const loc of locations) {
|
|
6728
6778
|
if (!isFinalClassList(loc)) continue;
|
|
6729
6779
|
const classes = splitClasses(loc.value);
|
|
6730
6780
|
const baseUtilities = /* @__PURE__ */ new Set();
|
|
6731
6781
|
for (const cls of classes) if (extractVariants(cls).length === 0) baseUtilities.add(cls);
|
|
6732
|
-
for (
|
|
6782
|
+
for (let i = 0; i < classes.length; i++) {
|
|
6783
|
+
const cls = classes[i];
|
|
6733
6784
|
const variants = extractVariants(cls);
|
|
6734
6785
|
if (variants.length === 0) continue;
|
|
6735
6786
|
if (variants.some((v) => changesTarget(v, factsFor(v)))) continue;
|
|
6736
6787
|
const utility = extractUtility(cls);
|
|
6737
|
-
if (baseUtilities.has(utility))
|
|
6788
|
+
if (!baseUtilities.has(utility)) continue;
|
|
6789
|
+
const bare = splitImportant(utility).bare;
|
|
6790
|
+
const candidateProps = propsOf(bare);
|
|
6791
|
+
if (candidateProps.length > 0) {
|
|
6792
|
+
if (classes.some((other, j) => {
|
|
6793
|
+
if (j === i) return false;
|
|
6794
|
+
if (extractVariants(other).some((v) => changesTarget(v, factsFor(v)))) return false;
|
|
6795
|
+
const otherBare = splitImportant(extractUtility(other)).bare;
|
|
6796
|
+
if (otherBare === bare) return false;
|
|
6797
|
+
return propsOf(otherBare).some((p) => candidateProps.includes(p));
|
|
6798
|
+
})) continue;
|
|
6799
|
+
}
|
|
6800
|
+
context.report({
|
|
6738
6801
|
node: loc.node,
|
|
6739
6802
|
messageId: "redundantVariant",
|
|
6740
6803
|
data: {
|
package/dist/index.mjs
CHANGED
|
@@ -901,6 +901,39 @@ function reattachImportant(bare, position) {
|
|
|
901
901
|
if (position === "suffix") return `${bare}!`;
|
|
902
902
|
return bare;
|
|
903
903
|
}
|
|
904
|
+
const EXPLICIT_VAR_RE = /^([a-z][a-z0-9-]*(?:-[a-z0-9]+)*)-\[var\((--[a-zA-Z0-9-]+)\)\]$/;
|
|
905
|
+
const SHORTHAND_VAR_RE = /^([a-z][a-z0-9-]*(?:-[a-z0-9]+)*)-\((--[a-zA-Z0-9-]+)\)$/;
|
|
906
|
+
/**
|
|
907
|
+
* Convert a class between the two CSS-variable syntaxes:
|
|
908
|
+
* `bg-[var(--x)]` (explicit) ↔ `bg-(--x)` (shorthand). Returns the converted
|
|
909
|
+
* class, or `null` when it isn't a simple single-variable utility.
|
|
910
|
+
*
|
|
911
|
+
* Deliberately narrow — it matches ONLY the bare-bracket form, so compound
|
|
912
|
+
* expressions (`bg-[color-mix(...)]`) and opacity-modifier forms
|
|
913
|
+
* (`text-[var(--c)]/90`, whose trailing `/90` fails the `$` anchor) return
|
|
914
|
+
* `null`. Variants and `!` position round-trip via `splitUtilityAndVariant` /
|
|
915
|
+
* `splitImportant`. This is the single set of classes over which
|
|
916
|
+
* `enforce-consistent-variable-syntax` (which owns the policy) and
|
|
917
|
+
* `enforce-canonical` (which cedes it) overlap, so both consume this one helper.
|
|
918
|
+
*/
|
|
919
|
+
function convertVarSyntax(cls, syntax) {
|
|
920
|
+
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
921
|
+
const { bare: bareUtility, position } = splitImportant(utility);
|
|
922
|
+
if (syntax === "shorthand") {
|
|
923
|
+
const match = EXPLICIT_VAR_RE.exec(bareUtility);
|
|
924
|
+
if (match) {
|
|
925
|
+
const [, prefix, varName] = match;
|
|
926
|
+
return `${variant}${reattachImportant(`${prefix}-(${varName})`, position)}`;
|
|
927
|
+
}
|
|
928
|
+
} else {
|
|
929
|
+
const match = SHORTHAND_VAR_RE.exec(bareUtility);
|
|
930
|
+
if (match) {
|
|
931
|
+
const [, prefix, varName] = match;
|
|
932
|
+
return `${variant}${reattachImportant(`${prefix}-[var(${varName})]`, position)}`;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
return null;
|
|
936
|
+
}
|
|
904
937
|
/**
|
|
905
938
|
* Pseudo-element variants, as a static fallback for when no design system is
|
|
906
939
|
* configured. They select a generated box (`::before`, `::marker`, …) rather than
|
|
@@ -5277,7 +5310,13 @@ const enforceCanonical = defineRule({
|
|
|
5277
5310
|
if (!dynamic) return;
|
|
5278
5311
|
for (let k = 0; k < arbitrary.length; k++) {
|
|
5279
5312
|
const { canonical, safe } = dynamic[k];
|
|
5280
|
-
|
|
5313
|
+
const idx = arbitraryIdx[k];
|
|
5314
|
+
if (!safe) {
|
|
5315
|
+
canonicals[idx] = arbitrary[k];
|
|
5316
|
+
continue;
|
|
5317
|
+
}
|
|
5318
|
+
const preserved = preserveImportantPosition(arbitrary[k], canonical);
|
|
5319
|
+
canonicals[idx] = convertVarSyntax(arbitrary[k], "shorthand") === preserved ? arbitrary[k] : preserved;
|
|
5281
5320
|
}
|
|
5282
5321
|
}
|
|
5283
5322
|
reportClassReplacements(context, loc, split, classes, classes.flatMap((cls, i) => canonicals[i] === cls ? [] : [{
|
|
@@ -6201,7 +6240,7 @@ const noArbitraryValue = defineRule({
|
|
|
6201
6240
|
const enforceConsistentImportantPosition = defineRule({
|
|
6202
6241
|
meta: {
|
|
6203
6242
|
type: "suggestion",
|
|
6204
|
-
docs: { description: "Enforce consistent position of the important (!) modifier. Default: suffix (Tailwind v4 canonical form).
|
|
6243
|
+
docs: { description: "Enforce consistent position of the important (!) modifier. Default: suffix (Tailwind v4 canonical form). This rule is the single source of truth for ! placement — enforce-canonical preserves the position you wrote, so the two never conflict." },
|
|
6205
6244
|
fixable: "code",
|
|
6206
6245
|
schema: [{
|
|
6207
6246
|
type: "object",
|
|
@@ -6299,26 +6338,6 @@ const enforceNegativeArbitraryValues = defineRule({
|
|
|
6299
6338
|
});
|
|
6300
6339
|
//#endregion
|
|
6301
6340
|
//#region src/rules/enforce-consistent-variable-syntax.ts
|
|
6302
|
-
const EXPLICIT_VAR_RE = /^([a-z][a-z0-9-]*(?:-[a-z0-9]+)*)-\[var\((--[a-zA-Z0-9-]+)\)\]$/;
|
|
6303
|
-
const SHORTHAND_VAR_RE = /^([a-z][a-z0-9-]*(?:-[a-z0-9]+)*)-\((--[a-zA-Z0-9-]+)\)$/;
|
|
6304
|
-
function convertClass(cls, syntax) {
|
|
6305
|
-
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
6306
|
-
const { bare: bareUtility, position } = splitImportant(utility);
|
|
6307
|
-
if (syntax === "shorthand") {
|
|
6308
|
-
const match = EXPLICIT_VAR_RE.exec(bareUtility);
|
|
6309
|
-
if (match) {
|
|
6310
|
-
const [, prefix, varName] = match;
|
|
6311
|
-
return `${variant}${reattachImportant(`${prefix}-(${varName})`, position)}`;
|
|
6312
|
-
}
|
|
6313
|
-
} else {
|
|
6314
|
-
const match = SHORTHAND_VAR_RE.exec(bareUtility);
|
|
6315
|
-
if (match) {
|
|
6316
|
-
const [, prefix, varName] = match;
|
|
6317
|
-
return `${variant}${reattachImportant(`${prefix}-[var(${varName})]`, position)}`;
|
|
6318
|
-
}
|
|
6319
|
-
}
|
|
6320
|
-
return null;
|
|
6321
|
-
}
|
|
6322
6341
|
const enforceConsistentVariableSyntax = defineRule({
|
|
6323
6342
|
meta: {
|
|
6324
6343
|
type: "suggestion",
|
|
@@ -6348,7 +6367,7 @@ const enforceConsistentVariableSyntax = defineRule({
|
|
|
6348
6367
|
for (const loc of locations) {
|
|
6349
6368
|
const split = splitClassesWithSeparators(loc.value);
|
|
6350
6369
|
const offending = split.classes.flatMap((cls) => {
|
|
6351
|
-
const converted =
|
|
6370
|
+
const converted = convertVarSyntax(cls, syntax);
|
|
6352
6371
|
return converted ? [{
|
|
6353
6372
|
cls,
|
|
6354
6373
|
replacement: converted
|
|
@@ -6707,6 +6726,32 @@ const noHardcodedColors = defineRule({
|
|
|
6707
6726
|
});
|
|
6708
6727
|
//#endregion
|
|
6709
6728
|
//#region src/rules/no-contradicting-variants.ts
|
|
6729
|
+
const STATIC_PROP_GROUPS = /* @__PURE__ */ new Map([
|
|
6730
|
+
["block", "display"],
|
|
6731
|
+
["inline-block", "display"],
|
|
6732
|
+
["inline", "display"],
|
|
6733
|
+
["flex", "display"],
|
|
6734
|
+
["inline-flex", "display"],
|
|
6735
|
+
["grid", "display"],
|
|
6736
|
+
["inline-grid", "display"],
|
|
6737
|
+
["table", "display"],
|
|
6738
|
+
["inline-table", "display"],
|
|
6739
|
+
["table-caption", "display"],
|
|
6740
|
+
["table-cell", "display"],
|
|
6741
|
+
["table-column", "display"],
|
|
6742
|
+
["table-column-group", "display"],
|
|
6743
|
+
["table-footer-group", "display"],
|
|
6744
|
+
["table-header-group", "display"],
|
|
6745
|
+
["table-row-group", "display"],
|
|
6746
|
+
["table-row", "display"],
|
|
6747
|
+
["flow-root", "display"],
|
|
6748
|
+
["contents", "display"],
|
|
6749
|
+
["list-item", "display"],
|
|
6750
|
+
["hidden", "display"],
|
|
6751
|
+
["visible", "visibility"],
|
|
6752
|
+
["invisible", "visibility"],
|
|
6753
|
+
["collapse", "visibility"]
|
|
6754
|
+
]);
|
|
6710
6755
|
const noContradictingVariants = defineRule({
|
|
6711
6756
|
meta: {
|
|
6712
6757
|
type: "suggestion",
|
|
@@ -6721,24 +6766,42 @@ const noContradictingVariants = defineRule({
|
|
|
6721
6766
|
},
|
|
6722
6767
|
createOnce(context) {
|
|
6723
6768
|
const getDS = createLazyLoader(context);
|
|
6724
|
-
function variantFactsLookup() {
|
|
6725
|
-
const ds = softGetDS(getDS);
|
|
6726
|
-
if (!ds) return () => void 0;
|
|
6727
|
-
return (variant) => ds.cache.getVariantFacts(variant);
|
|
6728
|
-
}
|
|
6729
6769
|
function check(locations) {
|
|
6730
|
-
const
|
|
6770
|
+
const ds = softGetDS(getDS);
|
|
6771
|
+
const cache = ds ? ds.cache : null;
|
|
6772
|
+
const factsFor = (v) => ds ? ds.cache.getVariantFacts(v) : void 0;
|
|
6773
|
+
const propsOf = (bare) => {
|
|
6774
|
+
if (cache) {
|
|
6775
|
+
const props = cache.getCssProperties(bare);
|
|
6776
|
+
if (props.length > 0) return props;
|
|
6777
|
+
}
|
|
6778
|
+
const group = STATIC_PROP_GROUPS.get(bare);
|
|
6779
|
+
return group ? [group] : [];
|
|
6780
|
+
};
|
|
6731
6781
|
for (const loc of locations) {
|
|
6732
6782
|
if (!isFinalClassList(loc)) continue;
|
|
6733
6783
|
const classes = splitClasses(loc.value);
|
|
6734
6784
|
const baseUtilities = /* @__PURE__ */ new Set();
|
|
6735
6785
|
for (const cls of classes) if (extractVariants(cls).length === 0) baseUtilities.add(cls);
|
|
6736
|
-
for (
|
|
6786
|
+
for (let i = 0; i < classes.length; i++) {
|
|
6787
|
+
const cls = classes[i];
|
|
6737
6788
|
const variants = extractVariants(cls);
|
|
6738
6789
|
if (variants.length === 0) continue;
|
|
6739
6790
|
if (variants.some((v) => changesTarget(v, factsFor(v)))) continue;
|
|
6740
6791
|
const utility = extractUtility(cls);
|
|
6741
|
-
if (baseUtilities.has(utility))
|
|
6792
|
+
if (!baseUtilities.has(utility)) continue;
|
|
6793
|
+
const bare = splitImportant(utility).bare;
|
|
6794
|
+
const candidateProps = propsOf(bare);
|
|
6795
|
+
if (candidateProps.length > 0) {
|
|
6796
|
+
if (classes.some((other, j) => {
|
|
6797
|
+
if (j === i) return false;
|
|
6798
|
+
if (extractVariants(other).some((v) => changesTarget(v, factsFor(v)))) return false;
|
|
6799
|
+
const otherBare = splitImportant(extractUtility(other)).bare;
|
|
6800
|
+
if (otherBare === bare) return false;
|
|
6801
|
+
return propsOf(otherBare).some((p) => candidateProps.includes(p));
|
|
6802
|
+
})) continue;
|
|
6803
|
+
}
|
|
6804
|
+
context.report({
|
|
6742
6805
|
node: loc.node,
|
|
6743
6806
|
messageId: "redundantVariant",
|
|
6744
6807
|
data: {
|