oxlint-tailwindcss 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/dist/index.cjs +242 -60
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +242 -60
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -990,6 +990,13 @@ the box. If you find one that doesn't, open an issue.
|
|
|
990
990
|
- Tailwind CSS v4
|
|
991
991
|
- oxlint >= 1.43.0
|
|
992
992
|
|
|
993
|
+
> **oxlint 1.77.0 crashes the language server.** Not a plugin bug, but you'll hit it through us:
|
|
994
|
+
> 1.77.0 panics the oxlint **language server** on any diagnostic from any JS plugin
|
|
995
|
+
> (`disable_fix.rs:52`, then SIGABRT and a restart loop). The upstream repro uses a different plugin
|
|
996
|
+
> — [oxc#25278](https://github.com/oxc-project/oxc/issues/25278) — and the fix
|
|
997
|
+
> ([oxc#25280](https://github.com/oxc-project/oxc/pull/25280)) is not released yet. The CLI is
|
|
998
|
+
> unaffected, so CI is fine; if you use the editor extension, pin `oxlint@1.76.0` for now.
|
|
999
|
+
|
|
993
1000
|
## License
|
|
994
1001
|
|
|
995
1002
|
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@ let node_crypto = require("node:crypto");
|
|
|
3
3
|
let node_fs = require("node:fs");
|
|
4
4
|
let node_path = require("node:path");
|
|
5
5
|
let node_os = require("node:os");
|
|
6
|
-
//#region ../../node_modules/.pnpm/@oxlint+plugins@1.
|
|
6
|
+
//#region ../../node_modules/.pnpm/@oxlint+plugins@1.77.0/node_modules/@oxlint/plugins/index.js
|
|
7
7
|
/**
|
|
8
8
|
* Define a plugin.
|
|
9
9
|
*
|
|
@@ -514,24 +514,58 @@ function splitClassesWithSeparators(classString) {
|
|
|
514
514
|
};
|
|
515
515
|
}
|
|
516
516
|
/**
|
|
517
|
+
* The separator to place before an output class whose source class sits at
|
|
518
|
+
* original index `si`, given the previous output class came from `sPrev`.
|
|
519
|
+
*
|
|
520
|
+
* - **forward move** (`si > sPrev`): the classes between them were dropped, so
|
|
521
|
+
* the effective separator is the LAST newline-bearing separator in that gap
|
|
522
|
+
* (it carries the correct indent), else the separator immediately preceding
|
|
523
|
+
* `si`. This transfers a line break forward when the class that opened a line
|
|
524
|
+
* is removed, so the next survivor keeps its own line.
|
|
525
|
+
* - **non-forward move** (append / reorder — e.g. `enforce-shorthand` pushes the
|
|
526
|
+
* merged replacement to the end): reuse `si`'s own preceding separator if it
|
|
527
|
+
* carries a newline, else a single space — never the (possibly empty) leader,
|
|
528
|
+
* so output classes never glue together.
|
|
529
|
+
*/
|
|
530
|
+
function pickSeparator(separators, sPrev, si) {
|
|
531
|
+
if (si > sPrev) {
|
|
532
|
+
let chosen = separators[si] ?? " ";
|
|
533
|
+
for (let k = sPrev + 1; k <= si; k++) if (separators[k]?.includes("\n")) chosen = separators[k];
|
|
534
|
+
return chosen;
|
|
535
|
+
}
|
|
536
|
+
const own = separators[si];
|
|
537
|
+
return own && own.includes("\n") ? own : " ";
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
517
540
|
* Reconstruct a class string from a `ClassSplit` and a (possibly transformed)
|
|
518
541
|
* array of classes.
|
|
519
542
|
*
|
|
520
|
-
* - If `newClasses.length === split.classes.length`
|
|
521
|
-
* canonicalize, sort, variant-order, etc.)
|
|
522
|
-
* verbatim. This keeps multiline indentation
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
543
|
+
* - If `newClasses.length === split.classes.length` and no `sourceIndices` are
|
|
544
|
+
* given (1-to-1 transformation: canonicalize, sort, variant-order, etc.)
|
|
545
|
+
* every separator is preserved verbatim. This keeps multiline indentation
|
|
546
|
+
* intact.
|
|
547
|
+
* - If `sourceIndices` is given (count-changing transforms that know where each
|
|
548
|
+
* output class came from: no-duplicate removes dupes, shorthand collapses
|
|
549
|
+
* pairs) the layout is preserved structurally — leader and trailing stay
|
|
550
|
+
* verbatim (edge-safe) and each interior separator is recovered from the
|
|
551
|
+
* source via `pickSeparator`, so a multiline block keeps its per-line grouping
|
|
552
|
+
* instead of reflowing to one class per line.
|
|
553
|
+
* - Otherwise (count differs, no mapping) it degrades gracefully: leading and
|
|
554
|
+
* trailing whitespace are preserved; classes are joined by the first internal
|
|
555
|
+
* separator that contains a newline, or a single space if none does.
|
|
527
556
|
*/
|
|
528
|
-
function rebuildClassString(split, newClasses) {
|
|
557
|
+
function rebuildClassString(split, newClasses, sourceIndices) {
|
|
529
558
|
const { classes, separators } = split;
|
|
530
|
-
if (newClasses.length === classes.length) {
|
|
559
|
+
if (!sourceIndices && newClasses.length === classes.length) {
|
|
531
560
|
let result = separators[0];
|
|
532
561
|
for (let i = 0; i < newClasses.length; i++) result += newClasses[i] + separators[i + 1];
|
|
533
562
|
return result;
|
|
534
563
|
}
|
|
564
|
+
if (sourceIndices && sourceIndices.length === newClasses.length && newClasses.length > 0) {
|
|
565
|
+
let result = separators[0] + newClasses[0];
|
|
566
|
+
for (let i = 1; i < newClasses.length; i++) result += pickSeparator(separators, sourceIndices[i - 1], sourceIndices[i]) + newClasses[i];
|
|
567
|
+
return result + separators[separators.length - 1];
|
|
568
|
+
}
|
|
535
569
|
const join = separators.slice(1, -1).find((s) => s.includes("\n")) ?? " ";
|
|
536
570
|
return separators[0] + newClasses.join(join) + separators[separators.length - 1];
|
|
537
571
|
}
|
|
@@ -555,7 +589,12 @@ const noDuplicateClasses = defineRule({
|
|
|
555
589
|
for (const cls of classes) if (seen.has(cls)) duplicates.push(cls);
|
|
556
590
|
else seen.add(cls);
|
|
557
591
|
if (duplicates.length > 0) {
|
|
558
|
-
const
|
|
592
|
+
const firstIdx = /* @__PURE__ */ new Map();
|
|
593
|
+
classes.forEach((c, i) => {
|
|
594
|
+
if (!firstIdx.has(c)) firstIdx.set(c, i);
|
|
595
|
+
});
|
|
596
|
+
const unique = [...firstIdx.keys()];
|
|
597
|
+
const fixed = rebuildClassString(split, unique, unique.map((c) => firstIdx.get(c)));
|
|
559
598
|
for (const dup of duplicates) context.report({
|
|
560
599
|
node: loc.node,
|
|
561
600
|
messageId: "duplicate",
|
|
@@ -590,7 +629,9 @@ const noUnnecessaryWhitespace = defineRule({
|
|
|
590
629
|
return m[1] + m[2].replace(/[ \t]+/g, " ");
|
|
591
630
|
}).join("\n");
|
|
592
631
|
if (normalized.startsWith(" ") && !loc.preserveLeadingSpace) normalized = normalized.slice(1);
|
|
593
|
-
|
|
632
|
+
const lastNl = normalized.lastIndexOf("\n");
|
|
633
|
+
const trailingIsClosingIndent = lastNl !== -1 && /^[ \t]*$/.test(normalized.slice(lastNl + 1));
|
|
634
|
+
if (normalized.endsWith(" ") && !loc.preserveTrailingSpace && !trailingIsClosingIndent) normalized = normalized.slice(0, -1);
|
|
594
635
|
if (normalized !== loc.value) context.report({
|
|
595
636
|
node: loc.node,
|
|
596
637
|
messageId: "unnecessaryWhitespace",
|
|
@@ -960,6 +1001,14 @@ function roundRemValue(className) {
|
|
|
960
1001
|
//#region src/design-system/cache.ts
|
|
961
1002
|
const EMPTY_DECLARATIONS = [];
|
|
962
1003
|
const EMPTY_TOKEN_VALUES = [];
|
|
1004
|
+
/** Off-scale numeric value: `w-45`, `min-h-17.5`, `gap-13`. */
|
|
1005
|
+
const DYNAMIC_NUMERIC_RE = /^(.+)-\d+\.?\d*$/;
|
|
1006
|
+
/**
|
|
1007
|
+
* Off-scale percentage: `from-33%`, `via-51%`, `mask-b-from-70%`. The integer is
|
|
1008
|
+
* not an accident — Tailwind compiles `from-33%` and does NOT compile
|
|
1009
|
+
* `from-33.5%`, so a decimal here would be tolerance with nothing behind it.
|
|
1010
|
+
*/
|
|
1011
|
+
const DYNAMIC_PERCENT_RE = /^(.+)-\d+%$/;
|
|
963
1012
|
var DesignSystemCache = class DesignSystemCache {
|
|
964
1013
|
canonicalMap = /* @__PURE__ */ new Map();
|
|
965
1014
|
deprecatedMap = /* @__PURE__ */ new Map();
|
|
@@ -976,7 +1025,7 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
976
1025
|
variantFactsMap = /* @__PURE__ */ new Map();
|
|
977
1026
|
arbitraryEquivMap = /* @__PURE__ */ new Map();
|
|
978
1027
|
_validClasses = [];
|
|
979
|
-
|
|
1028
|
+
_prefixSets = null;
|
|
980
1029
|
_maxOrder = 0n;
|
|
981
1030
|
_prefix = "";
|
|
982
1031
|
componentSet = /* @__PURE__ */ new Set();
|
|
@@ -1116,15 +1165,56 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
1116
1165
|
if (!this._prefixOrderMap) this._prefixOrderMap = this.buildPrefixOrderMap();
|
|
1117
1166
|
return this._prefixOrderMap.get(prefix);
|
|
1118
1167
|
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1168
|
+
/**
|
|
1169
|
+
* The two prefix sets the off-scale heuristics need, derived in ONE pass over
|
|
1170
|
+
* the ~23 600 valid class names.
|
|
1171
|
+
*
|
|
1172
|
+
* `known` is every dash-bounded prefix. `percent` is the subset that has at
|
|
1173
|
+
* least one enumerated class ending in `%`, and it exists because Tailwind
|
|
1174
|
+
* enumerates only 21 of the 101 percentages it compiles (0, 5, …, 100): a
|
|
1175
|
+
* `from-33%` is as real as a `w-45`, and was reported as a typo of `from-35%`
|
|
1176
|
+
* — a quick-fix that silently moves the gradient stop.
|
|
1177
|
+
*
|
|
1178
|
+
* The narrower set is the point. Accepting `<any known prefix>-N%` would reach
|
|
1179
|
+
* the ~1 780 prefixes Tailwind has, when only 22 take a percentage, and the
|
|
1180
|
+
* directional rules guard their replacements with `isValid` alone (no design
|
|
1181
|
+
* system to refute them), so `ml-33%` → `ms-33%` would start being reported and
|
|
1182
|
+
* autofixed from one dead class to another. Derived rather than listed: it
|
|
1183
|
+
* self-extends when a plugin enumerates percentage classes and self-prunes when
|
|
1184
|
+
* Tailwind stops emitting them.
|
|
1185
|
+
*/
|
|
1186
|
+
prefixSets() {
|
|
1187
|
+
if (!this._prefixSets) {
|
|
1188
|
+
const known = /* @__PURE__ */ new Set();
|
|
1189
|
+
const percent = /* @__PURE__ */ new Set();
|
|
1122
1190
|
for (const cls of this._validClasses) {
|
|
1123
1191
|
const dash = cls.lastIndexOf("-");
|
|
1124
|
-
if (dash
|
|
1192
|
+
if (dash <= 0) continue;
|
|
1193
|
+
const prefix = cls.slice(0, dash);
|
|
1194
|
+
known.add(prefix);
|
|
1195
|
+
if (cls.endsWith("%")) percent.add(prefix);
|
|
1125
1196
|
}
|
|
1197
|
+
this._prefixSets = {
|
|
1198
|
+
known,
|
|
1199
|
+
percent
|
|
1200
|
+
};
|
|
1126
1201
|
}
|
|
1127
|
-
return this.
|
|
1202
|
+
return this._prefixSets;
|
|
1203
|
+
}
|
|
1204
|
+
getKnownPrefixes() {
|
|
1205
|
+
return this.prefixSets().known;
|
|
1206
|
+
}
|
|
1207
|
+
/**
|
|
1208
|
+
* The utility prefix of an off-scale dynamic value, or null when the shape
|
|
1209
|
+
* doesn't match or the prefix doesn't take that kind of value. Shared by
|
|
1210
|
+
* `isValid` and `getOrder` so the two can't drift on what "dynamic" means.
|
|
1211
|
+
*/
|
|
1212
|
+
dynamicValuePrefix(bare) {
|
|
1213
|
+
const numeric = DYNAMIC_NUMERIC_RE.exec(bare);
|
|
1214
|
+
if (numeric) return this.getKnownPrefixes().has(numeric[1]) ? numeric[1] : null;
|
|
1215
|
+
const percent = DYNAMIC_PERCENT_RE.exec(bare);
|
|
1216
|
+
if (percent) return this.prefixSets().percent.has(percent[1]) ? percent[1] : null;
|
|
1217
|
+
return null;
|
|
1128
1218
|
}
|
|
1129
1219
|
/**
|
|
1130
1220
|
* Is this class name in the precomputed set VERBATIM?
|
|
@@ -1206,13 +1296,10 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
1206
1296
|
if (slashIdx > 0) {
|
|
1207
1297
|
const base = bare.slice(0, slashIdx);
|
|
1208
1298
|
if (this.validitySet.has(base)) return true;
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
if (dashIdx > 0 && this.getKnownPrefixes().has(base.slice(0, dashIdx))) return true;
|
|
1212
|
-
}
|
|
1299
|
+
const numericBase = DYNAMIC_NUMERIC_RE.exec(base);
|
|
1300
|
+
if (numericBase && this.getKnownPrefixes().has(numericBase[1])) return true;
|
|
1213
1301
|
}
|
|
1214
|
-
|
|
1215
|
-
if (numericMatch && this.getKnownPrefixes().has(numericMatch[1])) return true;
|
|
1302
|
+
if (this.dynamicValuePrefix(bare) !== null) return true;
|
|
1216
1303
|
if (hasArbitraryValue(className)) return true;
|
|
1217
1304
|
if (bare.includes("(") && bare.includes(")")) return true;
|
|
1218
1305
|
return false;
|
|
@@ -1280,9 +1367,8 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
1280
1367
|
}
|
|
1281
1368
|
}
|
|
1282
1369
|
if (baseOrder === void 0) {
|
|
1283
|
-
const
|
|
1284
|
-
|
|
1285
|
-
if (numericMatch && this.getKnownPrefixes().has(numericMatch[1])) baseOrder = this.findOrderByPrefix(numericMatch[1] + "-");
|
|
1370
|
+
const prefix = this.dynamicValuePrefix(splitImportant(utility).bare);
|
|
1371
|
+
if (prefix) baseOrder = this.findOrderByPrefix(prefix + "-");
|
|
1286
1372
|
}
|
|
1287
1373
|
if (baseOrder === void 0) return null;
|
|
1288
1374
|
if (!hasVariant) return baseOrder;
|
|
@@ -2881,6 +2967,22 @@ function safeFilename(context) {
|
|
|
2881
2967
|
}
|
|
2882
2968
|
}
|
|
2883
2969
|
/**
|
|
2970
|
+
* Safely read `context.sourceCode`. Same try/catch pattern as the other
|
|
2971
|
+
* accessors (the getter may throw inside `createOnce`). Used by
|
|
2972
|
+
* `enforce-consistent-line-wrapping` to derive a statement's real base
|
|
2973
|
+
* indentation (the line's leading whitespace) when wrapping a single-line
|
|
2974
|
+
* template into the block convention — the backtick column
|
|
2975
|
+
* (`node.loc.start.column`) is NOT the base indent. Returns `undefined` if
|
|
2976
|
+
* unavailable; callers fall back to a zero base indent.
|
|
2977
|
+
*/
|
|
2978
|
+
function safeSourceCode(context) {
|
|
2979
|
+
try {
|
|
2980
|
+
return context.sourceCode ?? void 0;
|
|
2981
|
+
} catch {
|
|
2982
|
+
return;
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
/**
|
|
2884
2986
|
* Safely read `context.cwd`, falling back to `process.cwd()`. Same try/catch
|
|
2885
2987
|
* pattern as the other accessors (the getter throws in `createOnce` on older
|
|
2886
2988
|
* oxlint). The fallback keeps relative-path resolution working even when the
|
|
@@ -3692,7 +3794,12 @@ const noUnknownClasses = defineRule({
|
|
|
3692
3794
|
const { variant, bare, position } = strippedUtility(cls);
|
|
3693
3795
|
if (validity === "valid" && !variant && cache.isKnownClass(bare)) continue;
|
|
3694
3796
|
if (cache.deprecatedReplacement(bare)) continue;
|
|
3695
|
-
|
|
3797
|
+
const compiles = cache.isKnownClass(bare) ? true : verified?.get(bare);
|
|
3798
|
+
const prefixWritten = !cache.prefix || variant.startsWith(`${cache.prefix}:`);
|
|
3799
|
+
let effectiveValidity = validity;
|
|
3800
|
+
if (validity === "unknown" && compiles === true) effectiveValidity = prefixWritten ? "valid" : "missing-prefix";
|
|
3801
|
+
else if (validity === "missing-prefix" && compiles === false) effectiveValidity = "unknown";
|
|
3802
|
+
if (effectiveValidity === "missing-prefix") {
|
|
3696
3803
|
const fixed = `${cache.prefix}:${cls}`;
|
|
3697
3804
|
reportWithSuggestion(loc, classes, cls, fixed, "missingPrefix", {
|
|
3698
3805
|
className: cls,
|
|
@@ -3701,9 +3808,17 @@ const noUnknownClasses = defineRule({
|
|
|
3701
3808
|
}, split);
|
|
3702
3809
|
continue;
|
|
3703
3810
|
}
|
|
3704
|
-
if (cache.isMarkerClass(bare)
|
|
3705
|
-
|
|
3706
|
-
|
|
3811
|
+
if (cache.isMarkerClass(bare)) {
|
|
3812
|
+
if (prefixWritten) continue;
|
|
3813
|
+
const fixed = `${cache.prefix}:${cls}`;
|
|
3814
|
+
reportWithSuggestion(loc, classes, cls, fixed, "missingPrefix", {
|
|
3815
|
+
className: cls,
|
|
3816
|
+
prefix: cache.prefix,
|
|
3817
|
+
suggestion: fixed
|
|
3818
|
+
}, split);
|
|
3819
|
+
continue;
|
|
3820
|
+
}
|
|
3821
|
+
if (effectiveValidity === "unknown" || compiles === false) {
|
|
3707
3822
|
const suggestionBare = findBestSuggestion(bare, cache.validClasses);
|
|
3708
3823
|
const suggestion = suggestionBare ? variant + reattachImportant(suggestionBare, position) : null;
|
|
3709
3824
|
if (suggestion) reportWithSuggestion(loc, classes, cls, suggestion, "unknownWithSuggestion", {
|
|
@@ -5150,8 +5265,22 @@ const enforceShorthand = defineRule({
|
|
|
5150
5265
|
if (!mergeIsSafe(family, group.value, cache)) continue;
|
|
5151
5266
|
const matched = family.parts.map((part) => group.byPart.get(part));
|
|
5152
5267
|
const replacement = group.variant + reattachImportant(`${family.to}-${group.value}`, group.position);
|
|
5153
|
-
const
|
|
5154
|
-
|
|
5268
|
+
const matchedSet = new Set(matched);
|
|
5269
|
+
const remaining = [];
|
|
5270
|
+
const sourceIndices = [];
|
|
5271
|
+
let firstMatchedIdx = -1;
|
|
5272
|
+
classes.forEach((cls, i) => {
|
|
5273
|
+
if (matchedSet.has(cls)) {
|
|
5274
|
+
if (firstMatchedIdx === -1) firstMatchedIdx = i;
|
|
5275
|
+
return;
|
|
5276
|
+
}
|
|
5277
|
+
remaining.push(cls);
|
|
5278
|
+
sourceIndices.push(i);
|
|
5279
|
+
});
|
|
5280
|
+
if (!remaining.includes(replacement)) {
|
|
5281
|
+
remaining.push(replacement);
|
|
5282
|
+
sourceIndices.push(firstMatchedIdx);
|
|
5283
|
+
}
|
|
5155
5284
|
for (const part of family.parts) consumed.add(part);
|
|
5156
5285
|
context.report({
|
|
5157
5286
|
node: loc.node,
|
|
@@ -5161,7 +5290,7 @@ const enforceShorthand = defineRule({
|
|
|
5161
5290
|
replacement
|
|
5162
5291
|
},
|
|
5163
5292
|
fix(fixer) {
|
|
5164
|
-
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, rebuildClassString(split, remaining)));
|
|
5293
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, rebuildClassString(split, remaining, sourceIndices)));
|
|
5165
5294
|
}
|
|
5166
5295
|
});
|
|
5167
5296
|
}
|
|
@@ -6390,6 +6519,14 @@ const consistentVariantOrder = defineRule({
|
|
|
6390
6519
|
//#endregion
|
|
6391
6520
|
//#region src/rules/enforce-consistent-line-wrapping.ts
|
|
6392
6521
|
const DEFAULT_PRINT_WIDTH = 80;
|
|
6522
|
+
/** One indentation level added below the statement's base indent for wrapped lines. */
|
|
6523
|
+
const INDENT_UNIT = " ";
|
|
6524
|
+
/** Group `classes` into chunks of at most `n`, each chunk space-joined. */
|
|
6525
|
+
function chunkList(classes, n) {
|
|
6526
|
+
const chunks = [];
|
|
6527
|
+
for (let i = 0; i < classes.length; i += n) chunks.push(classes.slice(i, i + n).join(" "));
|
|
6528
|
+
return chunks;
|
|
6529
|
+
}
|
|
6393
6530
|
const enforceConsistentLineWrapping = defineRule({
|
|
6394
6531
|
meta: {
|
|
6395
6532
|
type: "suggestion",
|
|
@@ -6405,52 +6542,97 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
6405
6542
|
}],
|
|
6406
6543
|
defaultOptions: [{ printWidth: DEFAULT_PRINT_WIDTH }],
|
|
6407
6544
|
messages: {
|
|
6408
|
-
tooLong: "Class string
|
|
6545
|
+
tooLong: "Class string exceeds the print width of {{printWidth}} (longest line is {{length}} characters). Consider splitting into multiple lines or extracting into a component.",
|
|
6409
6546
|
tooManyPerLine: "Too many classes on a single line ({{count}}). Maximum allowed per line is {{max}}."
|
|
6410
6547
|
}
|
|
6411
6548
|
},
|
|
6412
6549
|
createOnce(context) {
|
|
6413
6550
|
const getPrintWidth = createLazyOptions(context, (o) => o?.printWidth ?? DEFAULT_PRINT_WIDTH);
|
|
6414
6551
|
const getClassesPerLine = createLazyOptions(context, (o) => o?.classesPerLine);
|
|
6552
|
+
/**
|
|
6553
|
+
* The statement's real base indentation — the leading whitespace of the
|
|
6554
|
+
* source line the opening backtick sits on. NOT `node.loc.start.column`,
|
|
6555
|
+
* which is the backtick's column (e.g. 18 for `const className = ` and
|
|
6556
|
+
* deeper still inside nested JSX). Falls back to `''` when `sourceCode`
|
|
6557
|
+
* is unavailable (block still lands correctly for top-level statements).
|
|
6558
|
+
*/
|
|
6559
|
+
function deriveBaseIndent(loc) {
|
|
6560
|
+
const sc = safeSourceCode(context);
|
|
6561
|
+
const line = loc.node.loc?.start.line;
|
|
6562
|
+
if (sc?.lines && typeof line === "number" && line >= 1 && line <= sc.lines.length) {
|
|
6563
|
+
const src = sc.lines[line - 1] ?? "";
|
|
6564
|
+
const m = /^[ \t]*/.exec(src);
|
|
6565
|
+
return m ? m[0] : "";
|
|
6566
|
+
}
|
|
6567
|
+
return "";
|
|
6568
|
+
}
|
|
6569
|
+
/**
|
|
6570
|
+
* Re-wrap a template literal's classes into the block convention,
|
|
6571
|
+
* non-destructively:
|
|
6572
|
+
* - single-line → convert to a `\n` + indent block (unless the quasi is
|
|
6573
|
+
* glued to a `${}`, in which case keep it inline/hanging so adjacency
|
|
6574
|
+
* survives);
|
|
6575
|
+
* - already multiline → re-wrap ONLY the lines that exceed the budget,
|
|
6576
|
+
* reusing each line's own indent; conforming lines are left verbatim.
|
|
6577
|
+
*/
|
|
6578
|
+
function rewrapTemplate(loc, lines, classesPerLine) {
|
|
6579
|
+
const baseIndent = deriveBaseIndent(loc);
|
|
6580
|
+
const interiorIndent = baseIndent + INDENT_UNIT;
|
|
6581
|
+
if (lines.length === 1) {
|
|
6582
|
+
const chunks = chunkList(splitClasses(loc.value), classesPerLine);
|
|
6583
|
+
if (!loc.preserveLeadingSpace && !loc.preserveTrailingSpace) return "\n" + chunks.map((c) => interiorIndent + c).join("\n") + "\n" + baseIndent;
|
|
6584
|
+
return chunks.join("\n" + interiorIndent);
|
|
6585
|
+
}
|
|
6586
|
+
return lines.map((line) => {
|
|
6587
|
+
const classes = splitClasses(line);
|
|
6588
|
+
if (classes.length <= classesPerLine) return line;
|
|
6589
|
+
const m = /^[ \t]*/.exec(line);
|
|
6590
|
+
const lineIndent = m && m[0].length > 0 ? m[0] : interiorIndent;
|
|
6591
|
+
return chunkList(classes, classesPerLine).map((c) => lineIndent + c).join("\n");
|
|
6592
|
+
}).join("\n");
|
|
6593
|
+
}
|
|
6415
6594
|
function check(locations) {
|
|
6416
6595
|
const printWidth = getPrintWidth();
|
|
6417
6596
|
const classesPerLine = getClassesPerLine();
|
|
6418
6597
|
for (const loc of locations) {
|
|
6419
|
-
|
|
6598
|
+
let maxLine = 0;
|
|
6599
|
+
for (const line of loc.value.split("\n")) if (line.length > maxLine) maxLine = line.length;
|
|
6600
|
+
if (maxLine > printWidth) context.report({
|
|
6420
6601
|
node: loc.node,
|
|
6421
6602
|
messageId: "tooLong",
|
|
6422
6603
|
data: {
|
|
6423
|
-
length: String(
|
|
6604
|
+
length: String(maxLine),
|
|
6424
6605
|
printWidth: String(printWidth)
|
|
6425
6606
|
}
|
|
6426
6607
|
});
|
|
6427
6608
|
if (classesPerLine !== void 0) {
|
|
6428
|
-
const
|
|
6429
|
-
|
|
6430
|
-
|
|
6431
|
-
|
|
6432
|
-
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
|
|
6609
|
+
const lines = loc.value.split("\n");
|
|
6610
|
+
let maxPerLine = 0;
|
|
6611
|
+
for (const line of lines) {
|
|
6612
|
+
const n = splitClasses(line).length;
|
|
6613
|
+
if (n > maxPerLine) maxPerLine = n;
|
|
6614
|
+
}
|
|
6615
|
+
if (maxPerLine > classesPerLine) {
|
|
6616
|
+
const data = {
|
|
6617
|
+
count: String(maxPerLine),
|
|
6618
|
+
max: String(classesPerLine)
|
|
6619
|
+
};
|
|
6620
|
+
if (loc.node.type === "TemplateElement") {
|
|
6621
|
+
const fixedValue = rewrapTemplate(loc, lines, classesPerLine);
|
|
6622
|
+
context.report({
|
|
6623
|
+
node: loc.node,
|
|
6624
|
+
messageId: "tooManyPerLine",
|
|
6625
|
+
data,
|
|
6626
|
+
fix(fixer) {
|
|
6627
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
6628
|
+
}
|
|
6629
|
+
});
|
|
6630
|
+
} else context.report({
|
|
6436
6631
|
node: loc.node,
|
|
6437
6632
|
messageId: "tooManyPerLine",
|
|
6438
|
-
data
|
|
6439
|
-
count: String(classes.length),
|
|
6440
|
-
max: String(classesPerLine)
|
|
6441
|
-
},
|
|
6442
|
-
fix(fixer) {
|
|
6443
|
-
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
6444
|
-
}
|
|
6633
|
+
data
|
|
6445
6634
|
});
|
|
6446
|
-
}
|
|
6447
|
-
node: loc.node,
|
|
6448
|
-
messageId: "tooManyPerLine",
|
|
6449
|
-
data: {
|
|
6450
|
-
count: String(classes.length),
|
|
6451
|
-
max: String(classesPerLine)
|
|
6452
|
-
}
|
|
6453
|
-
});
|
|
6635
|
+
}
|
|
6454
6636
|
}
|
|
6455
6637
|
}
|
|
6456
6638
|
}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { tmpdir, userInfo } from "node:os";
|
|
|
7
7
|
//#region \0rolldown/runtime.js
|
|
8
8
|
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
9
9
|
//#endregion
|
|
10
|
-
//#region ../../node_modules/.pnpm/@oxlint+plugins@1.
|
|
10
|
+
//#region ../../node_modules/.pnpm/@oxlint+plugins@1.77.0/node_modules/@oxlint/plugins/index.js
|
|
11
11
|
/**
|
|
12
12
|
* Define a plugin.
|
|
13
13
|
*
|
|
@@ -518,24 +518,58 @@ function splitClassesWithSeparators(classString) {
|
|
|
518
518
|
};
|
|
519
519
|
}
|
|
520
520
|
/**
|
|
521
|
+
* The separator to place before an output class whose source class sits at
|
|
522
|
+
* original index `si`, given the previous output class came from `sPrev`.
|
|
523
|
+
*
|
|
524
|
+
* - **forward move** (`si > sPrev`): the classes between them were dropped, so
|
|
525
|
+
* the effective separator is the LAST newline-bearing separator in that gap
|
|
526
|
+
* (it carries the correct indent), else the separator immediately preceding
|
|
527
|
+
* `si`. This transfers a line break forward when the class that opened a line
|
|
528
|
+
* is removed, so the next survivor keeps its own line.
|
|
529
|
+
* - **non-forward move** (append / reorder — e.g. `enforce-shorthand` pushes the
|
|
530
|
+
* merged replacement to the end): reuse `si`'s own preceding separator if it
|
|
531
|
+
* carries a newline, else a single space — never the (possibly empty) leader,
|
|
532
|
+
* so output classes never glue together.
|
|
533
|
+
*/
|
|
534
|
+
function pickSeparator(separators, sPrev, si) {
|
|
535
|
+
if (si > sPrev) {
|
|
536
|
+
let chosen = separators[si] ?? " ";
|
|
537
|
+
for (let k = sPrev + 1; k <= si; k++) if (separators[k]?.includes("\n")) chosen = separators[k];
|
|
538
|
+
return chosen;
|
|
539
|
+
}
|
|
540
|
+
const own = separators[si];
|
|
541
|
+
return own && own.includes("\n") ? own : " ";
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
521
544
|
* Reconstruct a class string from a `ClassSplit` and a (possibly transformed)
|
|
522
545
|
* array of classes.
|
|
523
546
|
*
|
|
524
|
-
* - If `newClasses.length === split.classes.length`
|
|
525
|
-
* canonicalize, sort, variant-order, etc.)
|
|
526
|
-
* verbatim. This keeps multiline indentation
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
*
|
|
530
|
-
*
|
|
547
|
+
* - If `newClasses.length === split.classes.length` and no `sourceIndices` are
|
|
548
|
+
* given (1-to-1 transformation: canonicalize, sort, variant-order, etc.)
|
|
549
|
+
* every separator is preserved verbatim. This keeps multiline indentation
|
|
550
|
+
* intact.
|
|
551
|
+
* - If `sourceIndices` is given (count-changing transforms that know where each
|
|
552
|
+
* output class came from: no-duplicate removes dupes, shorthand collapses
|
|
553
|
+
* pairs) the layout is preserved structurally — leader and trailing stay
|
|
554
|
+
* verbatim (edge-safe) and each interior separator is recovered from the
|
|
555
|
+
* source via `pickSeparator`, so a multiline block keeps its per-line grouping
|
|
556
|
+
* instead of reflowing to one class per line.
|
|
557
|
+
* - Otherwise (count differs, no mapping) it degrades gracefully: leading and
|
|
558
|
+
* trailing whitespace are preserved; classes are joined by the first internal
|
|
559
|
+
* separator that contains a newline, or a single space if none does.
|
|
531
560
|
*/
|
|
532
|
-
function rebuildClassString(split, newClasses) {
|
|
561
|
+
function rebuildClassString(split, newClasses, sourceIndices) {
|
|
533
562
|
const { classes, separators } = split;
|
|
534
|
-
if (newClasses.length === classes.length) {
|
|
563
|
+
if (!sourceIndices && newClasses.length === classes.length) {
|
|
535
564
|
let result = separators[0];
|
|
536
565
|
for (let i = 0; i < newClasses.length; i++) result += newClasses[i] + separators[i + 1];
|
|
537
566
|
return result;
|
|
538
567
|
}
|
|
568
|
+
if (sourceIndices && sourceIndices.length === newClasses.length && newClasses.length > 0) {
|
|
569
|
+
let result = separators[0] + newClasses[0];
|
|
570
|
+
for (let i = 1; i < newClasses.length; i++) result += pickSeparator(separators, sourceIndices[i - 1], sourceIndices[i]) + newClasses[i];
|
|
571
|
+
return result + separators[separators.length - 1];
|
|
572
|
+
}
|
|
539
573
|
const join = separators.slice(1, -1).find((s) => s.includes("\n")) ?? " ";
|
|
540
574
|
return separators[0] + newClasses.join(join) + separators[separators.length - 1];
|
|
541
575
|
}
|
|
@@ -559,7 +593,12 @@ const noDuplicateClasses = defineRule({
|
|
|
559
593
|
for (const cls of classes) if (seen.has(cls)) duplicates.push(cls);
|
|
560
594
|
else seen.add(cls);
|
|
561
595
|
if (duplicates.length > 0) {
|
|
562
|
-
const
|
|
596
|
+
const firstIdx = /* @__PURE__ */ new Map();
|
|
597
|
+
classes.forEach((c, i) => {
|
|
598
|
+
if (!firstIdx.has(c)) firstIdx.set(c, i);
|
|
599
|
+
});
|
|
600
|
+
const unique = [...firstIdx.keys()];
|
|
601
|
+
const fixed = rebuildClassString(split, unique, unique.map((c) => firstIdx.get(c)));
|
|
563
602
|
for (const dup of duplicates) context.report({
|
|
564
603
|
node: loc.node,
|
|
565
604
|
messageId: "duplicate",
|
|
@@ -594,7 +633,9 @@ const noUnnecessaryWhitespace = defineRule({
|
|
|
594
633
|
return m[1] + m[2].replace(/[ \t]+/g, " ");
|
|
595
634
|
}).join("\n");
|
|
596
635
|
if (normalized.startsWith(" ") && !loc.preserveLeadingSpace) normalized = normalized.slice(1);
|
|
597
|
-
|
|
636
|
+
const lastNl = normalized.lastIndexOf("\n");
|
|
637
|
+
const trailingIsClosingIndent = lastNl !== -1 && /^[ \t]*$/.test(normalized.slice(lastNl + 1));
|
|
638
|
+
if (normalized.endsWith(" ") && !loc.preserveTrailingSpace && !trailingIsClosingIndent) normalized = normalized.slice(0, -1);
|
|
598
639
|
if (normalized !== loc.value) context.report({
|
|
599
640
|
node: loc.node,
|
|
600
641
|
messageId: "unnecessaryWhitespace",
|
|
@@ -964,6 +1005,14 @@ function roundRemValue(className) {
|
|
|
964
1005
|
//#region src/design-system/cache.ts
|
|
965
1006
|
const EMPTY_DECLARATIONS = [];
|
|
966
1007
|
const EMPTY_TOKEN_VALUES = [];
|
|
1008
|
+
/** Off-scale numeric value: `w-45`, `min-h-17.5`, `gap-13`. */
|
|
1009
|
+
const DYNAMIC_NUMERIC_RE = /^(.+)-\d+\.?\d*$/;
|
|
1010
|
+
/**
|
|
1011
|
+
* Off-scale percentage: `from-33%`, `via-51%`, `mask-b-from-70%`. The integer is
|
|
1012
|
+
* not an accident — Tailwind compiles `from-33%` and does NOT compile
|
|
1013
|
+
* `from-33.5%`, so a decimal here would be tolerance with nothing behind it.
|
|
1014
|
+
*/
|
|
1015
|
+
const DYNAMIC_PERCENT_RE = /^(.+)-\d+%$/;
|
|
967
1016
|
var DesignSystemCache = class DesignSystemCache {
|
|
968
1017
|
canonicalMap = /* @__PURE__ */ new Map();
|
|
969
1018
|
deprecatedMap = /* @__PURE__ */ new Map();
|
|
@@ -980,7 +1029,7 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
980
1029
|
variantFactsMap = /* @__PURE__ */ new Map();
|
|
981
1030
|
arbitraryEquivMap = /* @__PURE__ */ new Map();
|
|
982
1031
|
_validClasses = [];
|
|
983
|
-
|
|
1032
|
+
_prefixSets = null;
|
|
984
1033
|
_maxOrder = 0n;
|
|
985
1034
|
_prefix = "";
|
|
986
1035
|
componentSet = /* @__PURE__ */ new Set();
|
|
@@ -1120,15 +1169,56 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
1120
1169
|
if (!this._prefixOrderMap) this._prefixOrderMap = this.buildPrefixOrderMap();
|
|
1121
1170
|
return this._prefixOrderMap.get(prefix);
|
|
1122
1171
|
}
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1172
|
+
/**
|
|
1173
|
+
* The two prefix sets the off-scale heuristics need, derived in ONE pass over
|
|
1174
|
+
* the ~23 600 valid class names.
|
|
1175
|
+
*
|
|
1176
|
+
* `known` is every dash-bounded prefix. `percent` is the subset that has at
|
|
1177
|
+
* least one enumerated class ending in `%`, and it exists because Tailwind
|
|
1178
|
+
* enumerates only 21 of the 101 percentages it compiles (0, 5, …, 100): a
|
|
1179
|
+
* `from-33%` is as real as a `w-45`, and was reported as a typo of `from-35%`
|
|
1180
|
+
* — a quick-fix that silently moves the gradient stop.
|
|
1181
|
+
*
|
|
1182
|
+
* The narrower set is the point. Accepting `<any known prefix>-N%` would reach
|
|
1183
|
+
* the ~1 780 prefixes Tailwind has, when only 22 take a percentage, and the
|
|
1184
|
+
* directional rules guard their replacements with `isValid` alone (no design
|
|
1185
|
+
* system to refute them), so `ml-33%` → `ms-33%` would start being reported and
|
|
1186
|
+
* autofixed from one dead class to another. Derived rather than listed: it
|
|
1187
|
+
* self-extends when a plugin enumerates percentage classes and self-prunes when
|
|
1188
|
+
* Tailwind stops emitting them.
|
|
1189
|
+
*/
|
|
1190
|
+
prefixSets() {
|
|
1191
|
+
if (!this._prefixSets) {
|
|
1192
|
+
const known = /* @__PURE__ */ new Set();
|
|
1193
|
+
const percent = /* @__PURE__ */ new Set();
|
|
1126
1194
|
for (const cls of this._validClasses) {
|
|
1127
1195
|
const dash = cls.lastIndexOf("-");
|
|
1128
|
-
if (dash
|
|
1196
|
+
if (dash <= 0) continue;
|
|
1197
|
+
const prefix = cls.slice(0, dash);
|
|
1198
|
+
known.add(prefix);
|
|
1199
|
+
if (cls.endsWith("%")) percent.add(prefix);
|
|
1129
1200
|
}
|
|
1201
|
+
this._prefixSets = {
|
|
1202
|
+
known,
|
|
1203
|
+
percent
|
|
1204
|
+
};
|
|
1130
1205
|
}
|
|
1131
|
-
return this.
|
|
1206
|
+
return this._prefixSets;
|
|
1207
|
+
}
|
|
1208
|
+
getKnownPrefixes() {
|
|
1209
|
+
return this.prefixSets().known;
|
|
1210
|
+
}
|
|
1211
|
+
/**
|
|
1212
|
+
* The utility prefix of an off-scale dynamic value, or null when the shape
|
|
1213
|
+
* doesn't match or the prefix doesn't take that kind of value. Shared by
|
|
1214
|
+
* `isValid` and `getOrder` so the two can't drift on what "dynamic" means.
|
|
1215
|
+
*/
|
|
1216
|
+
dynamicValuePrefix(bare) {
|
|
1217
|
+
const numeric = DYNAMIC_NUMERIC_RE.exec(bare);
|
|
1218
|
+
if (numeric) return this.getKnownPrefixes().has(numeric[1]) ? numeric[1] : null;
|
|
1219
|
+
const percent = DYNAMIC_PERCENT_RE.exec(bare);
|
|
1220
|
+
if (percent) return this.prefixSets().percent.has(percent[1]) ? percent[1] : null;
|
|
1221
|
+
return null;
|
|
1132
1222
|
}
|
|
1133
1223
|
/**
|
|
1134
1224
|
* Is this class name in the precomputed set VERBATIM?
|
|
@@ -1210,13 +1300,10 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
1210
1300
|
if (slashIdx > 0) {
|
|
1211
1301
|
const base = bare.slice(0, slashIdx);
|
|
1212
1302
|
if (this.validitySet.has(base)) return true;
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
if (dashIdx > 0 && this.getKnownPrefixes().has(base.slice(0, dashIdx))) return true;
|
|
1216
|
-
}
|
|
1303
|
+
const numericBase = DYNAMIC_NUMERIC_RE.exec(base);
|
|
1304
|
+
if (numericBase && this.getKnownPrefixes().has(numericBase[1])) return true;
|
|
1217
1305
|
}
|
|
1218
|
-
|
|
1219
|
-
if (numericMatch && this.getKnownPrefixes().has(numericMatch[1])) return true;
|
|
1306
|
+
if (this.dynamicValuePrefix(bare) !== null) return true;
|
|
1220
1307
|
if (hasArbitraryValue(className)) return true;
|
|
1221
1308
|
if (bare.includes("(") && bare.includes(")")) return true;
|
|
1222
1309
|
return false;
|
|
@@ -1284,9 +1371,8 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
1284
1371
|
}
|
|
1285
1372
|
}
|
|
1286
1373
|
if (baseOrder === void 0) {
|
|
1287
|
-
const
|
|
1288
|
-
|
|
1289
|
-
if (numericMatch && this.getKnownPrefixes().has(numericMatch[1])) baseOrder = this.findOrderByPrefix(numericMatch[1] + "-");
|
|
1374
|
+
const prefix = this.dynamicValuePrefix(splitImportant(utility).bare);
|
|
1375
|
+
if (prefix) baseOrder = this.findOrderByPrefix(prefix + "-");
|
|
1290
1376
|
}
|
|
1291
1377
|
if (baseOrder === void 0) return null;
|
|
1292
1378
|
if (!hasVariant) return baseOrder;
|
|
@@ -2885,6 +2971,22 @@ function safeFilename(context) {
|
|
|
2885
2971
|
}
|
|
2886
2972
|
}
|
|
2887
2973
|
/**
|
|
2974
|
+
* Safely read `context.sourceCode`. Same try/catch pattern as the other
|
|
2975
|
+
* accessors (the getter may throw inside `createOnce`). Used by
|
|
2976
|
+
* `enforce-consistent-line-wrapping` to derive a statement's real base
|
|
2977
|
+
* indentation (the line's leading whitespace) when wrapping a single-line
|
|
2978
|
+
* template into the block convention — the backtick column
|
|
2979
|
+
* (`node.loc.start.column`) is NOT the base indent. Returns `undefined` if
|
|
2980
|
+
* unavailable; callers fall back to a zero base indent.
|
|
2981
|
+
*/
|
|
2982
|
+
function safeSourceCode(context) {
|
|
2983
|
+
try {
|
|
2984
|
+
return context.sourceCode ?? void 0;
|
|
2985
|
+
} catch {
|
|
2986
|
+
return;
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2989
|
+
/**
|
|
2888
2990
|
* Safely read `context.cwd`, falling back to `process.cwd()`. Same try/catch
|
|
2889
2991
|
* pattern as the other accessors (the getter throws in `createOnce` on older
|
|
2890
2992
|
* oxlint). The fallback keeps relative-path resolution working even when the
|
|
@@ -3696,7 +3798,12 @@ const noUnknownClasses = defineRule({
|
|
|
3696
3798
|
const { variant, bare, position } = strippedUtility(cls);
|
|
3697
3799
|
if (validity === "valid" && !variant && cache.isKnownClass(bare)) continue;
|
|
3698
3800
|
if (cache.deprecatedReplacement(bare)) continue;
|
|
3699
|
-
|
|
3801
|
+
const compiles = cache.isKnownClass(bare) ? true : verified?.get(bare);
|
|
3802
|
+
const prefixWritten = !cache.prefix || variant.startsWith(`${cache.prefix}:`);
|
|
3803
|
+
let effectiveValidity = validity;
|
|
3804
|
+
if (validity === "unknown" && compiles === true) effectiveValidity = prefixWritten ? "valid" : "missing-prefix";
|
|
3805
|
+
else if (validity === "missing-prefix" && compiles === false) effectiveValidity = "unknown";
|
|
3806
|
+
if (effectiveValidity === "missing-prefix") {
|
|
3700
3807
|
const fixed = `${cache.prefix}:${cls}`;
|
|
3701
3808
|
reportWithSuggestion(loc, classes, cls, fixed, "missingPrefix", {
|
|
3702
3809
|
className: cls,
|
|
@@ -3705,9 +3812,17 @@ const noUnknownClasses = defineRule({
|
|
|
3705
3812
|
}, split);
|
|
3706
3813
|
continue;
|
|
3707
3814
|
}
|
|
3708
|
-
if (cache.isMarkerClass(bare)
|
|
3709
|
-
|
|
3710
|
-
|
|
3815
|
+
if (cache.isMarkerClass(bare)) {
|
|
3816
|
+
if (prefixWritten) continue;
|
|
3817
|
+
const fixed = `${cache.prefix}:${cls}`;
|
|
3818
|
+
reportWithSuggestion(loc, classes, cls, fixed, "missingPrefix", {
|
|
3819
|
+
className: cls,
|
|
3820
|
+
prefix: cache.prefix,
|
|
3821
|
+
suggestion: fixed
|
|
3822
|
+
}, split);
|
|
3823
|
+
continue;
|
|
3824
|
+
}
|
|
3825
|
+
if (effectiveValidity === "unknown" || compiles === false) {
|
|
3711
3826
|
const suggestionBare = findBestSuggestion(bare, cache.validClasses);
|
|
3712
3827
|
const suggestion = suggestionBare ? variant + reattachImportant(suggestionBare, position) : null;
|
|
3713
3828
|
if (suggestion) reportWithSuggestion(loc, classes, cls, suggestion, "unknownWithSuggestion", {
|
|
@@ -5154,8 +5269,22 @@ const enforceShorthand = defineRule({
|
|
|
5154
5269
|
if (!mergeIsSafe(family, group.value, cache)) continue;
|
|
5155
5270
|
const matched = family.parts.map((part) => group.byPart.get(part));
|
|
5156
5271
|
const replacement = group.variant + reattachImportant(`${family.to}-${group.value}`, group.position);
|
|
5157
|
-
const
|
|
5158
|
-
|
|
5272
|
+
const matchedSet = new Set(matched);
|
|
5273
|
+
const remaining = [];
|
|
5274
|
+
const sourceIndices = [];
|
|
5275
|
+
let firstMatchedIdx = -1;
|
|
5276
|
+
classes.forEach((cls, i) => {
|
|
5277
|
+
if (matchedSet.has(cls)) {
|
|
5278
|
+
if (firstMatchedIdx === -1) firstMatchedIdx = i;
|
|
5279
|
+
return;
|
|
5280
|
+
}
|
|
5281
|
+
remaining.push(cls);
|
|
5282
|
+
sourceIndices.push(i);
|
|
5283
|
+
});
|
|
5284
|
+
if (!remaining.includes(replacement)) {
|
|
5285
|
+
remaining.push(replacement);
|
|
5286
|
+
sourceIndices.push(firstMatchedIdx);
|
|
5287
|
+
}
|
|
5159
5288
|
for (const part of family.parts) consumed.add(part);
|
|
5160
5289
|
context.report({
|
|
5161
5290
|
node: loc.node,
|
|
@@ -5165,7 +5294,7 @@ const enforceShorthand = defineRule({
|
|
|
5165
5294
|
replacement
|
|
5166
5295
|
},
|
|
5167
5296
|
fix(fixer) {
|
|
5168
|
-
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, rebuildClassString(split, remaining)));
|
|
5297
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, rebuildClassString(split, remaining, sourceIndices)));
|
|
5169
5298
|
}
|
|
5170
5299
|
});
|
|
5171
5300
|
}
|
|
@@ -6394,6 +6523,14 @@ const consistentVariantOrder = defineRule({
|
|
|
6394
6523
|
//#endregion
|
|
6395
6524
|
//#region src/rules/enforce-consistent-line-wrapping.ts
|
|
6396
6525
|
const DEFAULT_PRINT_WIDTH = 80;
|
|
6526
|
+
/** One indentation level added below the statement's base indent for wrapped lines. */
|
|
6527
|
+
const INDENT_UNIT = " ";
|
|
6528
|
+
/** Group `classes` into chunks of at most `n`, each chunk space-joined. */
|
|
6529
|
+
function chunkList(classes, n) {
|
|
6530
|
+
const chunks = [];
|
|
6531
|
+
for (let i = 0; i < classes.length; i += n) chunks.push(classes.slice(i, i + n).join(" "));
|
|
6532
|
+
return chunks;
|
|
6533
|
+
}
|
|
6397
6534
|
const enforceConsistentLineWrapping = defineRule({
|
|
6398
6535
|
meta: {
|
|
6399
6536
|
type: "suggestion",
|
|
@@ -6409,52 +6546,97 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
6409
6546
|
}],
|
|
6410
6547
|
defaultOptions: [{ printWidth: DEFAULT_PRINT_WIDTH }],
|
|
6411
6548
|
messages: {
|
|
6412
|
-
tooLong: "Class string
|
|
6549
|
+
tooLong: "Class string exceeds the print width of {{printWidth}} (longest line is {{length}} characters). Consider splitting into multiple lines or extracting into a component.",
|
|
6413
6550
|
tooManyPerLine: "Too many classes on a single line ({{count}}). Maximum allowed per line is {{max}}."
|
|
6414
6551
|
}
|
|
6415
6552
|
},
|
|
6416
6553
|
createOnce(context) {
|
|
6417
6554
|
const getPrintWidth = createLazyOptions(context, (o) => o?.printWidth ?? DEFAULT_PRINT_WIDTH);
|
|
6418
6555
|
const getClassesPerLine = createLazyOptions(context, (o) => o?.classesPerLine);
|
|
6556
|
+
/**
|
|
6557
|
+
* The statement's real base indentation — the leading whitespace of the
|
|
6558
|
+
* source line the opening backtick sits on. NOT `node.loc.start.column`,
|
|
6559
|
+
* which is the backtick's column (e.g. 18 for `const className = ` and
|
|
6560
|
+
* deeper still inside nested JSX). Falls back to `''` when `sourceCode`
|
|
6561
|
+
* is unavailable (block still lands correctly for top-level statements).
|
|
6562
|
+
*/
|
|
6563
|
+
function deriveBaseIndent(loc) {
|
|
6564
|
+
const sc = safeSourceCode(context);
|
|
6565
|
+
const line = loc.node.loc?.start.line;
|
|
6566
|
+
if (sc?.lines && typeof line === "number" && line >= 1 && line <= sc.lines.length) {
|
|
6567
|
+
const src = sc.lines[line - 1] ?? "";
|
|
6568
|
+
const m = /^[ \t]*/.exec(src);
|
|
6569
|
+
return m ? m[0] : "";
|
|
6570
|
+
}
|
|
6571
|
+
return "";
|
|
6572
|
+
}
|
|
6573
|
+
/**
|
|
6574
|
+
* Re-wrap a template literal's classes into the block convention,
|
|
6575
|
+
* non-destructively:
|
|
6576
|
+
* - single-line → convert to a `\n` + indent block (unless the quasi is
|
|
6577
|
+
* glued to a `${}`, in which case keep it inline/hanging so adjacency
|
|
6578
|
+
* survives);
|
|
6579
|
+
* - already multiline → re-wrap ONLY the lines that exceed the budget,
|
|
6580
|
+
* reusing each line's own indent; conforming lines are left verbatim.
|
|
6581
|
+
*/
|
|
6582
|
+
function rewrapTemplate(loc, lines, classesPerLine) {
|
|
6583
|
+
const baseIndent = deriveBaseIndent(loc);
|
|
6584
|
+
const interiorIndent = baseIndent + INDENT_UNIT;
|
|
6585
|
+
if (lines.length === 1) {
|
|
6586
|
+
const chunks = chunkList(splitClasses(loc.value), classesPerLine);
|
|
6587
|
+
if (!loc.preserveLeadingSpace && !loc.preserveTrailingSpace) return "\n" + chunks.map((c) => interiorIndent + c).join("\n") + "\n" + baseIndent;
|
|
6588
|
+
return chunks.join("\n" + interiorIndent);
|
|
6589
|
+
}
|
|
6590
|
+
return lines.map((line) => {
|
|
6591
|
+
const classes = splitClasses(line);
|
|
6592
|
+
if (classes.length <= classesPerLine) return line;
|
|
6593
|
+
const m = /^[ \t]*/.exec(line);
|
|
6594
|
+
const lineIndent = m && m[0].length > 0 ? m[0] : interiorIndent;
|
|
6595
|
+
return chunkList(classes, classesPerLine).map((c) => lineIndent + c).join("\n");
|
|
6596
|
+
}).join("\n");
|
|
6597
|
+
}
|
|
6419
6598
|
function check(locations) {
|
|
6420
6599
|
const printWidth = getPrintWidth();
|
|
6421
6600
|
const classesPerLine = getClassesPerLine();
|
|
6422
6601
|
for (const loc of locations) {
|
|
6423
|
-
|
|
6602
|
+
let maxLine = 0;
|
|
6603
|
+
for (const line of loc.value.split("\n")) if (line.length > maxLine) maxLine = line.length;
|
|
6604
|
+
if (maxLine > printWidth) context.report({
|
|
6424
6605
|
node: loc.node,
|
|
6425
6606
|
messageId: "tooLong",
|
|
6426
6607
|
data: {
|
|
6427
|
-
length: String(
|
|
6608
|
+
length: String(maxLine),
|
|
6428
6609
|
printWidth: String(printWidth)
|
|
6429
6610
|
}
|
|
6430
6611
|
});
|
|
6431
6612
|
if (classesPerLine !== void 0) {
|
|
6432
|
-
const
|
|
6433
|
-
|
|
6434
|
-
|
|
6435
|
-
|
|
6436
|
-
|
|
6437
|
-
|
|
6438
|
-
|
|
6439
|
-
|
|
6613
|
+
const lines = loc.value.split("\n");
|
|
6614
|
+
let maxPerLine = 0;
|
|
6615
|
+
for (const line of lines) {
|
|
6616
|
+
const n = splitClasses(line).length;
|
|
6617
|
+
if (n > maxPerLine) maxPerLine = n;
|
|
6618
|
+
}
|
|
6619
|
+
if (maxPerLine > classesPerLine) {
|
|
6620
|
+
const data = {
|
|
6621
|
+
count: String(maxPerLine),
|
|
6622
|
+
max: String(classesPerLine)
|
|
6623
|
+
};
|
|
6624
|
+
if (loc.node.type === "TemplateElement") {
|
|
6625
|
+
const fixedValue = rewrapTemplate(loc, lines, classesPerLine);
|
|
6626
|
+
context.report({
|
|
6627
|
+
node: loc.node,
|
|
6628
|
+
messageId: "tooManyPerLine",
|
|
6629
|
+
data,
|
|
6630
|
+
fix(fixer) {
|
|
6631
|
+
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
6632
|
+
}
|
|
6633
|
+
});
|
|
6634
|
+
} else context.report({
|
|
6440
6635
|
node: loc.node,
|
|
6441
6636
|
messageId: "tooManyPerLine",
|
|
6442
|
-
data
|
|
6443
|
-
count: String(classes.length),
|
|
6444
|
-
max: String(classesPerLine)
|
|
6445
|
-
},
|
|
6446
|
-
fix(fixer) {
|
|
6447
|
-
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
6448
|
-
}
|
|
6637
|
+
data
|
|
6449
6638
|
});
|
|
6450
|
-
}
|
|
6451
|
-
node: loc.node,
|
|
6452
|
-
messageId: "tooManyPerLine",
|
|
6453
|
-
data: {
|
|
6454
|
-
count: String(classes.length),
|
|
6455
|
-
max: String(classesPerLine)
|
|
6456
|
-
}
|
|
6457
|
-
});
|
|
6639
|
+
}
|
|
6458
6640
|
}
|
|
6459
6641
|
}
|
|
6460
6642
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oxlint-tailwindcss",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Tailwind CSS linting rules for oxlint",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css",
|
|
@@ -57,10 +57,10 @@
|
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@oxlint/plugins": "catalog:",
|
|
59
59
|
"@tailwindcss/typography": "^0.5.20",
|
|
60
|
-
"@types/node": "^26.1.
|
|
60
|
+
"@types/node": "^26.1.2",
|
|
61
61
|
"oxlint": "catalog:",
|
|
62
62
|
"tailwindcss-animate": "^1.0.7",
|
|
63
|
-
"tsdown": "^0.22.
|
|
63
|
+
"tsdown": "^0.22.14",
|
|
64
64
|
"tw-animate-css": "^1.4.0",
|
|
65
65
|
"typescript": "^7.0.2",
|
|
66
66
|
"vitest": "^4.1.10"
|