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