oxlint-tailwindcss 1.1.0 → 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.cjs +122 -22
- package/dist/index.mjs +122 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -718,6 +718,8 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
718
718
|
_validClasses = [];
|
|
719
719
|
_knownPrefixes = null;
|
|
720
720
|
_maxOrder = 0n;
|
|
721
|
+
_prefix = "";
|
|
722
|
+
componentSet = /* @__PURE__ */ new Set();
|
|
721
723
|
static fromPrecomputed(data) {
|
|
722
724
|
const cache = new DesignSystemCache();
|
|
723
725
|
cache._validClasses = data.validClasses;
|
|
@@ -730,7 +732,11 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
730
732
|
}
|
|
731
733
|
for (const [cls, props] of Object.entries(data.cssProps)) cache.cssPropsMap.set(cls, props);
|
|
732
734
|
if (data.variantOrder) for (const [name, index] of Object.entries(data.variantOrder)) cache.variantOrderMap.set(name, index);
|
|
733
|
-
if (data.componentClasses) for (const cls of data.componentClasses)
|
|
735
|
+
if (data.componentClasses) for (const cls of data.componentClasses) {
|
|
736
|
+
cache.validitySet.add(cls);
|
|
737
|
+
cache.componentSet.add(cls);
|
|
738
|
+
}
|
|
739
|
+
cache._prefix = data.prefix ?? "";
|
|
734
740
|
if (data.arbitraryEquivalents) for (const [arb, named] of Object.entries(data.arbitraryEquivalents)) cache.arbitraryEquivMap.set(arb, named);
|
|
735
741
|
return cache;
|
|
736
742
|
}
|
|
@@ -740,6 +746,10 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
740
746
|
get maxOrder() {
|
|
741
747
|
return this._maxOrder;
|
|
742
748
|
}
|
|
749
|
+
/** Tailwind v4 project prefix (e.g. 'tw'); '' when none is configured. */
|
|
750
|
+
get prefix() {
|
|
751
|
+
return this._prefix;
|
|
752
|
+
}
|
|
743
753
|
canonicalize(className) {
|
|
744
754
|
const cached = this.canonicalMap.get(className);
|
|
745
755
|
if (cached !== void 0) return cached;
|
|
@@ -838,7 +848,32 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
838
848
|
if (bare.includes("(") && bare.includes(")")) return true;
|
|
839
849
|
return false;
|
|
840
850
|
}
|
|
851
|
+
/**
|
|
852
|
+
* Strict validity for `no-unknown-classes`, prefix-aware.
|
|
853
|
+
*
|
|
854
|
+
* - `'valid'` — usable as written.
|
|
855
|
+
* - `'missing-prefix'`— a real Tailwind utility written WITHOUT the required
|
|
856
|
+
* project prefix (`flex` under `prefix(tw)`); generates no CSS.
|
|
857
|
+
* - `'unknown'` — not a recognized class.
|
|
858
|
+
*
|
|
859
|
+
* When no prefix is configured this collapses to the tolerant `isValid`
|
|
860
|
+
* behavior. `isValid` itself stays tolerant (other rules call it with
|
|
861
|
+
* prefix-free candidates), so the strict check lives here.
|
|
862
|
+
*/
|
|
863
|
+
classValidity(className) {
|
|
864
|
+
if (!this._prefix) return this.isValid(className) ? "valid" : "unknown";
|
|
865
|
+
const tag = this._prefix + ":";
|
|
866
|
+
const hadPrefix = className.startsWith(tag);
|
|
867
|
+
const body = hadPrefix ? className.slice(tag.length) : className;
|
|
868
|
+
let baseUtility = splitImportant(extractUtility(body)).bare;
|
|
869
|
+
const slashIdx = baseUtility.lastIndexOf("/");
|
|
870
|
+
if (slashIdx > 0) baseUtility = baseUtility.slice(0, slashIdx);
|
|
871
|
+
if (this.componentSet.has(baseUtility)) return "valid";
|
|
872
|
+
if (this.isValid(body)) return hadPrefix ? "valid" : "missing-prefix";
|
|
873
|
+
return "unknown";
|
|
874
|
+
}
|
|
841
875
|
getOrder(className) {
|
|
876
|
+
if (this._prefix && className.startsWith(this._prefix + ":")) className = className.slice(this._prefix.length + 1);
|
|
842
877
|
const cached = this.orderMap.get(className);
|
|
843
878
|
if (cached !== void 0) return cached;
|
|
844
879
|
const utility = extractUtility(className);
|
|
@@ -1169,6 +1204,16 @@ async function main() {
|
|
|
1169
1204
|
const base = dirname(cssPath);
|
|
1170
1205
|
const ds = await __unstable__loadDesignSystem(css, { base });
|
|
1171
1206
|
|
|
1207
|
+
// Tailwind v4 project prefix (\`@import "tailwindcss" prefix(tw)\`). getClassList()
|
|
1208
|
+
// returns names WITHOUT the prefix, but candidatesToCss/getClassOrder/
|
|
1209
|
+
// canonicalizeCandidates only resolve the PREFIXED form (\`tw:flex\`). We apply
|
|
1210
|
+
// the prefix only when calling the DS and strip it back off before storing, so
|
|
1211
|
+
// every structure stays prefix-free. The prefix is alphanumeric (no ':' '-' '['
|
|
1212
|
+
// ']' '/'), so \`prefix + ':'\` is an unambiguous separator.
|
|
1213
|
+
const prefix = (ds.theme && ds.theme.prefix) || '';
|
|
1214
|
+
const pfx = (c) => prefix ? prefix + ':' + c : c;
|
|
1215
|
+
const unpfx = (c) => (prefix && c.startsWith(prefix + ':')) ? c.slice(prefix.length + 1) : c;
|
|
1216
|
+
|
|
1172
1217
|
const entries = ds.getClassList();
|
|
1173
1218
|
const classNames = entries.map(e => e[0]);
|
|
1174
1219
|
|
|
@@ -1176,8 +1221,10 @@ async function main() {
|
|
|
1176
1221
|
const classNameIndex = new Map();
|
|
1177
1222
|
for (let i = 0; i < classNames.length; i++) classNameIndex.set(classNames[i], i);
|
|
1178
1223
|
|
|
1179
|
-
// Validity: which classes produce CSS
|
|
1180
|
-
|
|
1224
|
+
// Validity: which classes produce CSS. Validate the prefixed form, but keep
|
|
1225
|
+
// cssResults aligned positionally to the unprefixed classNames so the later
|
|
1226
|
+
// cssProps / arbitraryEquivalents phases keep indexing by position.
|
|
1227
|
+
const cssResults = ds.candidatesToCss(classNames.map(pfx));
|
|
1181
1228
|
const validClasses = classNames.filter((_, i) => cssResults[i] != null);
|
|
1182
1229
|
|
|
1183
1230
|
// Expand: validate extra candidates not in getClassList() but valid in v4
|
|
@@ -1199,7 +1246,7 @@ async function main() {
|
|
|
1199
1246
|
}
|
|
1200
1247
|
}
|
|
1201
1248
|
if (extraCandidates.length > 0) {
|
|
1202
|
-
const extraResults = ds.candidatesToCss(extraCandidates);
|
|
1249
|
+
const extraResults = ds.candidatesToCss(extraCandidates.map(pfx));
|
|
1203
1250
|
for (let i = 0; i < extraCandidates.length; i++) {
|
|
1204
1251
|
if (extraResults[i] != null) {
|
|
1205
1252
|
validClasses.push(extraCandidates[i]);
|
|
@@ -1228,9 +1275,11 @@ async function main() {
|
|
|
1228
1275
|
// NOTE: canonicalizeCandidates deduplicates, so we must call it one class at a time
|
|
1229
1276
|
const canonical = {};
|
|
1230
1277
|
for (const cls of classNames) {
|
|
1231
|
-
const result = ds.canonicalizeCandidates([cls]);
|
|
1232
|
-
|
|
1233
|
-
|
|
1278
|
+
const result = ds.canonicalizeCandidates([pfx(cls)]);
|
|
1279
|
+
const canon = result[0] ? unpfx(result[0]) : null;
|
|
1280
|
+
// Compare unprefixed-vs-unprefixed so the prefix itself never reads as a change.
|
|
1281
|
+
if (canon && canon !== cls) {
|
|
1282
|
+
canonical[cls] = canon;
|
|
1234
1283
|
}
|
|
1235
1284
|
}
|
|
1236
1285
|
|
|
@@ -1261,13 +1310,14 @@ async function main() {
|
|
|
1261
1310
|
}
|
|
1262
1311
|
const legacyToProcess = legacyCandidates.filter(cls => !validSet.has(cls));
|
|
1263
1312
|
if (legacyToProcess.length > 0) {
|
|
1264
|
-
const legacyCssResults = ds.candidatesToCss(legacyToProcess);
|
|
1313
|
+
const legacyCssResults = ds.candidatesToCss(legacyToProcess.map(pfx));
|
|
1265
1314
|
for (let i = 0; i < legacyToProcess.length; i++) {
|
|
1266
1315
|
if (legacyCssResults[i] == null) continue;
|
|
1267
1316
|
const cls = legacyToProcess[i];
|
|
1268
|
-
const result = ds.canonicalizeCandidates([cls]);
|
|
1269
|
-
|
|
1270
|
-
|
|
1317
|
+
const result = ds.canonicalizeCandidates([pfx(cls)]);
|
|
1318
|
+
const canon = result[0] ? unpfx(result[0]) : null;
|
|
1319
|
+
if (canon && canon !== cls) {
|
|
1320
|
+
canonical[cls] = canon;
|
|
1271
1321
|
}
|
|
1272
1322
|
// Mark as valid so no-unknown-classes doesn't flag legacy spellings.
|
|
1273
1323
|
validClasses.push(cls);
|
|
@@ -1281,9 +1331,9 @@ async function main() {
|
|
|
1281
1331
|
if (!classNameIndex.has(cls)) allForOrder.push(cls);
|
|
1282
1332
|
}
|
|
1283
1333
|
const order = {};
|
|
1284
|
-
const orderResults = ds.getClassOrder(allForOrder);
|
|
1334
|
+
const orderResults = ds.getClassOrder(allForOrder.map(pfx));
|
|
1285
1335
|
for (const [name, val] of orderResults) {
|
|
1286
|
-
if (val !== null) order[name] = val.toString();
|
|
1336
|
+
if (val !== null) order[unpfx(name)] = val.toString();
|
|
1287
1337
|
}
|
|
1288
1338
|
|
|
1289
1339
|
// CSS properties per class — extract only from the ROOT selector, not descendant selectors.
|
|
@@ -1372,7 +1422,9 @@ async function main() {
|
|
|
1372
1422
|
|
|
1373
1423
|
for (let i = 0; i < classNames.length; i++) {
|
|
1374
1424
|
if (cssResults[i]) {
|
|
1375
|
-
|
|
1425
|
+
// Match against the prefixed selector (the CSS emits \`.tw\\:flex\`), but
|
|
1426
|
+
// store under the unprefixed key. extractRootCssProps CSS-escapes the ':'.
|
|
1427
|
+
const props = extractRootCssProps(cssResults[i], pfx(classNames[i]));
|
|
1376
1428
|
if (props.length > 0) cssProps[classNames[i]] = props;
|
|
1377
1429
|
}
|
|
1378
1430
|
}
|
|
@@ -1398,7 +1450,8 @@ async function main() {
|
|
|
1398
1450
|
let acm;
|
|
1399
1451
|
attrClassRe.lastIndex = 0;
|
|
1400
1452
|
while ((acm = attrClassRe.exec(cssResults[i])) !== null) {
|
|
1401
|
-
|
|
1453
|
+
// Typography-style plugins emit \`[class~="tw:not-prose"]\` under a prefix.
|
|
1454
|
+
componentClasses.push(unpfx(acm[1]));
|
|
1402
1455
|
}
|
|
1403
1456
|
}
|
|
1404
1457
|
}
|
|
@@ -1433,7 +1486,10 @@ async function main() {
|
|
|
1433
1486
|
}
|
|
1434
1487
|
if (candidates.length > 0) {
|
|
1435
1488
|
const arbForms = candidates.map(c => c.arbitraryForm);
|
|
1436
|
-
|
|
1489
|
+
// Prefix only the validation; keys/values stored stay prefix-free. The
|
|
1490
|
+
// declaration block extractDeclarations compares is identical with or
|
|
1491
|
+
// without the prefix (the prefix only affects the selector).
|
|
1492
|
+
const arbResults = ds.candidatesToCss(arbForms.map(pfx));
|
|
1437
1493
|
for (let i = 0; i < candidates.length; i++) {
|
|
1438
1494
|
if (!arbResults[i]) continue;
|
|
1439
1495
|
if (extractDeclarations(arbResults[i]) === extractDeclarations(candidates[i].namedCss)) {
|
|
@@ -1442,7 +1498,7 @@ async function main() {
|
|
|
1442
1498
|
}
|
|
1443
1499
|
}
|
|
1444
1500
|
|
|
1445
|
-
const json = JSON.stringify({ validClasses, canonical, order, cssProps, variantOrder, componentClasses, arbitraryEquivalents });
|
|
1501
|
+
const json = JSON.stringify({ validClasses, canonical, order, cssProps, variantOrder, componentClasses, arbitraryEquivalents, prefix });
|
|
1446
1502
|
// Atomic write: write to a unique temp path then rename, so a peer isolate
|
|
1447
1503
|
// busy-waiting on the cache file never observes a half-written JSON.
|
|
1448
1504
|
writeFileSync(WD_TMP_PATH, json);
|
|
@@ -2104,6 +2160,7 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2104
2160
|
messages: {
|
|
2105
2161
|
unknown: "\"{{className}}\" is not a valid Tailwind class.",
|
|
2106
2162
|
unknownWithSuggestion: "\"{{className}}\" is not a valid Tailwind class. Did you mean \"{{suggestion}}\"?",
|
|
2163
|
+
missingPrefix: "\"{{className}}\" needs the \"{{prefix}}:\" prefix to produce CSS. Did you mean \"{{suggestion}}\"?",
|
|
2107
2164
|
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\".",
|
|
2108
2165
|
...DS_UNAVAILABLE_MESSAGE
|
|
2109
2166
|
}
|
|
@@ -2132,9 +2189,34 @@ const noUnknownClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2132
2189
|
const classes = split.classes;
|
|
2133
2190
|
for (const cls of classes) {
|
|
2134
2191
|
if (shouldIgnore(cls)) continue;
|
|
2192
|
+
const validity = cache.classValidity(cls);
|
|
2193
|
+
if (validity === "valid") continue;
|
|
2135
2194
|
const stripped = stripModifiers(cls);
|
|
2136
|
-
if (cache.isValid(stripped)) continue;
|
|
2137
2195
|
if (DEPRECATED_MAP[stripped]) continue;
|
|
2196
|
+
if (validity === "missing-prefix") {
|
|
2197
|
+
const fixed = `${cache.prefix}:${cls}`;
|
|
2198
|
+
const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? fixed : c));
|
|
2199
|
+
context.report({
|
|
2200
|
+
node: loc.node,
|
|
2201
|
+
messageId: "missingPrefix",
|
|
2202
|
+
data: {
|
|
2203
|
+
className: cls,
|
|
2204
|
+
prefix: cache.prefix,
|
|
2205
|
+
suggestion: fixed
|
|
2206
|
+
},
|
|
2207
|
+
suggest: [{
|
|
2208
|
+
messageId: "suggestReplace",
|
|
2209
|
+
data: {
|
|
2210
|
+
className: cls,
|
|
2211
|
+
replacement: fixed
|
|
2212
|
+
},
|
|
2213
|
+
fix(fixer) {
|
|
2214
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
2215
|
+
}
|
|
2216
|
+
}]
|
|
2217
|
+
});
|
|
2218
|
+
continue;
|
|
2219
|
+
}
|
|
2138
2220
|
const suggestion = findBestSuggestion(stripped, cache.validClasses);
|
|
2139
2221
|
if (suggestion) {
|
|
2140
2222
|
const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? suggestion : c));
|
|
@@ -2826,7 +2908,10 @@ const enforceSortOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
2826
2908
|
groupClasses.length = 0;
|
|
2827
2909
|
for (const [name] of ordered) groupClasses.push(name);
|
|
2828
2910
|
}
|
|
2829
|
-
const
|
|
2911
|
+
const stripKey = (k) => cache.prefix && k.startsWith(cache.prefix + ":") ? k.slice(cache.prefix.length + 1) : k;
|
|
2912
|
+
const sortedGroupKeys = [...groups.keys()].sort((ka, kb) => {
|
|
2913
|
+
const a = stripKey(ka);
|
|
2914
|
+
const b = stripKey(kb);
|
|
2830
2915
|
if (a === "" && b !== "") return -1;
|
|
2831
2916
|
if (a !== "" && b === "") return 1;
|
|
2832
2917
|
if (a === "" && b === "") return 0;
|
|
@@ -3908,8 +3993,23 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
3908
3993
|
const fallback = DEFAULT_VARIANT_ORDER.length;
|
|
3909
3994
|
return (v) => map.get(v) ?? fallback;
|
|
3910
3995
|
});
|
|
3996
|
+
const getPrefix = createLazyOptions(context, () => {
|
|
3997
|
+
try {
|
|
3998
|
+
return getDS().cache.prefix;
|
|
3999
|
+
} catch (err) {
|
|
4000
|
+
if (!isFatalError(err)) throw err;
|
|
4001
|
+
return "";
|
|
4002
|
+
}
|
|
4003
|
+
});
|
|
3911
4004
|
function reorderClass(cls) {
|
|
3912
|
-
const
|
|
4005
|
+
const prefix = getPrefix();
|
|
4006
|
+
let pfx = "";
|
|
4007
|
+
let body = cls;
|
|
4008
|
+
if (prefix && cls.startsWith(prefix + ":")) {
|
|
4009
|
+
pfx = prefix + ":";
|
|
4010
|
+
body = cls.slice(prefix.length + 1);
|
|
4011
|
+
}
|
|
4012
|
+
const variants = extractVariants(body);
|
|
3913
4013
|
if (variants.length < 2) return null;
|
|
3914
4014
|
const priorityOf = getPriority();
|
|
3915
4015
|
const sorted = [...variants].sort((a, b) => priorityOf(a) - priorityOf(b));
|
|
@@ -3919,8 +4019,8 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
3919
4019
|
else nonPseudo.push(v);
|
|
3920
4020
|
const final = nonPseudo.length > 0 && pseudo.length > 0 ? [...nonPseudo, ...pseudo] : sorted;
|
|
3921
4021
|
if (variants.every((v, i) => v === final[i])) return null;
|
|
3922
|
-
const utility = extractUtility(
|
|
3923
|
-
return final.join(":") + ":" + utility;
|
|
4022
|
+
const utility = extractUtility(body);
|
|
4023
|
+
return pfx + final.join(":") + ":" + utility;
|
|
3924
4024
|
}
|
|
3925
4025
|
function check(locations) {
|
|
3926
4026
|
for (const loc of locations) {
|
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)
|
|
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
|
-
|
|
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
|
-
|
|
1237
|
-
|
|
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
|
-
|
|
1274
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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;
|
|
@@ -3912,8 +3997,23 @@ const consistentVariantOrder = defineRule({
|
|
|
3912
3997
|
const fallback = DEFAULT_VARIANT_ORDER.length;
|
|
3913
3998
|
return (v) => map.get(v) ?? fallback;
|
|
3914
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
|
+
});
|
|
3915
4008
|
function reorderClass(cls) {
|
|
3916
|
-
const
|
|
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);
|
|
3917
4017
|
if (variants.length < 2) return null;
|
|
3918
4018
|
const priorityOf = getPriority();
|
|
3919
4019
|
const sorted = [...variants].sort((a, b) => priorityOf(a) - priorityOf(b));
|
|
@@ -3923,8 +4023,8 @@ const consistentVariantOrder = defineRule({
|
|
|
3923
4023
|
else nonPseudo.push(v);
|
|
3924
4024
|
const final = nonPseudo.length > 0 && pseudo.length > 0 ? [...nonPseudo, ...pseudo] : sorted;
|
|
3925
4025
|
if (variants.every((v, i) => v === final[i])) return null;
|
|
3926
|
-
const utility = extractUtility(
|
|
3927
|
-
return final.join(":") + ":" + utility;
|
|
4026
|
+
const utility = extractUtility(body);
|
|
4027
|
+
return pfx + final.join(":") + ":" + utility;
|
|
3928
4028
|
}
|
|
3929
4029
|
function check(locations) {
|
|
3930
4030
|
for (const loc of locations) {
|