oxlint-tailwindcss 1.0.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -722,6 +722,8 @@ var DesignSystemCache = class DesignSystemCache {
722
722
  _validClasses = [];
723
723
  _knownPrefixes = null;
724
724
  _maxOrder = 0n;
725
+ _prefix = "";
726
+ componentSet = /* @__PURE__ */ new Set();
725
727
  static fromPrecomputed(data) {
726
728
  const cache = new DesignSystemCache();
727
729
  cache._validClasses = data.validClasses;
@@ -734,7 +736,11 @@ var DesignSystemCache = class DesignSystemCache {
734
736
  }
735
737
  for (const [cls, props] of Object.entries(data.cssProps)) cache.cssPropsMap.set(cls, props);
736
738
  if (data.variantOrder) for (const [name, index] of Object.entries(data.variantOrder)) cache.variantOrderMap.set(name, index);
737
- if (data.componentClasses) for (const cls of data.componentClasses) cache.validitySet.add(cls);
739
+ if (data.componentClasses) for (const cls of data.componentClasses) {
740
+ cache.validitySet.add(cls);
741
+ cache.componentSet.add(cls);
742
+ }
743
+ cache._prefix = data.prefix ?? "";
738
744
  if (data.arbitraryEquivalents) for (const [arb, named] of Object.entries(data.arbitraryEquivalents)) cache.arbitraryEquivMap.set(arb, named);
739
745
  return cache;
740
746
  }
@@ -744,6 +750,10 @@ var DesignSystemCache = class DesignSystemCache {
744
750
  get maxOrder() {
745
751
  return this._maxOrder;
746
752
  }
753
+ /** Tailwind v4 project prefix (e.g. 'tw'); '' when none is configured. */
754
+ get prefix() {
755
+ return this._prefix;
756
+ }
747
757
  canonicalize(className) {
748
758
  const cached = this.canonicalMap.get(className);
749
759
  if (cached !== void 0) return cached;
@@ -842,7 +852,32 @@ var DesignSystemCache = class DesignSystemCache {
842
852
  if (bare.includes("(") && bare.includes(")")) return true;
843
853
  return false;
844
854
  }
855
+ /**
856
+ * Strict validity for `no-unknown-classes`, prefix-aware.
857
+ *
858
+ * - `'valid'` — usable as written.
859
+ * - `'missing-prefix'`— a real Tailwind utility written WITHOUT the required
860
+ * project prefix (`flex` under `prefix(tw)`); generates no CSS.
861
+ * - `'unknown'` — not a recognized class.
862
+ *
863
+ * When no prefix is configured this collapses to the tolerant `isValid`
864
+ * behavior. `isValid` itself stays tolerant (other rules call it with
865
+ * prefix-free candidates), so the strict check lives here.
866
+ */
867
+ classValidity(className) {
868
+ if (!this._prefix) return this.isValid(className) ? "valid" : "unknown";
869
+ const tag = this._prefix + ":";
870
+ const hadPrefix = className.startsWith(tag);
871
+ const body = hadPrefix ? className.slice(tag.length) : className;
872
+ let baseUtility = splitImportant(extractUtility(body)).bare;
873
+ const slashIdx = baseUtility.lastIndexOf("/");
874
+ if (slashIdx > 0) baseUtility = baseUtility.slice(0, slashIdx);
875
+ if (this.componentSet.has(baseUtility)) return "valid";
876
+ if (this.isValid(body)) return hadPrefix ? "valid" : "missing-prefix";
877
+ return "unknown";
878
+ }
845
879
  getOrder(className) {
880
+ if (this._prefix && className.startsWith(this._prefix + ":")) className = className.slice(this._prefix.length + 1);
846
881
  const cached = this.orderMap.get(className);
847
882
  if (cached !== void 0) return cached;
848
883
  const utility = extractUtility(className);
@@ -1173,6 +1208,16 @@ async function main() {
1173
1208
  const base = dirname(cssPath);
1174
1209
  const ds = await __unstable__loadDesignSystem(css, { base });
1175
1210
 
1211
+ // Tailwind v4 project prefix (\`@import "tailwindcss" prefix(tw)\`). getClassList()
1212
+ // returns names WITHOUT the prefix, but candidatesToCss/getClassOrder/
1213
+ // canonicalizeCandidates only resolve the PREFIXED form (\`tw:flex\`). We apply
1214
+ // the prefix only when calling the DS and strip it back off before storing, so
1215
+ // every structure stays prefix-free. The prefix is alphanumeric (no ':' '-' '['
1216
+ // ']' '/'), so \`prefix + ':'\` is an unambiguous separator.
1217
+ const prefix = (ds.theme && ds.theme.prefix) || '';
1218
+ const pfx = (c) => prefix ? prefix + ':' + c : c;
1219
+ const unpfx = (c) => (prefix && c.startsWith(prefix + ':')) ? c.slice(prefix.length + 1) : c;
1220
+
1176
1221
  const entries = ds.getClassList();
1177
1222
  const classNames = entries.map(e => e[0]);
1178
1223
 
@@ -1180,8 +1225,10 @@ async function main() {
1180
1225
  const classNameIndex = new Map();
1181
1226
  for (let i = 0; i < classNames.length; i++) classNameIndex.set(classNames[i], i);
1182
1227
 
1183
- // Validity: which classes produce CSS
1184
- const cssResults = ds.candidatesToCss(classNames);
1228
+ // Validity: which classes produce CSS. Validate the prefixed form, but keep
1229
+ // cssResults aligned positionally to the unprefixed classNames so the later
1230
+ // cssProps / arbitraryEquivalents phases keep indexing by position.
1231
+ const cssResults = ds.candidatesToCss(classNames.map(pfx));
1185
1232
  const validClasses = classNames.filter((_, i) => cssResults[i] != null);
1186
1233
 
1187
1234
  // Expand: validate extra candidates not in getClassList() but valid in v4
@@ -1203,7 +1250,7 @@ async function main() {
1203
1250
  }
1204
1251
  }
1205
1252
  if (extraCandidates.length > 0) {
1206
- const extraResults = ds.candidatesToCss(extraCandidates);
1253
+ const extraResults = ds.candidatesToCss(extraCandidates.map(pfx));
1207
1254
  for (let i = 0; i < extraCandidates.length; i++) {
1208
1255
  if (extraResults[i] != null) {
1209
1256
  validClasses.push(extraCandidates[i]);
@@ -1232,9 +1279,11 @@ async function main() {
1232
1279
  // NOTE: canonicalizeCandidates deduplicates, so we must call it one class at a time
1233
1280
  const canonical = {};
1234
1281
  for (const cls of classNames) {
1235
- const result = ds.canonicalizeCandidates([cls]);
1236
- if (result[0] && result[0] !== cls) {
1237
- canonical[cls] = result[0];
1282
+ const result = ds.canonicalizeCandidates([pfx(cls)]);
1283
+ const canon = result[0] ? unpfx(result[0]) : null;
1284
+ // Compare unprefixed-vs-unprefixed so the prefix itself never reads as a change.
1285
+ if (canon && canon !== cls) {
1286
+ canonical[cls] = canon;
1238
1287
  }
1239
1288
  }
1240
1289
 
@@ -1265,13 +1314,14 @@ async function main() {
1265
1314
  }
1266
1315
  const legacyToProcess = legacyCandidates.filter(cls => !validSet.has(cls));
1267
1316
  if (legacyToProcess.length > 0) {
1268
- const legacyCssResults = ds.candidatesToCss(legacyToProcess);
1317
+ const legacyCssResults = ds.candidatesToCss(legacyToProcess.map(pfx));
1269
1318
  for (let i = 0; i < legacyToProcess.length; i++) {
1270
1319
  if (legacyCssResults[i] == null) continue;
1271
1320
  const cls = legacyToProcess[i];
1272
- const result = ds.canonicalizeCandidates([cls]);
1273
- if (result[0] && result[0] !== cls) {
1274
- canonical[cls] = result[0];
1321
+ const result = ds.canonicalizeCandidates([pfx(cls)]);
1322
+ const canon = result[0] ? unpfx(result[0]) : null;
1323
+ if (canon && canon !== cls) {
1324
+ canonical[cls] = canon;
1275
1325
  }
1276
1326
  // Mark as valid so no-unknown-classes doesn't flag legacy spellings.
1277
1327
  validClasses.push(cls);
@@ -1285,9 +1335,9 @@ async function main() {
1285
1335
  if (!classNameIndex.has(cls)) allForOrder.push(cls);
1286
1336
  }
1287
1337
  const order = {};
1288
- const orderResults = ds.getClassOrder(allForOrder);
1338
+ const orderResults = ds.getClassOrder(allForOrder.map(pfx));
1289
1339
  for (const [name, val] of orderResults) {
1290
- if (val !== null) order[name] = val.toString();
1340
+ if (val !== null) order[unpfx(name)] = val.toString();
1291
1341
  }
1292
1342
 
1293
1343
  // CSS properties per class — extract only from the ROOT selector, not descendant selectors.
@@ -1376,7 +1426,9 @@ async function main() {
1376
1426
 
1377
1427
  for (let i = 0; i < classNames.length; i++) {
1378
1428
  if (cssResults[i]) {
1379
- const props = extractRootCssProps(cssResults[i], classNames[i]);
1429
+ // Match against the prefixed selector (the CSS emits \`.tw\\:flex\`), but
1430
+ // store under the unprefixed key. extractRootCssProps CSS-escapes the ':'.
1431
+ const props = extractRootCssProps(cssResults[i], pfx(classNames[i]));
1380
1432
  if (props.length > 0) cssProps[classNames[i]] = props;
1381
1433
  }
1382
1434
  }
@@ -1402,7 +1454,8 @@ async function main() {
1402
1454
  let acm;
1403
1455
  attrClassRe.lastIndex = 0;
1404
1456
  while ((acm = attrClassRe.exec(cssResults[i])) !== null) {
1405
- componentClasses.push(acm[1]);
1457
+ // Typography-style plugins emit \`[class~="tw:not-prose"]\` under a prefix.
1458
+ componentClasses.push(unpfx(acm[1]));
1406
1459
  }
1407
1460
  }
1408
1461
  }
@@ -1437,7 +1490,10 @@ async function main() {
1437
1490
  }
1438
1491
  if (candidates.length > 0) {
1439
1492
  const arbForms = candidates.map(c => c.arbitraryForm);
1440
- const arbResults = ds.candidatesToCss(arbForms);
1493
+ // Prefix only the validation; keys/values stored stay prefix-free. The
1494
+ // declaration block extractDeclarations compares is identical with or
1495
+ // without the prefix (the prefix only affects the selector).
1496
+ const arbResults = ds.candidatesToCss(arbForms.map(pfx));
1441
1497
  for (let i = 0; i < candidates.length; i++) {
1442
1498
  if (!arbResults[i]) continue;
1443
1499
  if (extractDeclarations(arbResults[i]) === extractDeclarations(candidates[i].namedCss)) {
@@ -1446,7 +1502,7 @@ async function main() {
1446
1502
  }
1447
1503
  }
1448
1504
 
1449
- const json = JSON.stringify({ validClasses, canonical, order, cssProps, variantOrder, componentClasses, arbitraryEquivalents });
1505
+ const json = JSON.stringify({ validClasses, canonical, order, cssProps, variantOrder, componentClasses, arbitraryEquivalents, prefix });
1450
1506
  // Atomic write: write to a unique temp path then rename, so a peer isolate
1451
1507
  // busy-waiting on the cache file never observes a half-written JSON.
1452
1508
  writeFileSync(WD_TMP_PATH, json);
@@ -2108,6 +2164,7 @@ const noUnknownClasses = defineRule({
2108
2164
  messages: {
2109
2165
  unknown: "\"{{className}}\" is not a valid Tailwind class.",
2110
2166
  unknownWithSuggestion: "\"{{className}}\" is not a valid Tailwind class. Did you mean \"{{suggestion}}\"?",
2167
+ missingPrefix: "\"{{className}}\" needs the \"{{prefix}}:\" prefix to produce CSS. Did you mean \"{{suggestion}}\"?",
2111
2168
  suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\".",
2112
2169
  ...DS_UNAVAILABLE_MESSAGE
2113
2170
  }
@@ -2136,9 +2193,34 @@ const noUnknownClasses = defineRule({
2136
2193
  const classes = split.classes;
2137
2194
  for (const cls of classes) {
2138
2195
  if (shouldIgnore(cls)) continue;
2196
+ const validity = cache.classValidity(cls);
2197
+ if (validity === "valid") continue;
2139
2198
  const stripped = stripModifiers(cls);
2140
- if (cache.isValid(stripped)) continue;
2141
2199
  if (DEPRECATED_MAP[stripped]) continue;
2200
+ if (validity === "missing-prefix") {
2201
+ const fixed = `${cache.prefix}:${cls}`;
2202
+ const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? fixed : c));
2203
+ context.report({
2204
+ node: loc.node,
2205
+ messageId: "missingPrefix",
2206
+ data: {
2207
+ className: cls,
2208
+ prefix: cache.prefix,
2209
+ suggestion: fixed
2210
+ },
2211
+ suggest: [{
2212
+ messageId: "suggestReplace",
2213
+ data: {
2214
+ className: cls,
2215
+ replacement: fixed
2216
+ },
2217
+ fix(fixer) {
2218
+ return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
2219
+ }
2220
+ }]
2221
+ });
2222
+ continue;
2223
+ }
2142
2224
  const suggestion = findBestSuggestion(stripped, cache.validClasses);
2143
2225
  if (suggestion) {
2144
2226
  const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? suggestion : c));
@@ -2830,7 +2912,10 @@ const enforceSortOrder = defineRule({
2830
2912
  groupClasses.length = 0;
2831
2913
  for (const [name] of ordered) groupClasses.push(name);
2832
2914
  }
2833
- const sortedGroupKeys = [...groups.keys()].sort((a, b) => {
2915
+ const stripKey = (k) => cache.prefix && k.startsWith(cache.prefix + ":") ? k.slice(cache.prefix.length + 1) : k;
2916
+ const sortedGroupKeys = [...groups.keys()].sort((ka, kb) => {
2917
+ const a = stripKey(ka);
2918
+ const b = stripKey(kb);
2834
2919
  if (a === "" && b !== "") return -1;
2835
2920
  if (a !== "" && b === "") return 1;
2836
2921
  if (a === "" && b === "") return 0;
@@ -2865,7 +2950,7 @@ const enforceSortOrder = defineRule({
2865
2950
  });
2866
2951
  //#endregion
2867
2952
  //#region src/rules/enforce-shorthand.ts
2868
- const VALUE_RE = /^(?:m[trbl]|p[trbl]|[wh]|rounded-t[lr]|rounded-b[lr]|min-[wh]|max-[wh])-(.+)$/;
2953
+ const VALUE_RE = /^(?:m[trbl]|mx|my|p[trbl]|px|py|[wh]|rounded-t[lr]|rounded-b[lr]|min-[wh]|max-[wh])-(.+)$/;
2869
2954
  const INVALID_SIZE_VALUES = new Set([
2870
2955
  "screen",
2871
2956
  "dvw",
@@ -2898,6 +2983,10 @@ function createShorthandRules(value) {
2898
2983
  parts: [`ml-${value}`, `mr-${value}`],
2899
2984
  replacement: `mx-${value}`
2900
2985
  },
2986
+ {
2987
+ parts: [`mx-${value}`, `my-${value}`],
2988
+ replacement: `m-${value}`
2989
+ },
2901
2990
  {
2902
2991
  parts: [
2903
2992
  `pt-${value}`,
@@ -2915,6 +3004,10 @@ function createShorthandRules(value) {
2915
3004
  parts: [`pl-${value}`, `pr-${value}`],
2916
3005
  replacement: `px-${value}`
2917
3006
  },
3007
+ {
3008
+ parts: [`px-${value}`, `py-${value}`],
3009
+ replacement: `p-${value}`
3010
+ },
2918
3011
  ...!INVALID_SIZE_VALUES.has(value) ? [{
2919
3012
  parts: [`w-${value}`, `h-${value}`],
2920
3013
  replacement: `size-${value}`
@@ -2945,29 +3038,33 @@ const enforceShorthand = defineRule({
2945
3038
  const classes = split.classes;
2946
3039
  if (classes.length < 2) continue;
2947
3040
  const classSet = new Set(classes);
2948
- const values = /* @__PURE__ */ new Set();
3041
+ const variantValues = /* @__PURE__ */ new Set();
2949
3042
  for (const cls of classes) {
2950
- const match = VALUE_RE.exec(splitImportant(cls).bare);
2951
- if (match) values.add(match[1]);
3043
+ const { utility, variant } = splitUtilityAndVariant(cls);
3044
+ const match = VALUE_RE.exec(splitImportant(utility).bare);
3045
+ if (match) variantValues.add(`${variant}\0${match[1]}`);
2952
3046
  }
2953
- for (const value of values) {
2954
- const rules = createShorthandRules(value);
3047
+ for (const variantValue of variantValues) {
3048
+ const nul = variantValue.indexOf("\0");
3049
+ const variant = variantValue.slice(0, nul);
3050
+ const rules = createShorthandRules(variantValue.slice(nul + 1));
2955
3051
  for (const rule of rules) {
2956
- const hasImportantPrefix = rule.parts.every((p) => classSet.has(`!${p}`));
2957
- const hasImportantSuffix = !hasImportantPrefix && rule.parts.every((p) => classSet.has(`${p}!`));
2958
- const hasPlain = rule.parts.every((p) => classSet.has(p));
3052
+ const withVariant = (p) => `${variant}${p}`;
3053
+ const hasImportantPrefix = rule.parts.every((p) => classSet.has(withVariant(`!${p}`)));
3054
+ const hasImportantSuffix = !hasImportantPrefix && rule.parts.every((p) => classSet.has(withVariant(`${p}!`)));
3055
+ const hasPlain = rule.parts.every((p) => classSet.has(withVariant(p)));
2959
3056
  if (!hasImportantPrefix && !hasImportantSuffix && !hasPlain) continue;
2960
3057
  const importantStart = hasImportantPrefix ? "!" : "";
2961
3058
  const importantEnd = hasImportantSuffix ? "!" : "";
2962
- const matchParts = rule.parts.map((p) => `${importantStart}${p}${importantEnd}`);
3059
+ const matchParts = rule.parts.map((p) => withVariant(`${importantStart}${p}${importantEnd}`));
2963
3060
  const remaining = classes.filter((c) => !matchParts.includes(c));
2964
- remaining.push(`${importantStart}${rule.replacement}${importantEnd}`);
3061
+ remaining.push(withVariant(`${importantStart}${rule.replacement}${importantEnd}`));
2965
3062
  context.report({
2966
3063
  node: loc.node,
2967
3064
  messageId: "shorthand",
2968
3065
  data: {
2969
3066
  parts: matchParts.map((p) => `"${p}"`).join(", "),
2970
- replacement: `${importantStart}${rule.replacement}${importantEnd}`
3067
+ replacement: withVariant(`${importantStart}${rule.replacement}${importantEnd}`)
2971
3068
  },
2972
3069
  fix(fixer) {
2973
3070
  return fixer.replaceTextRange(loc.range, preserveSpaces(loc, rebuildClassString(split, remaining)));
@@ -3900,8 +3997,23 @@ const consistentVariantOrder = defineRule({
3900
3997
  const fallback = DEFAULT_VARIANT_ORDER.length;
3901
3998
  return (v) => map.get(v) ?? fallback;
3902
3999
  });
4000
+ const getPrefix = createLazyOptions(context, () => {
4001
+ try {
4002
+ return getDS().cache.prefix;
4003
+ } catch (err) {
4004
+ if (!isFatalError(err)) throw err;
4005
+ return "";
4006
+ }
4007
+ });
3903
4008
  function reorderClass(cls) {
3904
- const variants = extractVariants(cls);
4009
+ const prefix = getPrefix();
4010
+ let pfx = "";
4011
+ let body = cls;
4012
+ if (prefix && cls.startsWith(prefix + ":")) {
4013
+ pfx = prefix + ":";
4014
+ body = cls.slice(prefix.length + 1);
4015
+ }
4016
+ const variants = extractVariants(body);
3905
4017
  if (variants.length < 2) return null;
3906
4018
  const priorityOf = getPriority();
3907
4019
  const sorted = [...variants].sort((a, b) => priorityOf(a) - priorityOf(b));
@@ -3911,8 +4023,8 @@ const consistentVariantOrder = defineRule({
3911
4023
  else nonPseudo.push(v);
3912
4024
  const final = nonPseudo.length > 0 && pseudo.length > 0 ? [...nonPseudo, ...pseudo] : sorted;
3913
4025
  if (variants.every((v, i) => v === final[i])) return null;
3914
- const utility = extractUtility(cls);
3915
- return final.join(":") + ":" + utility;
4026
+ const utility = extractUtility(body);
4027
+ return pfx + final.join(":") + ":" + utility;
3916
4028
  }
3917
4029
  function check(locations) {
3918
4030
  for (const loc of locations) {