oxlint-tailwindcss 1.4.0 → 1.5.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.
Files changed (3) hide show
  1. package/dist/index.cjs +1071 -472
  2. package/dist/index.mjs +1071 -472
  3. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -735,6 +735,18 @@ function utilityHasDynamicValue(cls) {
735
735
  return utility.includes("[") || utility.includes("(");
736
736
  }
737
737
  /**
738
+ * A utility the precompute cannot have enumerated, because the VALUE comes from
739
+ * the user rather than from the design system's class list: arbitrary brackets,
740
+ * the `(--var)` shorthand, a `/` modifier, or an off-scale number.
741
+ *
742
+ * Asking the design system about exactly these is what closes the "looks like
743
+ * coverage" false negatives — `p-4 p-[5px]` used to be accepted silently while
744
+ * `p-4 p-6` reported. Takes the bare utility (no variants, no `!`).
745
+ */
746
+ function isUserValued(utility) {
747
+ return utility.includes("[") || utility.includes("(") || utility.includes("/") || /-\d/.test(utility);
748
+ }
749
+ /**
738
750
  * Gets the arbitrary value from a class, or null if none.
739
751
  * e.g. "w-[200px]" → "200px"
740
752
  * "bg-[#ff0000]" → "#ff0000"
@@ -953,6 +965,7 @@ function roundRemValue(className) {
953
965
  const EMPTY_DECLARATIONS = [];
954
966
  var DesignSystemCache = class DesignSystemCache {
955
967
  canonicalMap = /* @__PURE__ */ new Map();
968
+ deprecatedMap = /* @__PURE__ */ new Map();
956
969
  validitySet = /* @__PURE__ */ new Set();
957
970
  orderMap = /* @__PURE__ */ new Map();
958
971
  declIndex = null;
@@ -976,6 +989,7 @@ var DesignSystemCache = class DesignSystemCache {
976
989
  cache._validClasses = data.validClasses;
977
990
  for (const cls of data.validClasses) cache.validitySet.add(cls);
978
991
  for (const [from, to] of Object.entries(data.canonical)) cache.canonicalMap.set(from, roundRemValue(to));
992
+ if (data.deprecated) for (const [from, to] of Object.entries(data.deprecated)) cache.deprecatedMap.set(from, to);
979
993
  for (const [cls, val] of Object.entries(data.order)) {
980
994
  const order = BigInt(val);
981
995
  cache.orderMap.set(cls, order);
@@ -1030,6 +1044,24 @@ var DesignSystemCache = class DesignSystemCache {
1030
1044
  return className;
1031
1045
  }
1032
1046
  /**
1047
+ * The v4 name of a class Tailwind renamed, or `null` if it isn't a renamed
1048
+ * spelling. Takes the BARE utility (no variants, no `!`) — the caller has
1049
+ * already split those off to rebuild the replacement around them.
1050
+ *
1051
+ * Derived by the precompute from what `canonicalizeCandidates` reports for the
1052
+ * v3 spellings, rather than from a map maintained by hand. Two rules read it:
1053
+ * `no-deprecated-classes`, which owns the diagnostic, and `enforce-canonical`,
1054
+ * which stays quiet about these so one class doesn't produce two identical
1055
+ * rewrites.
1056
+ */
1057
+ deprecatedReplacement(bareUtility) {
1058
+ return this.deprecatedMap.get(this.stripProjectPrefix(bareUtility)) ?? null;
1059
+ }
1060
+ /** Whether the precompute produced a deprecation map at all (older artifacts didn't). */
1061
+ get hasDeprecatedMap() {
1062
+ return this.deprecatedMap.size > 0;
1063
+ }
1064
+ /**
1033
1065
  * Resolve a variant name to its priority in the CSS output order.
1034
1066
  * Named variants use the precomputed map. Arbitrary variants use pattern-based heuristics
1035
1067
  * to approximate their position relative to named variants.
@@ -1088,6 +1120,23 @@ var DesignSystemCache = class DesignSystemCache {
1088
1120
  }
1089
1121
  return this._knownPrefixes;
1090
1122
  }
1123
+ /**
1124
+ * Is this class name in the precomputed set VERBATIM?
1125
+ *
1126
+ * `isValid` is deliberately tolerant: it accepts anything shaped like a dynamic
1127
+ * value (`w-45`, `bg-red-5000`, `bg-red-500/foo`) because there used to be no
1128
+ * way to ask the design system at lint time. That tolerance is what let
1129
+ * `no-unknown-classes` accept classes Tailwind compiles to nothing. This is the
1130
+ * exact answer, so a rule can tell "known to produce CSS" from "shaped like it
1131
+ * might" and ask the design system about the difference.
1132
+ */
1133
+ isKnownClass(className) {
1134
+ return this.validitySet.has(this.stripProjectPrefix(className));
1135
+ }
1136
+ /** Variant names the design system reports, for suggesting a typo's neighbour. */
1137
+ variantNames() {
1138
+ return [...this.variantOrderMap.keys()];
1139
+ }
1091
1140
  isValid(className) {
1092
1141
  if (this.validitySet.has(className)) return true;
1093
1142
  const utility = extractUtility(className);
@@ -1425,6 +1474,29 @@ function safeGetDS(getDS, context, node) {
1425
1474
  throw err;
1426
1475
  }
1427
1476
  }
1477
+ /**
1478
+ * `safeGetDS`'s quiet sibling, for the DS-OPTIONAL rules.
1479
+ *
1480
+ * A handful of rules work without a design system — their static fallback is
1481
+ * itself deterministic (`consistent-variant-order`'s variant table,
1482
+ * `no-dark-without-light`'s prefix grouping) — and an entry point only makes
1483
+ * them more accurate. Those rules must never emit `designSystemUnavailable`:
1484
+ * they were usable with no configuration before the DS lookup existed and have
1485
+ * to stay that way, or adding the lookup would break every project that runs
1486
+ * them without a CSS entry point.
1487
+ *
1488
+ * So: returns the load result, or `null` when the design system is unavailable
1489
+ * for a reason the plugin knows about. Non-fatal errors still propagate, since
1490
+ * those are bugs rather than missing configuration.
1491
+ */
1492
+ function softGetDS(getDS) {
1493
+ try {
1494
+ return getDS();
1495
+ } catch (err) {
1496
+ if (isFatalError(err)) return null;
1497
+ throw err;
1498
+ }
1499
+ }
1428
1500
  //#endregion
1429
1501
  //#region src/design-system/tailwind-node.ts
1430
1502
  /**
@@ -1934,11 +2006,17 @@ async function main() {
1934
2006
  // their v4 equivalent, so we feed them in explicitly. Without this pass,
1935
2007
  // classes like \`break-words\` would be invisible to enforce-canonical
1936
2008
  // (issue #16).
1937
- // - Fixed renames mirror the internal v3->v4 map in tailwindcss/canonicalize.
1938
- // - Pattern renames (start-* -> inset-s-*, end-* -> inset-e-*) are derived
1939
- // from the inset-{s,e}-* utilities present in validClasses so we cover
1940
- // every numeric/named value the design system exposes.
1941
- const legacyCandidates = [
2009
+ //
2010
+ // Two kinds, and the difference is what \`deprecated\` records:
2011
+ // - RENAMES: a v3 spelling of a utility v4 calls something else. Mirrors the
2012
+ // internal v3->v4 map in tailwindcss/canonicalize. These ARE deprecated, and
2013
+ // no-deprecated-classes owns them.
2014
+ // - Pattern renames (start-* -> inset-s-*, end-* -> inset-e-*), derived from
2015
+ // the inset-{s,e}-* utilities in validClasses so every numeric/named value is
2016
+ // covered. These are NOT deprecated: \`start-2\` is current Tailwind (it is
2017
+ // what the docs use), it just isn't the canonical spelling. Calling it
2018
+ // deprecated would be a lie, so only enforce-canonical speaks about it.
2019
+ const v3Renames = [
1942
2020
  'order-none',
1943
2021
  'break-words',
1944
2022
  'overflow-ellipsis',
@@ -1953,12 +2031,15 @@ async function main() {
1953
2031
  'bg-left-top', 'bg-right-top', 'bg-left-bottom', 'bg-right-bottom',
1954
2032
  'object-left-top', 'object-right-top', 'object-left-bottom', 'object-right-bottom',
1955
2033
  ];
2034
+ const renameSet = new Set(v3Renames);
2035
+ const legacyCandidates = [...v3Renames];
1956
2036
  for (const cls of validClasses) {
1957
2037
  if (cls.startsWith('inset-s-')) legacyCandidates.push('start-' + cls.slice(8));
1958
2038
  else if (cls.startsWith('-inset-s-')) legacyCandidates.push('-start-' + cls.slice(9));
1959
2039
  else if (cls.startsWith('inset-e-')) legacyCandidates.push('end-' + cls.slice(8));
1960
2040
  else if (cls.startsWith('-inset-e-')) legacyCandidates.push('-end-' + cls.slice(9));
1961
2041
  }
2042
+ const deprecated = {};
1962
2043
  const legacyToProcess = legacyCandidates.filter(cls => !validSet.has(cls));
1963
2044
  if (legacyToProcess.length > 0) {
1964
2045
  const legacyCssResults = ds.candidatesToCss(legacyToProcess.map(pfx));
@@ -1969,6 +2050,10 @@ async function main() {
1969
2050
  const canon = result[0] ? unpfx(result[0]) : null;
1970
2051
  if (canon && canon !== cls) {
1971
2052
  canonical[cls] = canon;
2053
+ // Only a v3 rename that this Tailwind still compiles AND still renames.
2054
+ // A release that drops either of those drops the entry, so the rule can
2055
+ // never suggest a replacement for a class that no longer exists.
2056
+ if (renameSet.has(cls)) deprecated[cls] = canon;
1972
2057
  }
1973
2058
  // Mark as valid so no-unknown-classes doesn't flag legacy spellings.
1974
2059
  validClasses.push(cls);
@@ -2245,7 +2330,7 @@ async function main() {
2245
2330
  }
2246
2331
  }
2247
2332
 
2248
- const json = JSON.stringify({ validClasses, canonical, order, cssDeclarations, variantOrder, variantFacts, componentClasses, arbitraryEquivalents, themeRefs, definedVars, prefix });
2333
+ const json = JSON.stringify({ validClasses, canonical, deprecated, order, cssDeclarations, variantOrder, variantFacts, componentClasses, arbitraryEquivalents, themeRefs, definedVars, prefix });
2249
2334
  // Atomic write: write to a unique temp path then rename, so a peer isolate
2250
2335
  // busy-waiting on the cache file never observes a half-written JSON.
2251
2336
  writeFileSync(WD_TMP_PATH, json);
@@ -2949,250 +3034,6 @@ function resolveEntryPointForFile(ruleOptionEntry, settingsEntry, filePath, cwd
2949
3034
  throw new MissingEntryPointError(`\`settings.tailwindcss.entryPoint\` is required${filePath ? ` (linting \`${filePath}\`)` : ""}.`, "Set it to a string (single-project) or an array of `{ files, use }` mappings (monorepo).");
2950
3035
  }
2951
3036
  //#endregion
2952
- //#region src/utils/report.ts
2953
- /**
2954
- * Shared reporter for the "first-as-fix, rest-as-suggestion" pattern.
2955
- *
2956
- * Nine rules (enforce-canonical, enforce-logical, enforce-physical,
2957
- * enforce-consistent-variable-syntax, enforce-consistent-important-position,
2958
- * enforce-negative-arbitrary-values, no-deprecated-classes,
2959
- * no-unnecessary-arbitrary-value, prefer-theme-tokens) all emit
2960
- * replacements via the same shape:
2961
- *
2962
- * 1. Collect `{ cls, replacement }` entries from a class string.
2963
- * 2. Rebuild the full class string with replacements applied.
2964
- * 3. Emit ONE diagnostic with the autofix attached.
2965
- * 4. Emit one MORE diagnostic per remaining offender, each carrying
2966
- * the same autofix as a `suggest`.
2967
- *
2968
- * oxlint's fixer is single-shot per AST node, so multiple offenders in the
2969
- * same class string can only get one mechanical fix; the rest stay as
2970
- * suggestions the IDE can offer interactively.
2971
- */
2972
- /**
2973
- * Emit autofix + suggestion diagnostics for a list of class replacements.
2974
- *
2975
- * If `offending` is empty, no-op. The fixer's `replaceTextRange` is shared
2976
- * across all diagnostics — the first one is the primary fix, the rest carry
2977
- * the same fix as a suggestion (oxlint can only apply one autofix per node).
2978
- */
2979
- function reportClassReplacements(context, loc, split, classes, offending, options) {
2980
- if (offending.length === 0) return;
2981
- const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
2982
- const fixedValue = rebuildClassString(split, classes.map((c) => replacements.get(c) ?? c));
2983
- const replacementKey = options.replacementKey ?? "replacement";
2984
- const suggestMessageId = options.suggestMessageId ?? "suggestReplace";
2985
- const applyFix = (fixer) => fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
2986
- const report = context.report;
2987
- for (let i = 0; i < offending.length; i++) {
2988
- const { cls, replacement } = offending[i];
2989
- const primaryData = {
2990
- className: cls,
2991
- [replacementKey]: replacement
2992
- };
2993
- if (i === 0) report({
2994
- node: loc.node,
2995
- messageId: options.messageId,
2996
- data: primaryData,
2997
- fix: applyFix
2998
- });
2999
- else report({
3000
- node: loc.node,
3001
- messageId: options.messageId,
3002
- data: primaryData,
3003
- suggest: [{
3004
- messageId: suggestMessageId,
3005
- data: {
3006
- className: cls,
3007
- replacement
3008
- },
3009
- fix: applyFix
3010
- }]
3011
- });
3012
- }
3013
- }
3014
- //#endregion
3015
- //#region src/rules/no-deprecated-classes.ts
3016
- const DEPRECATED_MAP = {
3017
- "flex-grow": "grow",
3018
- "flex-grow-0": "grow-0",
3019
- "flex-shrink": "shrink",
3020
- "flex-shrink-0": "shrink-0",
3021
- "overflow-ellipsis": "text-ellipsis",
3022
- "decoration-slice": "box-decoration-slice",
3023
- "decoration-clone": "box-decoration-clone",
3024
- "bg-gradient-to-t": "bg-linear-to-t",
3025
- "bg-gradient-to-tr": "bg-linear-to-tr",
3026
- "bg-gradient-to-r": "bg-linear-to-r",
3027
- "bg-gradient-to-br": "bg-linear-to-br",
3028
- "bg-gradient-to-b": "bg-linear-to-b",
3029
- "bg-gradient-to-bl": "bg-linear-to-bl",
3030
- "bg-gradient-to-l": "bg-linear-to-l",
3031
- "bg-gradient-to-tl": "bg-linear-to-tl"
3032
- };
3033
- const noDeprecatedClasses = defineRule({
3034
- meta: {
3035
- type: "problem",
3036
- docs: { description: "Disallow deprecated Tailwind CSS v4 classes" },
3037
- fixable: "code",
3038
- schema: [{
3039
- type: "object",
3040
- properties: { entryPoint: { type: "string" } },
3041
- additionalProperties: false
3042
- }],
3043
- hasSuggestions: true,
3044
- defaultOptions: [{}],
3045
- messages: {
3046
- deprecated: "\"{{className}}\" is deprecated in Tailwind v4. Use \"{{replacement}}\" instead.",
3047
- suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
3048
- }
3049
- },
3050
- createOnce(context) {
3051
- function check(locations) {
3052
- if (locations.length === 0) return;
3053
- for (const loc of locations) {
3054
- const split = splitClassesWithSeparators(loc.value);
3055
- const offending = split.classes.flatMap((cls) => {
3056
- const { utility, variant } = splitUtilityAndVariant(cls);
3057
- const { bare: bareUtility, position } = splitImportant(utility);
3058
- const replacement = DEPRECATED_MAP[bareUtility];
3059
- return replacement ? [{
3060
- cls,
3061
- replacement: variant + reattachImportant(replacement, position)
3062
- }] : [];
3063
- });
3064
- reportClassReplacements(context, loc, split, split.classes, offending, { messageId: "deprecated" });
3065
- }
3066
- }
3067
- return createExtractorVisitors(context, check);
3068
- }
3069
- });
3070
- //#endregion
3071
- //#region src/rules/no-unknown-classes.ts
3072
- const noUnknownClasses = defineRule({
3073
- meta: {
3074
- type: "problem",
3075
- docs: { description: "Disallow classes that are not defined in the Tailwind CSS design system" },
3076
- schema: [{
3077
- type: "object",
3078
- properties: {
3079
- entryPoint: { type: "string" },
3080
- allowlist: {
3081
- type: "array",
3082
- items: { type: "string" }
3083
- },
3084
- ignorePrefixes: {
3085
- type: "array",
3086
- items: { type: "string" }
3087
- }
3088
- },
3089
- additionalProperties: false
3090
- }],
3091
- hasSuggestions: true,
3092
- defaultOptions: [{
3093
- allowlist: [],
3094
- ignorePrefixes: []
3095
- }],
3096
- messages: {
3097
- unknown: "\"{{className}}\" is not a valid Tailwind class.",
3098
- unknownWithSuggestion: "\"{{className}}\" is not a valid Tailwind class. Did you mean \"{{suggestion}}\"?",
3099
- missingPrefix: "\"{{className}}\" needs the \"{{prefix}}:\" prefix to produce CSS. Did you mean \"{{suggestion}}\"?",
3100
- suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\".",
3101
- ...DS_UNAVAILABLE_MESSAGE
3102
- }
3103
- },
3104
- createOnce(context) {
3105
- const getDS = createLazyLoader(context);
3106
- const getLazyOptions = createLazyOptions(context, (o) => ({
3107
- allowlist: new Set(o?.allowlist ?? []),
3108
- ignorePrefixes: o?.ignorePrefixes ?? []
3109
- }));
3110
- function shouldIgnore(className) {
3111
- const { allowlist, ignorePrefixes } = getLazyOptions();
3112
- if (allowlist.has(className)) return true;
3113
- return ignorePrefixes.some((prefix) => className.startsWith(prefix));
3114
- }
3115
- function strippedUtility(className) {
3116
- const { utility, variant } = splitUtilityAndVariant(className);
3117
- const { bare, position } = splitImportant(utility);
3118
- return {
3119
- variant,
3120
- bare,
3121
- position
3122
- };
3123
- }
3124
- function check(locations) {
3125
- if (locations.length === 0) return;
3126
- const ds = safeGetDS(getDS, context, locations[0].node);
3127
- if (!ds) return;
3128
- const { cache } = ds;
3129
- for (const loc of locations) {
3130
- const split = splitClassesWithSeparators(loc.value);
3131
- const classes = split.classes;
3132
- for (const cls of classes) {
3133
- if (shouldIgnore(cls)) continue;
3134
- const validity = cache.classValidity(cls);
3135
- if (validity === "valid") continue;
3136
- const { variant, bare, position } = strippedUtility(cls);
3137
- if (DEPRECATED_MAP[bare]) continue;
3138
- if (validity === "missing-prefix") {
3139
- const fixed = `${cache.prefix}:${cls}`;
3140
- const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? fixed : c));
3141
- context.report({
3142
- node: loc.node,
3143
- messageId: "missingPrefix",
3144
- data: {
3145
- className: cls,
3146
- prefix: cache.prefix,
3147
- suggestion: fixed
3148
- },
3149
- suggest: [{
3150
- messageId: "suggestReplace",
3151
- data: {
3152
- className: cls,
3153
- replacement: fixed
3154
- },
3155
- fix(fixer) {
3156
- return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
3157
- }
3158
- }]
3159
- });
3160
- continue;
3161
- }
3162
- const suggestionBare = findBestSuggestion(bare, cache.validClasses);
3163
- const suggestion = suggestionBare ? variant + reattachImportant(suggestionBare, position) : null;
3164
- if (suggestion) {
3165
- const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? suggestion : c));
3166
- context.report({
3167
- node: loc.node,
3168
- messageId: "unknownWithSuggestion",
3169
- data: {
3170
- className: cls,
3171
- suggestion
3172
- },
3173
- suggest: [{
3174
- messageId: "suggestReplace",
3175
- data: {
3176
- className: cls,
3177
- replacement: suggestion
3178
- },
3179
- fix(fixer) {
3180
- return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
3181
- }
3182
- }]
3183
- });
3184
- } else context.report({
3185
- node: loc.node,
3186
- messageId: "unknown",
3187
- data: { className: cls }
3188
- });
3189
- }
3190
- }
3191
- }
3192
- return createExtractorVisitors(context, check);
3193
- }
3194
- });
3195
- //#endregion
3196
3037
  //#region src/design-system/ds-worker.ts
3197
3038
  /**
3198
3039
  * Generic worker-thread service wrapping `__unstable__loadDesignSystem`.
@@ -3438,6 +3279,7 @@ const declWorker = new DesignSystemWorker({
3438
3279
  workerScript: makeWorkerScript(`(ds, request) => {
3439
3280
  const decls = {};
3440
3281
  const values = {};
3282
+ const invalid = [];
3441
3283
  // A prefixed design system only resolves the PREFIXED form (\`tw:p-[5px]\`), and
3442
3284
  // the host asks with prefix-free names — \`extractUtility\` strips the project
3443
3285
  // prefix along with the variants. Same invariant the precompute follows: apply
@@ -3448,7 +3290,7 @@ const declWorker = new DesignSystemWorker({
3448
3290
  const pfx = (c) => (prefix && !c.startsWith(prefix + ':')) ? prefix + ':' + c : c;
3449
3291
  const css = ds.candidatesToCss(request.classes.map(pfx));
3450
3292
  for (let i = 0; i < request.classes.length; i++) {
3451
- if (!css[i]) continue;
3293
+ if (!css[i]) { invalid.push(request.classes[i]); continue; }
3452
3294
  const cls = request.classes[i];
3453
3295
  const list = [];
3454
3296
  // The selector carries the prefix, so the scope classifier needs the
@@ -3462,58 +3304,302 @@ const declWorker = new DesignSystemWorker({
3462
3304
  });
3463
3305
  if (list.length > 0) decls[cls] = list;
3464
3306
  }
3465
- return { decls, values };
3307
+ return { decls, values, invalid };
3466
3308
  }`, DECL_EXTRACTOR_SOURCE),
3467
3309
  serviceName: "declarations"
3468
3310
  });
3469
3311
  /**
3470
- * Classes already asked about, per design-system CACHE — not per entry point. A
3471
- * miss is remembered too: a class the design system produces no CSS for must not
3472
- * be re-queried on every AST node it appears in.
3312
+ * Everything already asked about, per design-system CACHE — not per entry point:
3313
+ * class name → does the design system produce CSS for it. A miss is remembered
3314
+ * too, so a class that compiles to nothing is not re-queried on every AST node it
3315
+ * appears in.
3473
3316
  *
3474
- * The lifetime has to match the cache's, because that is where the answers are
3475
- * interned. Keyed by path, a rebuilt cache (an mtime bump in a long-lived editor
3476
- * process, or `resetDesignSystem()`) inherited a fully-populated set and could
3477
- * never re-learn: the rule went permanently blind to user-written values with no
3478
- * diagnostic. A WeakMap also means there is nothing to reset.
3317
+ * The lifetime has to match the cache's, because that is where the declarations
3318
+ * are interned. Keyed by path, a rebuilt cache (an mtime bump in a long-lived
3319
+ * editor process, or `resetDesignSystem()`) inherited a fully-populated map and
3320
+ * could never re-learn: the rules went permanently blind to user-written values
3321
+ * with no diagnostic. A WeakMap also means there is nothing to reset.
3479
3322
  */
3480
- const queried = /* @__PURE__ */ new WeakMap();
3481
- function queriedFor(cache) {
3482
- let set = queried.get(cache);
3483
- if (!set) {
3484
- set = /* @__PURE__ */ new Set();
3485
- queried.set(cache, set);
3323
+ const answers = /* @__PURE__ */ new WeakMap();
3324
+ function answersFor(cache) {
3325
+ let map = answers.get(cache);
3326
+ if (!map) {
3327
+ map = /* @__PURE__ */ new Map();
3328
+ answers.set(cache, map);
3486
3329
  }
3487
- return set;
3330
+ return map;
3488
3331
  }
3489
3332
  /**
3490
- * Resolve declarations for `classes` that the precompute doesn't know.
3333
+ * Ask the design system about every class there is no answer for yet, intern the
3334
+ * declarations it returns, and record which classes produce no CSS at all.
3491
3335
  *
3492
- * Returns null when the service is unavailable, which the caller treats as "no
3493
- * information" — the same posture as a class with no declarations, so a broken
3494
- * worker degrades to today's silence rather than to wrong diagnostics. Real
3495
- * failures still surface through the sticky error the worker records.
3336
+ * Returns false when the service is unavailable. Callers treat that as "no
3337
+ * information" rather than as an answer, so a broken worker degrades to the
3338
+ * behaviour that predates it instead of to wrong diagnostics. Real failures still
3339
+ * surface through the sticky error the worker records.
3496
3340
  */
3497
- function resolveDeclarationsSync(cssPath, cache, classes) {
3498
- const seen = queriedFor(cache);
3499
- const pending = classes.filter((cls) => !seen.has(cls));
3500
- if (pending.length === 0) return null;
3501
- for (const cls of pending) seen.add(cls);
3341
+ function ask(cssPath, cache, classes) {
3342
+ const known = answersFor(cache);
3343
+ const pending = [...new Set(classes.filter((cls) => !known.has(cls)))];
3344
+ if (pending.length === 0) return true;
3345
+ let response;
3502
3346
  try {
3503
- return declWorker.callSync(cssPath, { classes: pending });
3347
+ response = declWorker.callSync(cssPath, { classes: pending });
3504
3348
  } catch (error) {
3505
- if (error instanceof SortServiceError) return null;
3349
+ if (error instanceof SortServiceError) return false;
3506
3350
  throw error;
3507
3351
  }
3352
+ const invalid = new Set(response.invalid);
3353
+ for (const cls of pending) known.set(cls, !invalid.has(cls));
3354
+ for (const [cls, raws] of Object.entries(response.decls)) cache.internDeclarations(cls, raws, response.values);
3355
+ return true;
3356
+ }
3357
+ /**
3358
+ * Resolve and intern declarations for `classes` that the precompute doesn't know.
3359
+ * They land in the cache, so the caller reads them back through
3360
+ * `cache.getCssDeclarations` like any other class.
3361
+ */
3362
+ function resolveDeclarationsSync(cssPath, cache, classes) {
3363
+ ask(cssPath, cache, classes);
3364
+ }
3365
+ /**
3366
+ * Which of these classes produce CSS. `null` when the service is unavailable, so
3367
+ * the caller can fall back instead of reading silence as an answer.
3368
+ *
3369
+ * This is what makes validity exact for the classes the precompute cannot
3370
+ * enumerate: `w-45` and `bg-red-5000` are shaped identically, and only Tailwind
3371
+ * knows that it compiles the first and not the second.
3372
+ */
3373
+ function validateClassesSync(cssPath, cache, classes) {
3374
+ if (!ask(cssPath, cache, classes)) return null;
3375
+ return answersFor(cache);
3508
3376
  }
3509
3377
  //#endregion
3510
- //#region src/rules/no-conflicting-classes/spec.ts
3511
- const COMPLEMENTARY_GROUPS = [{
3512
- pattern: /^prose(?:-|$)/,
3513
- reason: "`prose` + `prose-sm`/`prose-lg`/`prose-xl` modify the same scope and are designed to compose."
3514
- }];
3515
- const COMPOSITION_PAIRS = [
3516
- {
3378
+ //#region src/rules/no-unknown-classes.ts
3379
+ /**
3380
+ * Utility used to probe a variant chain. Any always-valid utility works; `flex`
3381
+ * is the shortest one every Tailwind build has.
3382
+ */
3383
+ const PROBE_UTILITY = "flex";
3384
+ const noUnknownClasses = defineRule({
3385
+ meta: {
3386
+ type: "problem",
3387
+ docs: { description: "Disallow classes that are not defined in the Tailwind CSS design system" },
3388
+ schema: [{
3389
+ type: "object",
3390
+ properties: {
3391
+ entryPoint: { type: "string" },
3392
+ allowlist: {
3393
+ type: "array",
3394
+ items: { type: "string" }
3395
+ },
3396
+ ignorePrefixes: {
3397
+ type: "array",
3398
+ items: { type: "string" }
3399
+ }
3400
+ },
3401
+ additionalProperties: false
3402
+ }],
3403
+ hasSuggestions: true,
3404
+ defaultOptions: [{
3405
+ allowlist: [],
3406
+ ignorePrefixes: []
3407
+ }],
3408
+ messages: {
3409
+ unknown: "\"{{className}}\" is not a valid Tailwind class.",
3410
+ unknownWithSuggestion: "\"{{className}}\" is not a valid Tailwind class. Did you mean \"{{suggestion}}\"?",
3411
+ missingPrefix: "\"{{className}}\" needs the \"{{prefix}}:\" prefix to produce CSS. Did you mean \"{{suggestion}}\"?",
3412
+ unknownVariant: "\"{{className}}\" produces no CSS: \"{{variant}}\" is not a variant this design system knows.",
3413
+ unknownVariantWithSuggestion: "\"{{className}}\" produces no CSS: \"{{variant}}\" is not a variant this design system knows. Did you mean \"{{suggestion}}\"?",
3414
+ suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\".",
3415
+ ...DS_UNAVAILABLE_MESSAGE
3416
+ }
3417
+ },
3418
+ createOnce(context) {
3419
+ const getDS = createLazyLoader(context);
3420
+ const getLazyOptions = createLazyOptions(context, (o) => ({
3421
+ allowlist: new Set(o?.allowlist ?? []),
3422
+ ignorePrefixes: o?.ignorePrefixes ?? []
3423
+ }));
3424
+ function shouldIgnore(className) {
3425
+ const { allowlist, ignorePrefixes } = getLazyOptions();
3426
+ if (allowlist.has(className)) return true;
3427
+ return ignorePrefixes.some((prefix) => className.startsWith(prefix));
3428
+ }
3429
+ function strippedUtility(className) {
3430
+ const { utility, variant } = splitUtilityAndVariant(className);
3431
+ const { bare, position } = splitImportant(utility);
3432
+ return {
3433
+ variant,
3434
+ bare,
3435
+ position
3436
+ };
3437
+ }
3438
+ /**
3439
+ * Does the design system compile this variant chain?
3440
+ *
3441
+ * `variantOrder` only lists the STATIC variants (71 of them: `hover`, `md`,
3442
+ * `dark`, …). It has no `group`, no `data`, no `@md`, because those are
3443
+ * functional variants whose values are unbounded — so validating a chain
3444
+ * against that list would report `group-hover:` and `data-[x=1]:` as unknown.
3445
+ * Compiling a probe utility under the chain is the only exact answer, and it
3446
+ * costs one design-system call per DISTINCT chain in the project.
3447
+ */
3448
+ const chainAnswers = /* @__PURE__ */ new Map();
3449
+ function chainProduces(cache, entryPoint, chain) {
3450
+ const key = `${entryPoint}\0${chain}`;
3451
+ const memo = chainAnswers.get(key);
3452
+ if (memo !== void 0) return memo;
3453
+ const probe = `${chain}${PROBE_UTILITY}`;
3454
+ const answers = validateClassesSync(entryPoint, cache, [probe]);
3455
+ const verdict = answers ? answers.get(probe) ?? null : null;
3456
+ chainAnswers.set(key, verdict);
3457
+ return verdict;
3458
+ }
3459
+ /** Replace one class in the location and report, with a quick-fix suggestion. */
3460
+ function reportWithSuggestion(loc, classes, cls, replacement, messageId, data, split) {
3461
+ const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? replacement : c));
3462
+ context.report({
3463
+ node: loc.node,
3464
+ messageId,
3465
+ data,
3466
+ suggest: [{
3467
+ messageId: "suggestReplace",
3468
+ data: {
3469
+ className: cls,
3470
+ replacement
3471
+ },
3472
+ fix(fixer) {
3473
+ return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
3474
+ }
3475
+ }]
3476
+ });
3477
+ }
3478
+ function check(locations) {
3479
+ if (locations.length === 0) return;
3480
+ const ds = safeGetDS(getDS, context, locations[0].node);
3481
+ if (!ds) return;
3482
+ const { cache, entryPoint } = ds;
3483
+ for (const loc of locations) {
3484
+ const split = splitClassesWithSeparators(loc.value);
3485
+ const classes = split.classes;
3486
+ let toVerify = null;
3487
+ for (const cls of classes) {
3488
+ if (shouldIgnore(cls)) continue;
3489
+ const bare = strippedUtility(cls).bare;
3490
+ if (cache.isKnownClass(bare)) continue;
3491
+ if (!toVerify) toVerify = [];
3492
+ toVerify.push(bare);
3493
+ }
3494
+ const verified = toVerify ? validateClassesSync(entryPoint, cache, toVerify) : null;
3495
+ for (const cls of classes) {
3496
+ if (shouldIgnore(cls)) continue;
3497
+ const validity = cache.classValidity(cls);
3498
+ const { variant, bare, position } = strippedUtility(cls);
3499
+ if (validity === "valid" && !variant && cache.isKnownClass(bare)) continue;
3500
+ if (cache.deprecatedReplacement(bare)) continue;
3501
+ if (validity === "missing-prefix") {
3502
+ const fixed = `${cache.prefix}:${cls}`;
3503
+ reportWithSuggestion(loc, classes, cls, fixed, "missingPrefix", {
3504
+ className: cls,
3505
+ prefix: cache.prefix,
3506
+ suggestion: fixed
3507
+ }, split);
3508
+ continue;
3509
+ }
3510
+ const compiles = cache.isKnownClass(bare) ? true : verified?.get(bare);
3511
+ if (validity === "unknown" || compiles === false) {
3512
+ const suggestionBare = findBestSuggestion(bare, cache.validClasses);
3513
+ const suggestion = suggestionBare ? variant + reattachImportant(suggestionBare, position) : null;
3514
+ if (suggestion) reportWithSuggestion(loc, classes, cls, suggestion, "unknownWithSuggestion", {
3515
+ className: cls,
3516
+ suggestion
3517
+ }, split);
3518
+ else context.report({
3519
+ node: loc.node,
3520
+ messageId: "unknown",
3521
+ data: { className: cls }
3522
+ });
3523
+ continue;
3524
+ }
3525
+ if (!variant) continue;
3526
+ if (chainProduces(cache, entryPoint, variant) !== false) continue;
3527
+ const { variant: offending, suggestion, fixedChain } = diagnoseChain(cache, entryPoint, variant);
3528
+ const fixedClass = fixedChain ? fixedChain + reattachImportant(bare, position) : null;
3529
+ if (fixedClass && suggestion) reportWithSuggestion(loc, classes, cls, fixedClass, "unknownVariantWithSuggestion", {
3530
+ className: cls,
3531
+ variant: offending,
3532
+ suggestion
3533
+ }, split);
3534
+ else context.report({
3535
+ node: loc.node,
3536
+ messageId: "unknownVariant",
3537
+ data: {
3538
+ className: cls,
3539
+ variant: offending
3540
+ }
3541
+ });
3542
+ }
3543
+ }
3544
+ }
3545
+ /**
3546
+ * Which segment of an invalid chain is to blame, and what to use instead.
3547
+ *
3548
+ * Every candidate correction is checked against the design system before it
3549
+ * is offered, so a suggestion is never a guess: `group-hoverr` is corrected by
3550
+ * fixing its last dash-segment and confirming that `group-hover:` compiles.
3551
+ * That also means no list of compound roots (`group`, `peer`, `data`, …) has
3552
+ * to be maintained here.
3553
+ */
3554
+ function diagnoseChain(cache, entryPoint, chain) {
3555
+ const segments = extractVariants(`${chain}${PROBE_UTILITY}`);
3556
+ const names = cache.variantNames();
3557
+ for (const segment of segments) {
3558
+ if (segment.startsWith("[")) continue;
3559
+ if (chainProduces(cache, entryPoint, `${segment}:`) !== false) continue;
3560
+ for (const candidate of correctionsFor(segment, names)) {
3561
+ if (chainProduces(cache, entryPoint, `${candidate}:`) !== true) continue;
3562
+ return {
3563
+ variant: segment,
3564
+ suggestion: candidate,
3565
+ fixedChain: segments.map((s) => s === segment ? candidate : s).join(":") + ":"
3566
+ };
3567
+ }
3568
+ return {
3569
+ variant: segment,
3570
+ suggestion: null,
3571
+ fixedChain: null
3572
+ };
3573
+ }
3574
+ return {
3575
+ variant: chain.slice(0, -1),
3576
+ suggestion: null,
3577
+ fixedChain: null
3578
+ };
3579
+ }
3580
+ /** Spelling candidates for a variant segment, nearest neighbour first. */
3581
+ function correctionsFor(segment, names) {
3582
+ const out = [];
3583
+ const whole = findBestSuggestion(segment, names);
3584
+ if (whole) out.push(whole);
3585
+ const dash = segment.lastIndexOf("-");
3586
+ if (dash > 0) {
3587
+ const tail = findBestSuggestion(segment.slice(dash + 1), names);
3588
+ if (tail) out.push(`${segment.slice(0, dash)}-${tail}`);
3589
+ }
3590
+ return out;
3591
+ }
3592
+ return createExtractorVisitors(context, check);
3593
+ }
3594
+ });
3595
+ //#endregion
3596
+ //#region src/rules/no-conflicting-classes/spec.ts
3597
+ const COMPLEMENTARY_GROUPS = [{
3598
+ pattern: /^prose(?:-|$)/,
3599
+ reason: "`prose` + `prose-sm`/`prose-lg`/`prose-xl` modify the same scope and are designed to compose."
3600
+ }];
3601
+ const COMPOSITION_PAIRS = [
3602
+ {
3517
3603
  a: /^prose(?:-|$)/,
3518
3604
  b: /^max-w-/,
3519
3605
  reason: "`prose` sets a default max-width; `max-w-*` overrides it."
@@ -3785,15 +3871,6 @@ function shouldSkipPair(a, b, rules = {}) {
3785
3871
  for (const { a: reA, b: reB } of pairs) if (reA.test(ua) && reB.test(ub) || reA.test(ub) && reB.test(ua)) return true;
3786
3872
  return false;
3787
3873
  }
3788
- /**
3789
- * A class the precompute cannot have enumerated: the value is written by the
3790
- * user, not by the design system's class list. Asking the design system about
3791
- * these is what closes the false negatives — `p-4 p-[5px]` used to be silently
3792
- * accepted while `p-4 p-6` reported.
3793
- */
3794
- function isUserValued(utility) {
3795
- return utility.includes("[") || utility.includes("(") || utility.includes("/") || /-\d/.test(utility);
3796
- }
3797
3874
  /** Whether the user's `allow` option silences this pair. */
3798
3875
  function isAllowed(a, b, allowClasses, allowPairs) {
3799
3876
  if (matchesAny(a, allowClasses) || matchesAny(b, allowClasses)) return true;
@@ -3873,10 +3950,7 @@ const noConflictingClasses = defineRule({
3873
3950
  for (const [, variantClasses] of byVariant) {
3874
3951
  if (variantClasses.length < 2) continue;
3875
3952
  const unknown = variantClasses.map((cls) => splitImportant(extractUtility(cls)).bare).filter((bare) => cache.getCssDeclarations(bare).length === 0 && isUserValued(bare));
3876
- if (unknown.length > 0) {
3877
- const resolved = resolveDeclarationsSync(ds.entryPoint, cache, unknown);
3878
- if (resolved) for (const [cls, raws] of Object.entries(resolved.decls)) cache.internDeclarations(cls, raws, resolved.values);
3879
- }
3953
+ if (unknown.length > 0) resolveDeclarationsSync(ds.entryPoint, cache, unknown);
3880
3954
  const facts = variantClasses.map((cls) => {
3881
3955
  const utility = extractUtility(cls);
3882
3956
  const bare = splitImportant(utility).bare;
@@ -3950,6 +4024,156 @@ const noConflictingClasses = defineRule({
3950
4024
  }
3951
4025
  });
3952
4026
  //#endregion
4027
+ //#region src/utils/report.ts
4028
+ /**
4029
+ * Shared reporter for the "first-as-fix, rest-as-suggestion" pattern.
4030
+ *
4031
+ * Nine rules (enforce-canonical, enforce-logical, enforce-physical,
4032
+ * enforce-consistent-variable-syntax, enforce-consistent-important-position,
4033
+ * enforce-negative-arbitrary-values, no-deprecated-classes,
4034
+ * no-unnecessary-arbitrary-value, prefer-theme-tokens) all emit
4035
+ * replacements via the same shape:
4036
+ *
4037
+ * 1. Collect `{ cls, replacement }` entries from a class string.
4038
+ * 2. Rebuild the full class string with replacements applied.
4039
+ * 3. Emit ONE diagnostic with the autofix attached.
4040
+ * 4. Emit one MORE diagnostic per remaining offender, each carrying
4041
+ * the same autofix as a `suggest`.
4042
+ *
4043
+ * oxlint's fixer is single-shot per AST node, so multiple offenders in the
4044
+ * same class string can only get one mechanical fix; the rest stay as
4045
+ * suggestions the IDE can offer interactively.
4046
+ */
4047
+ /**
4048
+ * Emit autofix + suggestion diagnostics for a list of class replacements.
4049
+ *
4050
+ * If `offending` is empty, no-op. The fixer's `replaceTextRange` is shared
4051
+ * across all diagnostics — the first one is the primary fix, the rest carry
4052
+ * the same fix as a suggestion (oxlint can only apply one autofix per node).
4053
+ */
4054
+ function reportClassReplacements(context, loc, split, classes, offending, options) {
4055
+ if (offending.length === 0) return;
4056
+ const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
4057
+ const fixedValue = rebuildClassString(split, classes.map((c) => replacements.get(c) ?? c));
4058
+ const replacementKey = options.replacementKey ?? "replacement";
4059
+ const suggestMessageId = options.suggestMessageId ?? "suggestReplace";
4060
+ const applyFix = (fixer) => fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
4061
+ const report = context.report;
4062
+ for (let i = 0; i < offending.length; i++) {
4063
+ const { cls, replacement } = offending[i];
4064
+ const primaryData = {
4065
+ className: cls,
4066
+ [replacementKey]: replacement
4067
+ };
4068
+ if (i === 0) report({
4069
+ node: loc.node,
4070
+ messageId: options.messageId,
4071
+ data: primaryData,
4072
+ fix: applyFix
4073
+ });
4074
+ else report({
4075
+ node: loc.node,
4076
+ messageId: options.messageId,
4077
+ data: primaryData,
4078
+ suggest: [{
4079
+ messageId: suggestMessageId,
4080
+ data: {
4081
+ className: cls,
4082
+ replacement
4083
+ },
4084
+ fix: applyFix
4085
+ }]
4086
+ });
4087
+ }
4088
+ }
4089
+ //#endregion
4090
+ //#region src/utils/replacement.ts
4091
+ /**
4092
+ * Returns a predicate that answers "would this replacement produce CSS?".
4093
+ *
4094
+ * `cache.isValid` is the tolerant validity check, so it accepts arbitrary values
4095
+ * (`foo-[5px]`) it cannot verify. That is the right posture here: a rewrite of an
4096
+ * already-invalid class is `no-unknown-classes`' business, and this guard only
4097
+ * has to stop a rewrite from INTRODUCING an invalid class.
4098
+ */
4099
+ function makeReplacementGuard(cache) {
4100
+ if (!cache) return () => true;
4101
+ return (replacement) => cache.isValid(replacement);
4102
+ }
4103
+ //#endregion
4104
+ //#region src/rules/no-deprecated-classes.ts
4105
+ /**
4106
+ * Fallback rename map, for when no design system is available.
4107
+ *
4108
+ * With an `entryPoint` configured the rule uses the map the precompute derives
4109
+ * from `canonicalizeCandidates`, which is strictly better: it covers the renames
4110
+ * this list misses (`break-words`, `order-none`, the reordered
4111
+ * `bg-left-top`/`object-left-top` position spellings) and it prunes itself when a
4112
+ * Tailwind release stops compiling one of them. This table only has to keep the
4113
+ * unconfigured case working exactly as it did.
4114
+ */
4115
+ const DEPRECATED_MAP = {
4116
+ "flex-grow": "grow",
4117
+ "flex-grow-0": "grow-0",
4118
+ "flex-shrink": "shrink",
4119
+ "flex-shrink-0": "shrink-0",
4120
+ "overflow-ellipsis": "text-ellipsis",
4121
+ "decoration-slice": "box-decoration-slice",
4122
+ "decoration-clone": "box-decoration-clone",
4123
+ "bg-gradient-to-t": "bg-linear-to-t",
4124
+ "bg-gradient-to-tr": "bg-linear-to-tr",
4125
+ "bg-gradient-to-r": "bg-linear-to-r",
4126
+ "bg-gradient-to-br": "bg-linear-to-br",
4127
+ "bg-gradient-to-b": "bg-linear-to-b",
4128
+ "bg-gradient-to-bl": "bg-linear-to-bl",
4129
+ "bg-gradient-to-l": "bg-linear-to-l",
4130
+ "bg-gradient-to-tl": "bg-linear-to-tl"
4131
+ };
4132
+ const noDeprecatedClasses = defineRule({
4133
+ meta: {
4134
+ type: "problem",
4135
+ docs: { description: "Disallow deprecated Tailwind CSS v4 classes" },
4136
+ fixable: "code",
4137
+ schema: [{
4138
+ type: "object",
4139
+ properties: { entryPoint: { type: "string" } },
4140
+ additionalProperties: false
4141
+ }],
4142
+ hasSuggestions: true,
4143
+ defaultOptions: [{}],
4144
+ messages: {
4145
+ deprecated: "\"{{className}}\" is deprecated in Tailwind v4. Use \"{{replacement}}\" instead.",
4146
+ suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
4147
+ }
4148
+ },
4149
+ createOnce(context) {
4150
+ const getDS = createLazyLoader(context);
4151
+ function check(locations) {
4152
+ if (locations.length === 0) return;
4153
+ const ds = softGetDS(getDS);
4154
+ const cache = ds ? ds.cache : null;
4155
+ const replacementFor = (bare) => cache?.hasDeprecatedMap ? cache.deprecatedReplacement(bare) : DEPRECATED_MAP[bare] ?? null;
4156
+ const isUsable = makeReplacementGuard(cache);
4157
+ for (const loc of locations) {
4158
+ const split = splitClassesWithSeparators(loc.value);
4159
+ const offending = split.classes.flatMap((cls) => {
4160
+ const { utility, variant } = splitUtilityAndVariant(cls);
4161
+ const { bare: bareUtility, position } = splitImportant(utility);
4162
+ const replacement = replacementFor(bareUtility);
4163
+ if (!replacement) return [];
4164
+ const rebuilt = variant + reattachImportant(replacement, position);
4165
+ return isUsable(rebuilt) ? [{
4166
+ cls,
4167
+ replacement: rebuilt
4168
+ }] : [];
4169
+ });
4170
+ reportClassReplacements(context, loc, split, split.classes, offending, { messageId: "deprecated" });
4171
+ }
4172
+ }
4173
+ return createExtractorVisitors(context, check);
4174
+ }
4175
+ });
4176
+ //#endregion
3953
4177
  //#region src/design-system/canonicalize-service.ts
3954
4178
  /**
3955
4179
  * Persistent canonicalize service backed by `DesignSystemWorker`.
@@ -4264,10 +4488,17 @@ const enforceCanonical = defineRule({
4264
4488
  const canonicals = Array.from({ length: classes.length });
4265
4489
  const arbitraryIdx = [];
4266
4490
  const arbitrary = [];
4267
- for (let i = 0; i < classes.length; i++) if (utilityHasDynamicValue(classes[i])) {
4268
- arbitraryIdx.push(i);
4269
- arbitrary.push(classes[i]);
4270
- } else canonicals[i] = cache.canonicalize(classes[i]);
4491
+ for (let i = 0; i < classes.length; i++) {
4492
+ const { utility } = splitUtilityAndVariant(classes[i]);
4493
+ if (cache.deprecatedReplacement(splitImportant(utility).bare)) {
4494
+ canonicals[i] = classes[i];
4495
+ continue;
4496
+ }
4497
+ if (utilityHasDynamicValue(classes[i])) {
4498
+ arbitraryIdx.push(i);
4499
+ arbitrary.push(classes[i]);
4500
+ } else canonicals[i] = cache.canonicalize(classes[i]);
4501
+ }
4271
4502
  if (arbitrary.length > 0) {
4272
4503
  const rem = getRem();
4273
4504
  const dynamic = safeGetDS(() => canonicalizeClassesSync(entryPoint, arbitrary, rem), context, loc.node);
@@ -4417,121 +4648,317 @@ const enforceSortOrder = defineRule({
4417
4648
  });
4418
4649
  //#endregion
4419
4650
  //#region src/rules/enforce-shorthand.ts
4420
- const VALUE_RE = /^(?:m[trbl]|mx|my|p[trbl]|px|py|[wh]|rounded-t[lr]|rounded-b[lr]|min-[wh]|max-[wh])-(.+)$/;
4421
- const INVALID_SIZE_VALUES = /* @__PURE__ */ new Set([
4422
- "screen",
4423
- "dvw",
4424
- "dvh",
4425
- "svw",
4426
- "svh",
4427
- "lvw",
4428
- "lvh"
4429
- ]);
4430
4651
  /**
4431
- * Generates shorthand rules parameterized by value.
4432
- * E.g.: mt-2 + mr-2 + mb-2 + ml-2 -> m-2
4652
+ * The `m`/`p` shape, shared by `margin`, `padding`, `scroll-margin` and
4653
+ * `scroll-padding`: four sides, each axis, and the logical inline pair (`ms`+`me`
4654
+ * IS `margin-inline`, so that one is property-identical rather than merely
4655
+ * equivalent).
4433
4656
  */
4434
- function createShorthandRules(value) {
4657
+ function boxFamilies(p) {
4435
4658
  return [
4436
4659
  {
4437
4660
  parts: [
4438
- `mt-${value}`,
4439
- `mr-${value}`,
4440
- `mb-${value}`,
4441
- `ml-${value}`
4661
+ `${p}t`,
4662
+ `${p}r`,
4663
+ `${p}b`,
4664
+ `${p}l`
4442
4665
  ],
4443
- replacement: `m-${value}`
4666
+ to: p
4444
4667
  },
4445
4668
  {
4446
- parts: [`mt-${value}`, `mb-${value}`],
4447
- replacement: `my-${value}`
4448
- },
4449
- {
4450
- parts: [`ml-${value}`, `mr-${value}`],
4451
- replacement: `mx-${value}`
4452
- },
4453
- {
4454
- parts: [`mx-${value}`, `my-${value}`],
4455
- replacement: `m-${value}`
4456
- },
4457
- {
4458
- parts: [
4459
- `pt-${value}`,
4460
- `pr-${value}`,
4461
- `pb-${value}`,
4462
- `pl-${value}`
4463
- ],
4464
- replacement: `p-${value}`
4669
+ parts: [`${p}t`, `${p}b`],
4670
+ to: `${p}y`
4465
4671
  },
4466
4672
  {
4467
- parts: [`pt-${value}`, `pb-${value}`],
4468
- replacement: `py-${value}`
4673
+ parts: [`${p}l`, `${p}r`],
4674
+ to: `${p}x`
4469
4675
  },
4470
4676
  {
4471
- parts: [`pl-${value}`, `pr-${value}`],
4472
- replacement: `px-${value}`
4677
+ parts: [`${p}s`, `${p}e`],
4678
+ to: `${p}x`
4473
4679
  },
4474
4680
  {
4475
- parts: [`px-${value}`, `py-${value}`],
4476
- replacement: `p-${value}`
4477
- },
4478
- ...!INVALID_SIZE_VALUES.has(value) ? [{
4479
- parts: [`w-${value}`, `h-${value}`],
4480
- replacement: `size-${value}`
4481
- }] : [],
4482
- {
4483
- parts: [
4484
- `rounded-tl-${value}`,
4485
- `rounded-tr-${value}`,
4486
- `rounded-br-${value}`,
4487
- `rounded-bl-${value}`
4488
- ],
4489
- replacement: `rounded-${value}`
4681
+ parts: [`${p}x`, `${p}y`],
4682
+ to: p
4490
4683
  }
4491
4684
  ];
4492
4685
  }
4686
+ const SHORTHAND_FAMILIES = [
4687
+ ...boxFamilies("m"),
4688
+ ...boxFamilies("p"),
4689
+ ...boxFamilies("scroll-m"),
4690
+ ...boxFamilies("scroll-p"),
4691
+ {
4692
+ parts: ["w", "h"],
4693
+ to: "size",
4694
+ perAxisNamespaces: true
4695
+ },
4696
+ {
4697
+ parts: [
4698
+ "rounded-tl",
4699
+ "rounded-tr",
4700
+ "rounded-br",
4701
+ "rounded-bl"
4702
+ ],
4703
+ to: "rounded"
4704
+ },
4705
+ {
4706
+ parts: [
4707
+ "rounded-ss",
4708
+ "rounded-se",
4709
+ "rounded-ee",
4710
+ "rounded-es"
4711
+ ],
4712
+ to: "rounded"
4713
+ },
4714
+ {
4715
+ parts: ["rounded-tl", "rounded-tr"],
4716
+ to: "rounded-t"
4717
+ },
4718
+ {
4719
+ parts: ["rounded-bl", "rounded-br"],
4720
+ to: "rounded-b"
4721
+ },
4722
+ {
4723
+ parts: ["rounded-tl", "rounded-bl"],
4724
+ to: "rounded-l"
4725
+ },
4726
+ {
4727
+ parts: ["rounded-tr", "rounded-br"],
4728
+ to: "rounded-r"
4729
+ },
4730
+ {
4731
+ parts: ["rounded-ss", "rounded-es"],
4732
+ to: "rounded-s"
4733
+ },
4734
+ {
4735
+ parts: ["rounded-se", "rounded-ee"],
4736
+ to: "rounded-e"
4737
+ },
4738
+ {
4739
+ parts: ["rounded-t", "rounded-b"],
4740
+ to: "rounded"
4741
+ },
4742
+ {
4743
+ parts: ["rounded-l", "rounded-r"],
4744
+ to: "rounded"
4745
+ },
4746
+ {
4747
+ parts: ["rounded-s", "rounded-e"],
4748
+ to: "rounded"
4749
+ },
4750
+ {
4751
+ parts: [
4752
+ "border-t",
4753
+ "border-r",
4754
+ "border-b",
4755
+ "border-l"
4756
+ ],
4757
+ to: "border"
4758
+ },
4759
+ {
4760
+ parts: ["border-t", "border-b"],
4761
+ to: "border-y"
4762
+ },
4763
+ {
4764
+ parts: ["border-l", "border-r"],
4765
+ to: "border-x"
4766
+ },
4767
+ {
4768
+ parts: ["border-s", "border-e"],
4769
+ to: "border-x"
4770
+ },
4771
+ {
4772
+ parts: ["border-x", "border-y"],
4773
+ to: "border"
4774
+ },
4775
+ {
4776
+ parts: [
4777
+ "top",
4778
+ "right",
4779
+ "bottom",
4780
+ "left"
4781
+ ],
4782
+ to: "inset"
4783
+ },
4784
+ {
4785
+ parts: ["top", "bottom"],
4786
+ to: "inset-y"
4787
+ },
4788
+ {
4789
+ parts: ["left", "right"],
4790
+ to: "inset-x"
4791
+ },
4792
+ {
4793
+ parts: ["start", "end"],
4794
+ to: "inset-x"
4795
+ },
4796
+ {
4797
+ parts: ["inset-x", "inset-y"],
4798
+ to: "inset"
4799
+ },
4800
+ {
4801
+ parts: ["gap-x", "gap-y"],
4802
+ to: "gap"
4803
+ },
4804
+ {
4805
+ parts: ["overflow-x", "overflow-y"],
4806
+ to: "overflow"
4807
+ },
4808
+ {
4809
+ parts: ["overscroll-x", "overscroll-y"],
4810
+ to: "overscroll"
4811
+ },
4812
+ {
4813
+ parts: ["border-spacing-x", "border-spacing-y"],
4814
+ to: "border-spacing"
4815
+ },
4816
+ {
4817
+ parts: ["translate-x", "translate-y"],
4818
+ to: "translate"
4819
+ }
4820
+ ];
4821
+ /**
4822
+ * Largest merges first, so four sides collapse to `m-2` instead of also
4823
+ * reporting the `my-2`/`mx-2` halves — three diagnostics for one problem, which
4824
+ * is what this rule used to emit. `sort` is stable, so same-size families keep
4825
+ * their declaration order and the choice stays deterministic.
4826
+ */
4827
+ const FAMILIES_BY_SIZE = [...SHORTHAND_FAMILIES].sort((a, b) => b.parts.length - a.parts.length);
4828
+ /**
4829
+ * `^<part>-<value>$`, longest prefix first so `rounded-tl-lg` is read as
4830
+ * `rounded-tl` + `lg` and never as `rounded-t` + `l-lg`.
4831
+ */
4832
+ const VALUE_RE = (() => {
4833
+ const prefixes = [...new Set(SHORTHAND_FAMILIES.flatMap((f) => f.parts))].sort((a, b) => b.length - a.length);
4834
+ return new RegExp(`^(${prefixes.join("|")})-(.+)$`);
4835
+ })();
4836
+ /** A plain number or fraction: always the shared numeric/`--spacing` scale. */
4837
+ const NUMERIC_VALUE_RE = /^\d+(?:\.\d+)?(?:\/\d+(?:\.\d+)?)?$/;
4838
+ /**
4839
+ * Core keywords whose per-axis forms are known to agree, for when no design
4840
+ * system is available to check. Deliberately excludes `screen` (`w-screen` is
4841
+ * `100vw`, `h-screen` is `100vh`) and every named theme token, which is the case
4842
+ * that can only be settled by looking at the emitted CSS.
4843
+ */
4844
+ const AXIS_SAFE_KEYWORDS = /* @__PURE__ */ new Set([
4845
+ "full",
4846
+ "auto",
4847
+ "min",
4848
+ "max",
4849
+ "fit",
4850
+ "px",
4851
+ "dvw",
4852
+ "dvh",
4853
+ "lvw",
4854
+ "lvh",
4855
+ "svw",
4856
+ "svh"
4857
+ ]);
4858
+ /** The value is a literal the user wrote, injected verbatim into every part. */
4859
+ function isWrittenValue(value) {
4860
+ return value.startsWith("[") || value.startsWith("(");
4861
+ }
4862
+ /**
4863
+ * Values the class declares on its own box, unconditionally. `null` when the
4864
+ * class produces nothing — which for a named token means it does not exist.
4865
+ */
4866
+ function declaredValues(cache, cls) {
4867
+ const values = /* @__PURE__ */ new Set();
4868
+ for (const decl of cache.getCssDeclarations(cls)) {
4869
+ if (decl.conditional) continue;
4870
+ values.add(decl.value);
4871
+ }
4872
+ return values.size > 0 ? values : null;
4873
+ }
4874
+ function sameValues(a, b) {
4875
+ if (a.size !== b.size) return false;
4876
+ for (const value of a) if (!b.has(value)) return false;
4877
+ return true;
4878
+ }
4879
+ /**
4880
+ * Would collapsing this family at this value keep the CSS identical?
4881
+ *
4882
+ * With a design system this is answered from the emitted declarations. Without
4883
+ * one it falls back to what is safe by construction, which is everything except
4884
+ * a named token on the one family whose parts read different namespaces.
4885
+ */
4886
+ function mergeIsSafe(family, value, cache) {
4887
+ const structurallySafe = NUMERIC_VALUE_RE.test(value) || isWrittenValue(value);
4888
+ if (!cache) {
4889
+ if (!family.perAxisNamespaces) return true;
4890
+ return structurallySafe || AXIS_SAFE_KEYWORDS.has(value);
4891
+ }
4892
+ if (!cache.isValid(`${family.to}-${value}`)) return false;
4893
+ if (structurallySafe) return true;
4894
+ const expected = declaredValues(cache, `${family.parts[0]}-${value}`);
4895
+ if (!expected) return false;
4896
+ for (let i = 1; i < family.parts.length; i++) {
4897
+ const actual = declaredValues(cache, `${family.parts[i]}-${value}`);
4898
+ if (!actual || !sameValues(expected, actual)) return false;
4899
+ }
4900
+ const replacement = declaredValues(cache, `${family.to}-${value}`);
4901
+ return replacement !== null && sameValues(expected, replacement);
4902
+ }
4493
4903
  const enforceShorthand = defineRule({
4494
4904
  meta: {
4495
4905
  type: "suggestion",
4496
4906
  docs: { description: "Enforce shorthand Tailwind CSS classes when all axes have the same value" },
4497
4907
  fixable: "code",
4498
- schema: [],
4908
+ schema: [{
4909
+ type: "object",
4910
+ properties: { entryPoint: { type: "string" } },
4911
+ additionalProperties: false
4912
+ }],
4913
+ defaultOptions: [{}],
4499
4914
  messages: { shorthand: "{{parts}} can be simplified to \"{{replacement}}\"." }
4500
4915
  },
4501
4916
  createOnce(context) {
4917
+ const getDS = createLazyLoader(context);
4502
4918
  function check(locations) {
4919
+ const ds = softGetDS(getDS);
4920
+ const cache = ds ? ds.cache : null;
4503
4921
  for (const loc of locations) {
4504
4922
  const split = splitClassesWithSeparators(loc.value);
4505
4923
  const classes = split.classes;
4506
4924
  if (classes.length < 2) continue;
4507
- const classSet = new Set(classes);
4508
- const variantValues = /* @__PURE__ */ new Set();
4925
+ const groups = /* @__PURE__ */ new Map();
4509
4926
  for (const cls of classes) {
4510
4927
  const { utility, variant } = splitUtilityAndVariant(cls);
4511
- const match = VALUE_RE.exec(splitImportant(utility).bare);
4512
- if (match) variantValues.add(`${variant}\0${match[1]}`);
4928
+ const { bare, position } = splitImportant(utility);
4929
+ const match = VALUE_RE.exec(bare);
4930
+ if (!match) continue;
4931
+ const [, part, value] = match;
4932
+ const key = `${variant}\0${position ?? ""}\0${value}`;
4933
+ let group = groups.get(key);
4934
+ if (!group) {
4935
+ group = {
4936
+ variant,
4937
+ position,
4938
+ value,
4939
+ byPart: /* @__PURE__ */ new Map()
4940
+ };
4941
+ groups.set(key, group);
4942
+ }
4943
+ group.byPart.set(part, cls);
4513
4944
  }
4514
- for (const variantValue of variantValues) {
4515
- const nul = variantValue.indexOf("\0");
4516
- const variant = variantValue.slice(0, nul);
4517
- const rules = createShorthandRules(variantValue.slice(nul + 1));
4518
- for (const rule of rules) {
4519
- const withVariant = (p) => `${variant}${p}`;
4520
- const hasImportantPrefix = rule.parts.every((p) => classSet.has(withVariant(`!${p}`)));
4521
- const hasImportantSuffix = !hasImportantPrefix && rule.parts.every((p) => classSet.has(withVariant(`${p}!`)));
4522
- const hasPlain = rule.parts.every((p) => classSet.has(withVariant(p)));
4523
- if (!hasImportantPrefix && !hasImportantSuffix && !hasPlain) continue;
4524
- const importantStart = hasImportantPrefix ? "!" : "";
4525
- const importantEnd = hasImportantSuffix ? "!" : "";
4526
- const matchParts = rule.parts.map((p) => withVariant(`${importantStart}${p}${importantEnd}`));
4527
- const remaining = classes.filter((c) => !matchParts.includes(c));
4528
- remaining.push(withVariant(`${importantStart}${rule.replacement}${importantEnd}`));
4945
+ for (const group of groups.values()) {
4946
+ if (group.byPart.size < 2) continue;
4947
+ const consumed = /* @__PURE__ */ new Set();
4948
+ for (const family of FAMILIES_BY_SIZE) {
4949
+ if (family.parts.some((part) => !group.byPart.has(part) || consumed.has(part))) continue;
4950
+ if (!mergeIsSafe(family, group.value, cache)) continue;
4951
+ const matched = family.parts.map((part) => group.byPart.get(part));
4952
+ const replacement = group.variant + reattachImportant(`${family.to}-${group.value}`, group.position);
4953
+ const remaining = classes.filter((cls) => !matched.includes(cls));
4954
+ if (!remaining.includes(replacement)) remaining.push(replacement);
4955
+ for (const part of family.parts) consumed.add(part);
4529
4956
  context.report({
4530
4957
  node: loc.node,
4531
4958
  messageId: "shorthand",
4532
4959
  data: {
4533
- parts: matchParts.map((p) => `"${p}"`).join(", "),
4534
- replacement: withVariant(`${importantStart}${rule.replacement}${importantEnd}`)
4960
+ parts: matched.map((p) => `"${p}"`).join(", "),
4961
+ replacement
4535
4962
  },
4536
4963
  fix(fixer) {
4537
4964
  return fixer.replaceTextRange(loc.range, preserveSpaces(loc, rebuildClassString(split, remaining)));
@@ -4560,7 +4987,8 @@ const LOGICAL_PHYSICAL_SCHEMA = {
4560
4987
  "block",
4561
4988
  "both"
4562
4989
  ]
4563
- }
4990
+ },
4991
+ entryPoint: { type: "string" }
4564
4992
  },
4565
4993
  additionalProperties: false
4566
4994
  };
@@ -4654,17 +5082,73 @@ const PHYSICAL_TO_LOGICAL_MAPPINGS = [
4654
5082
  from: "scroll-pr",
4655
5083
  to: "scroll-pe",
4656
5084
  axis: "inline"
5085
+ },
5086
+ {
5087
+ from: "float-left",
5088
+ to: "float-start",
5089
+ axis: "inline",
5090
+ exact: true
5091
+ },
5092
+ {
5093
+ from: "float-right",
5094
+ to: "float-end",
5095
+ axis: "inline",
5096
+ exact: true
5097
+ },
5098
+ {
5099
+ from: "clear-left",
5100
+ to: "clear-start",
5101
+ axis: "inline",
5102
+ exact: true
5103
+ },
5104
+ {
5105
+ from: "clear-right",
5106
+ to: "clear-end",
5107
+ axis: "inline",
5108
+ exact: true
5109
+ },
5110
+ {
5111
+ from: "text-left",
5112
+ to: "text-start",
5113
+ axis: "inline",
5114
+ exact: true
5115
+ },
5116
+ {
5117
+ from: "text-right",
5118
+ to: "text-end",
5119
+ axis: "inline",
5120
+ exact: true
4657
5121
  }
4658
5122
  ];
5123
+ /**
5124
+ * Extra sources for enforce-physical ONLY.
5125
+ *
5126
+ * `enforce-logical` rewrites `left-2` to `start-2`, the spelling Tailwind's own
5127
+ * docs use. `enforce-canonical`, asking the design system, then rewrites that to
5128
+ * `inset-s-2` — same CSS, canonical name. So a codebase that ran both ends up with
5129
+ * `inset-s-*`, and enforce-physical had no way back: its table only knew `start`.
5130
+ *
5131
+ * Kept out of the main table so inverting it doesn't change what enforce-logical
5132
+ * suggests (both spellings map to the same physical class, but only one of them
5133
+ * can be the recommendation).
5134
+ */
5135
+ const LOGICAL_INSET_ALIASES = [{
5136
+ from: "inset-s",
5137
+ to: "left",
5138
+ axis: "inline"
5139
+ }, {
5140
+ from: "inset-e",
5141
+ to: "right",
5142
+ axis: "inline"
5143
+ }];
4659
5144
  /** Invert a directional table. enforce-physical consumes this. */
4660
5145
  function invertAxisMappings(mappings) {
4661
5146
  return mappings.map((m) => ({
5147
+ ...m,
4662
5148
  from: m.to,
4663
- to: m.from,
4664
- axis: m.axis
5149
+ to: m.from
4665
5150
  }));
4666
5151
  }
4667
- Object.fromEntries(PHYSICAL_TO_LOGICAL_MAPPINGS.map((m) => [m.from, m.to]));
4668
5152
  /**
4669
5153
  * Build the `check` callback for a directional-rewrite rule. Both
4670
5154
  * enforce-logical and enforce-physical instantiate this with their own
@@ -4680,6 +5164,7 @@ function createDirectionalMapper(context, opts) {
4680
5164
  allowlist: compileRegexList(o?.allowlist),
4681
5165
  direction: o?.direction ?? "both"
4682
5166
  }));
5167
+ const getDS = createLazyLoader(context);
4683
5168
  function convertClass(cls) {
4684
5169
  const { allowlist, direction } = getState();
4685
5170
  if (matchesAny(cls, allowlist)) return null;
@@ -4687,24 +5172,26 @@ function createDirectionalMapper(context, opts) {
4687
5172
  const { bare: bareUtility, position } = splitImportant(utility);
4688
5173
  const negative = bareUtility.startsWith("-");
4689
5174
  const core = negative ? bareUtility.slice(1) : bareUtility;
4690
- for (const { from, to, axis } of opts.mappings) {
5175
+ for (const { from, to, axis, exact } of opts.mappings) {
4691
5176
  if (direction !== "both" && direction !== axis) continue;
4692
- if (core === from || core.startsWith(`${from}-`)) {
4693
- const suffix = core.slice(from.length);
4694
- return `${variant}${reattachImportant(`${negative ? "-" : ""}${to}${suffix}`, position)}`;
4695
- }
5177
+ if (!(core === from || !exact && core.startsWith(`${from}-`))) continue;
5178
+ const suffix = core.slice(from.length);
5179
+ return `${variant}${reattachImportant(`${negative ? "-" : ""}${to}${suffix}`, position)}`;
4696
5180
  }
4697
5181
  return null;
4698
5182
  }
4699
5183
  function check(locations) {
5184
+ const ds = softGetDS(getDS);
5185
+ const isUsable = makeReplacementGuard(ds ? ds.cache : null);
4700
5186
  for (const loc of locations) {
4701
5187
  const split = splitClassesWithSeparators(loc.value);
4702
5188
  const offending = split.classes.flatMap((cls) => {
4703
5189
  const converted = convertClass(cls);
4704
- return converted ? [{
5190
+ if (!converted || !isUsable(converted)) return [];
5191
+ return [{
4705
5192
  cls,
4706
5193
  replacement: converted
4707
- }] : [];
5194
+ }];
4708
5195
  });
4709
5196
  reportClassReplacements(context, loc, split, split.classes, offending, { messageId: opts.messageId });
4710
5197
  }
@@ -4755,7 +5242,7 @@ const enforcePhysical = defineRule({
4755
5242
  },
4756
5243
  createOnce(context) {
4757
5244
  const { check } = createDirectionalMapper(context, {
4758
- mappings: invertAxisMappings(PHYSICAL_TO_LOGICAL_MAPPINGS),
5245
+ mappings: [...invertAxisMappings(PHYSICAL_TO_LOGICAL_MAPPINGS), ...LOGICAL_INSET_ALIASES],
4759
5246
  messageId: "usePhysical"
4760
5247
  });
4761
5248
  return createExtractorVisitors(context, check);
@@ -4908,7 +5395,7 @@ const noArbitraryValue = defineRule({
4908
5395
  for (const loc of locations) {
4909
5396
  const classes = splitClasses(loc.value);
4910
5397
  for (const cls of classes) {
4911
- if (!hasArbitraryValue(cls)) continue;
5398
+ if (!utilityHasDynamicValue(cls)) continue;
4912
5399
  const utility = splitImportant(extractUtility(cls)).bare;
4913
5400
  if (isAllowed(utility)) continue;
4914
5401
  context.report({
@@ -5173,10 +5660,13 @@ const noDarkWithoutLight = defineRule({
5173
5660
  docs: { description: "Require a base (light) utility when using dark: (or other scheme) variant" },
5174
5661
  schema: [{
5175
5662
  type: "object",
5176
- properties: { variants: {
5177
- type: "array",
5178
- items: { type: "string" }
5179
- } },
5663
+ properties: {
5664
+ variants: {
5665
+ type: "array",
5666
+ items: { type: "string" }
5667
+ },
5668
+ entryPoint: { type: "string" }
5669
+ },
5180
5670
  additionalProperties: false
5181
5671
  }],
5182
5672
  defaultOptions: [{ variants: DEFAULT_VARIANTS }],
@@ -5184,85 +5674,206 @@ const noDarkWithoutLight = defineRule({
5184
5674
  },
5185
5675
  createOnce(context) {
5186
5676
  const getWatchedVariants = createLazyOptions(context, (o) => new Set(o?.variants ?? DEFAULT_VARIANTS));
5677
+ const getDS = createLazyLoader(context);
5678
+ const bareOf = (cls) => splitImportant(extractUtility(cls)).bare;
5187
5679
  function check(locations) {
5188
5680
  const watchedVariants = getWatchedVariants();
5681
+ const ds = softGetDS(getDS);
5682
+ const cache = ds ? ds.cache : null;
5189
5683
  for (const loc of locations) {
5190
5684
  const classes = splitClasses(loc.value);
5685
+ if (cache && ds) {
5686
+ let unresolved = null;
5687
+ for (const cls of classes) {
5688
+ const bare = bareOf(cls);
5689
+ if (cache.getCssProperties(bare).length > 0 || !isUserValued(bare)) continue;
5690
+ if (!unresolved) unresolved = [];
5691
+ unresolved.push(bare);
5692
+ }
5693
+ if (unresolved) resolveDeclarationsSync(ds.entryPoint, cache, unresolved);
5694
+ }
5191
5695
  const basePrefixes = /* @__PURE__ */ new Set();
5696
+ const baseProperties = /* @__PURE__ */ new Set();
5192
5697
  const variantClasses = [];
5193
5698
  for (const cls of classes) {
5194
5699
  const variants = extractVariants(cls);
5195
5700
  const prefix = getUtilityPrefix(extractUtility(cls));
5196
- if (variants.some((v) => watchedVariants.has(v))) {
5197
- const variant = variants.find((v) => watchedVariants.has(v));
5198
- variantClasses.push({
5199
- cls,
5701
+ const properties = cache ? cache.getCssProperties(bareOf(cls)) : [];
5702
+ const variant = variants.find((v) => watchedVariants.has(v));
5703
+ if (variant !== void 0) variantClasses.push({
5704
+ cls,
5705
+ variant,
5706
+ prefix,
5707
+ properties
5708
+ });
5709
+ else {
5710
+ basePrefixes.add(prefix);
5711
+ for (const property of properties) baseProperties.add(property);
5712
+ }
5713
+ }
5714
+ for (const { cls, variant, prefix, properties } of variantClasses) {
5715
+ if (basePrefixes.has(prefix)) continue;
5716
+ if (properties.some((property) => baseProperties.has(property))) continue;
5717
+ context.report({
5718
+ node: loc.node,
5719
+ messageId: "missingBase",
5720
+ data: {
5721
+ className: cls,
5200
5722
  variant,
5201
5723
  prefix
5202
- });
5203
- } else basePrefixes.add(prefix);
5724
+ }
5725
+ });
5204
5726
  }
5205
- for (const { cls, variant, prefix } of variantClasses) if (!basePrefixes.has(prefix)) context.report({
5206
- node: loc.node,
5207
- messageId: "missingBase",
5208
- data: {
5209
- className: cls,
5210
- variant,
5211
- prefix
5212
- }
5213
- });
5214
5727
  }
5215
5728
  }
5216
5729
  return createExtractorVisitors(context, check);
5217
5730
  }
5218
5731
  });
5219
5732
  //#endregion
5733
+ //#region src/utils/color-literal.ts
5734
+ /**
5735
+ * Does this CSS value contain a hardcoded color literal, anywhere in it?
5736
+ *
5737
+ * `no-hardcoded-colors` used to answer that with `^`-anchored regexes over the
5738
+ * whole value, which only ever matched a value that IS a color. Every real
5739
+ * shorthand slipped through: `shadow-[0_1px_2px_#000]` carries a hardcoded black
5740
+ * that the rule promised to catch and didn't. Anchoring also forced a companion
5741
+ * list of "color-bearing utility prefixes" to keep the match plausible, and that
5742
+ * list drifted from Tailwind (it has `ring` but not `inset-ring`, `shadow` but not
5743
+ * `inset-shadow`, and no way to spell an arbitrary property like `[color:#f00]`).
5744
+ *
5745
+ * Scanning the value instead of anchoring to it drops both problems: the value
5746
+ * carries the color or it doesn't, whatever utility it is attached to.
5747
+ *
5748
+ * Two things must NOT count, and they are why this is a scanner rather than a
5749
+ * regex:
5750
+ * - quoted strings — `content-['#fff']` is the text `#fff`, not a color;
5751
+ * - `url()` contents — `fill-[url(#gradient)]` references an SVG node by id, the
5752
+ * single most common `#` in a Tailwind class that isn't a color.
5753
+ *
5754
+ * The notation set is exactly the one the rule documents (hex + the CSS color
5755
+ * functions). Named colors (`bg-[red]`) are deliberately absent: they were never
5756
+ * covered, and `currentColor`/`transparent`/`inherit` make that a separate
5757
+ * judgement call rather than a scan.
5758
+ */
5759
+ /** CSS color functions. `color-mix` is absent on purpose: its arguments are scanned. */
5760
+ const COLOR_FUNCTIONS = /* @__PURE__ */ new Set([
5761
+ "rgb",
5762
+ "rgba",
5763
+ "hsl",
5764
+ "hsla",
5765
+ "hwb",
5766
+ "lab",
5767
+ "lch",
5768
+ "oklab",
5769
+ "oklch",
5770
+ "color"
5771
+ ]);
5772
+ /** Hex digit counts CSS accepts: `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`. */
5773
+ const HEX_LENGTHS = /* @__PURE__ */ new Set([
5774
+ 3,
5775
+ 4,
5776
+ 6,
5777
+ 8
5778
+ ]);
5779
+ function isHexDigit(ch) {
5780
+ return ch >= "0" && ch <= "9" || ch >= "a" && ch <= "f" || ch >= "A" && ch <= "F";
5781
+ }
5782
+ /**
5783
+ * `-` belongs to the identifier so `color-mix(` is not read as `color(`. `_` does
5784
+ * NOT: in a Tailwind arbitrary value an underscore stands for a space, so
5785
+ * `0_0_4px_rgb(…)` has to break into words or the function name never surfaces.
5786
+ */
5787
+ function isIdentChar(ch) {
5788
+ return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z" || ch >= "0" && ch <= "9" || ch === "-";
5789
+ }
5790
+ function isIdentStart(ch) {
5791
+ return ch >= "a" && ch <= "z" || ch >= "A" && ch <= "Z";
5792
+ }
5793
+ /** Index just past the closing quote (or end of input on an unterminated string). */
5794
+ function skipQuoted(value, start) {
5795
+ const quote = value[start];
5796
+ let i = start + 1;
5797
+ while (i < value.length) {
5798
+ if (value[i] === "\\") {
5799
+ i += 2;
5800
+ continue;
5801
+ }
5802
+ if (value[i] === quote) return i + 1;
5803
+ i++;
5804
+ }
5805
+ return value.length;
5806
+ }
5807
+ /** Index just past the matching `)`, given `open` pointing at a `(`. */
5808
+ function skipBalanced(value, open) {
5809
+ let depth = 0;
5810
+ let i = open;
5811
+ while (i < value.length) {
5812
+ const ch = value[i];
5813
+ if (ch === "\"" || ch === "'") {
5814
+ i = skipQuoted(value, i);
5815
+ continue;
5816
+ }
5817
+ if (ch === "(") depth++;
5818
+ else if (ch === ")") {
5819
+ depth--;
5820
+ if (depth === 0) return i + 1;
5821
+ }
5822
+ i++;
5823
+ }
5824
+ return value.length;
5825
+ }
5826
+ function containsColorLiteral(value) {
5827
+ let i = 0;
5828
+ while (i < value.length) {
5829
+ const ch = value[i];
5830
+ if (ch === "\"" || ch === "'") {
5831
+ i = skipQuoted(value, i);
5832
+ continue;
5833
+ }
5834
+ if (ch === "#") {
5835
+ let end = i + 1;
5836
+ while (end < value.length && isHexDigit(value[end])) end++;
5837
+ if (HEX_LENGTHS.has(end - i - 1)) return true;
5838
+ i = end > i + 1 ? end : i + 1;
5839
+ continue;
5840
+ }
5841
+ if (isIdentStart(ch)) {
5842
+ const start = i;
5843
+ while (i < value.length && isIdentChar(value[i])) i++;
5844
+ if (value[i] !== "(") continue;
5845
+ const name = value.slice(start, i).toLowerCase();
5846
+ if (name === "url") {
5847
+ i = skipBalanced(value, i);
5848
+ continue;
5849
+ }
5850
+ if (COLOR_FUNCTIONS.has(name)) return true;
5851
+ continue;
5852
+ }
5853
+ i++;
5854
+ }
5855
+ return false;
5856
+ }
5857
+ //#endregion
5220
5858
  //#region src/rules/no-hardcoded-colors.ts
5221
- const COLOR_UTILITY_PREFIXES = [
5222
- "bg",
5223
- "text",
5224
- "border",
5225
- "border-t",
5226
- "border-b",
5227
- "border-l",
5228
- "border-r",
5229
- "border-s",
5230
- "border-e",
5231
- "border-x",
5232
- "border-y",
5233
- "outline",
5234
- "ring",
5235
- "ring-offset",
5236
- "shadow",
5237
- "accent",
5238
- "caret",
5239
- "fill",
5240
- "stroke",
5241
- "decoration",
5242
- "divide",
5243
- "placeholder",
5244
- "from",
5245
- "via",
5246
- "to"
5247
- ];
5248
- const HEX_RE = /^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
5249
- const RGB_RE = /^rgba?\s*\(/;
5250
- const HSL_RE = /^hsla?\s*\(/;
5251
- const OKLCH_RE = /^oklch\s*\(/;
5252
- const OKLAB_RE = /^oklab\s*\(/;
5253
- const LCH_RE = /^lch\s*\(/;
5254
- const LAB_RE = /^lab\s*\(/;
5255
- const HWB_RE = /^hwb\s*\(/;
5256
- const COLOR_RE = /^color\s*\(/;
5257
5859
  const VAR_REF_RE = /var\(\s*--[\w-]+/i;
5860
+ /**
5861
+ * Does the arbitrary value the user wrote carry a hardcoded colour?
5862
+ *
5863
+ * This used to be a set of `^`-anchored regexes plus a list of "colour-bearing
5864
+ * utility prefixes", and both halves leaked. The anchoring meant only a value
5865
+ * that IS a colour matched, so `shadow-[0_1px_2px_#000]` passed. The prefix list
5866
+ * had `ring` but not `inset-ring`, `shadow` but not `inset-shadow`, and no way to
5867
+ * spell an arbitrary property at all (`[color:#f00]`, `[--brand:#f00]`).
5868
+ *
5869
+ * Neither is needed: the value carries the colour or it doesn't, whatever utility
5870
+ * it is attached to. `containsColorLiteral` skips quoted strings and `url()`
5871
+ * contents, which is what keeps `content-['#fff']` and `fill-[url(#gradient)]` out.
5872
+ */
5258
5873
  function isHardcodedColor(value) {
5259
5874
  const trimmed = value.trim();
5260
5875
  if (VAR_REF_RE.test(trimmed)) return false;
5261
- return HEX_RE.test(trimmed) || RGB_RE.test(trimmed) || HSL_RE.test(trimmed) || OKLCH_RE.test(trimmed) || OKLAB_RE.test(trimmed) || LCH_RE.test(trimmed) || LAB_RE.test(trimmed) || HWB_RE.test(trimmed) || COLOR_RE.test(trimmed);
5262
- }
5263
- function isColorUtility(utility) {
5264
- for (const prefix of COLOR_UTILITY_PREFIXES) if (utility === prefix || utility.startsWith(`${prefix}-`)) return true;
5265
- return false;
5876
+ return containsColorLiteral(trimmed);
5266
5877
  }
5267
5878
  const noHardcodedColors = defineRule({
5268
5879
  meta: {
@@ -5288,8 +5899,6 @@ const noHardcodedColors = defineRule({
5288
5899
  for (const cls of classes) {
5289
5900
  if (allowlist.has(cls)) continue;
5290
5901
  if (!hasArbitraryValue(cls)) continue;
5291
- const utility = splitImportant(extractUtility(cls)).bare;
5292
- if (!isColorUtility(utility)) continue;
5293
5902
  const value = getArbitraryValue(cls);
5294
5903
  if (!value) continue;
5295
5904
  if (isHardcodedColor(value)) context.report({
@@ -5320,13 +5929,9 @@ const noContradictingVariants = defineRule({
5320
5929
  createOnce(context) {
5321
5930
  const getDS = createLazyLoader(context);
5322
5931
  function variantFactsLookup() {
5323
- try {
5324
- const ds = getDS();
5325
- return (variant) => ds.cache.getVariantFacts(variant);
5326
- } catch (err) {
5327
- if (!isFatalError(err)) throw err;
5328
- return () => void 0;
5329
- }
5932
+ const ds = softGetDS(getDS);
5933
+ if (!ds) return () => void 0;
5934
+ return (variant) => ds.cache.getVariantFacts(variant);
5330
5935
  }
5331
5936
  function check(locations) {
5332
5937
  const factsFor = variantFactsLookup();
@@ -5473,15 +6078,9 @@ const consistentVariantOrder = defineRule({
5473
6078
  const priorityByEntry = /* @__PURE__ */ new Map();
5474
6079
  const prefixByEntry = /* @__PURE__ */ new Map();
5475
6080
  function resolveForFile() {
5476
- let dsCache = null;
5477
- let entryKey = "";
5478
- try {
5479
- const ds = getDS();
5480
- dsCache = ds.cache;
5481
- entryKey = ds.entryPoint;
5482
- } catch (err) {
5483
- if (!isFatalError(err)) throw err;
5484
- }
6081
+ const ds = softGetDS(getDS);
6082
+ const dsCache = ds ? ds.cache : null;
6083
+ const entryKey = ds ? ds.entryPoint : "";
5485
6084
  let priorityOf = priorityByEntry.get(entryKey);
5486
6085
  if (!priorityOf) {
5487
6086
  priorityOf = buildPriority(getOptions().order, dsCache);