oxlint-tailwindcss 1.15.1 → 1.17.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/config.cjs +2 -4
- package/dist/config.d.cts +9 -4
- package/dist/config.d.mts +9 -4
- package/dist/config.mjs +2 -4
- package/dist/index.cjs +190 -144
- package/dist/index.d.cts +0 -3
- package/dist/index.d.mts +0 -4
- package/dist/index.mjs +191 -146
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -4,10 +4,9 @@ import { createHash } from "node:crypto";
|
|
|
4
4
|
import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, statSync, unlinkSync, utimesSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
6
6
|
import { tmpdir, userInfo } from "node:os";
|
|
7
|
-
|
|
7
|
+
// \0rolldown/runtime.js
|
|
8
8
|
var __require = /* #__PURE__ */ (() => createRequire(import.meta.url))();
|
|
9
|
-
|
|
10
|
-
//#region ../../node_modules/.pnpm/@oxlint+plugins@1.87.0/node_modules/@oxlint/plugins/index.js
|
|
9
|
+
// ../../node_modules/.pnpm/@oxlint+plugins@1.89.0/node_modules/@oxlint/plugins/index.js
|
|
11
10
|
/**
|
|
12
11
|
* Define a plugin.
|
|
13
12
|
*
|
|
@@ -71,8 +70,7 @@ Object.freeze({
|
|
|
71
70
|
throw Error("Cannot access `context.parserPath` in `createOnce`");
|
|
72
71
|
}
|
|
73
72
|
});
|
|
74
|
-
|
|
75
|
-
//#region src/utils/rule-docs.ts
|
|
73
|
+
// src/utils/rule-docs.ts
|
|
76
74
|
const DOCS_URL = "https://oxlint-tailwindcss.pages.dev";
|
|
77
75
|
function ruleDocs(name, docs) {
|
|
78
76
|
return {
|
|
@@ -80,8 +78,7 @@ function ruleDocs(name, docs) {
|
|
|
80
78
|
url: `${DOCS_URL}/rules/${name}`
|
|
81
79
|
};
|
|
82
80
|
}
|
|
83
|
-
|
|
84
|
-
//#region src/utils/allowlist.ts
|
|
81
|
+
// src/utils/allowlist.ts
|
|
85
82
|
/**
|
|
86
83
|
* Shared regex-allowlist helpers for options and settings that take regex
|
|
87
84
|
* source strings: the directional rules' `allowlist`, `no-conflicting-classes`'
|
|
@@ -101,8 +98,7 @@ function compileRegexList(patterns) {
|
|
|
101
98
|
function matchesAny(value, list) {
|
|
102
99
|
return list.some((re) => re.test(value));
|
|
103
100
|
}
|
|
104
|
-
|
|
105
|
-
//#region src/utils/context.ts
|
|
101
|
+
// src/utils/context.ts
|
|
106
102
|
/**
|
|
107
103
|
* Safely read `context.options[0]`. Returns `undefined` if the getter throws
|
|
108
104
|
* (oxlint < 1.31.0) or if options aren't populated yet.
|
|
@@ -250,8 +246,7 @@ function createLazySettings(context, compile) {
|
|
|
250
246
|
function settingsKey(settings) {
|
|
251
247
|
return JSON.stringify(settings?.tailwindcss) ?? "";
|
|
252
248
|
}
|
|
253
|
-
|
|
254
|
-
//#region src/utils/css-properties.ts
|
|
249
|
+
// src/utils/css-properties.ts
|
|
255
250
|
/**
|
|
256
251
|
* CSS property names (standard, SVG and `-ms-`), from csstype's `*PropertiesHyphen`
|
|
257
252
|
* interfaces, minus the 15 that are also Tailwind classes (`flex`, `grid`, `border`,
|
|
@@ -368,8 +363,7 @@ const CSS_PROPERTY_NAMES = new Set(`
|
|
|
368
363
|
view-transition-name visibility white-space white-space-collapse widows width will-change
|
|
369
364
|
word-break word-spacing word-wrap writing-mode x y z-index zoom
|
|
370
365
|
`.trim().split(/\s+/));
|
|
371
|
-
|
|
372
|
-
//#region src/utils/levenshtein.ts
|
|
366
|
+
// src/utils/levenshtein.ts
|
|
373
367
|
let bufA = /* @__PURE__ */ new Int32Array(64);
|
|
374
368
|
let bufB = /* @__PURE__ */ new Int32Array(64);
|
|
375
369
|
let bufC = /* @__PURE__ */ new Int32Array(64);
|
|
@@ -448,8 +442,7 @@ function findBestSuggestion(input, candidates, maxDistance = 3) {
|
|
|
448
442
|
}
|
|
449
443
|
return best;
|
|
450
444
|
}
|
|
451
|
-
|
|
452
|
-
//#region src/utils/settings-check.ts
|
|
445
|
+
// src/utils/settings-check.ts
|
|
453
446
|
const SETTINGS_MESSAGE_ID = "invalidSetting";
|
|
454
447
|
/** Pre-shaped entry for `meta.messages`: `messages: { ..., ...SETTINGS_MESSAGE }`. */
|
|
455
448
|
const SETTINGS_MESSAGE = { [SETTINGS_MESSAGE_ID]: "{{message}}" };
|
|
@@ -465,6 +458,7 @@ const CHECKS = {
|
|
|
465
458
|
calleeExtractors: "extractors",
|
|
466
459
|
tags: "strings",
|
|
467
460
|
variablePatterns: "regexes",
|
|
461
|
+
lookupTablePatterns: "regexes",
|
|
468
462
|
exclude: "exclude"
|
|
469
463
|
};
|
|
470
464
|
const EXCLUDE_KEYS = {
|
|
@@ -562,8 +556,7 @@ function reportSettingsProblems(context, program) {
|
|
|
562
556
|
}
|
|
563
557
|
});
|
|
564
558
|
}
|
|
565
|
-
|
|
566
|
-
//#region src/utils/extractors.ts
|
|
559
|
+
// src/utils/extractors.ts
|
|
567
560
|
/**
|
|
568
561
|
* Whether this string is the element's FINAL, self-contained class list — the
|
|
569
562
|
* only position where a RELATIONAL rule (one whose verdict for a class depends
|
|
@@ -620,6 +613,7 @@ const DEFAULT_EXTRACTOR_CONFIG = {
|
|
|
620
613
|
/^classes$/,
|
|
621
614
|
/^styles?$/
|
|
622
615
|
],
|
|
616
|
+
lookupTablePatterns: [],
|
|
623
617
|
calleeExtractors: /* @__PURE__ */ new Map()
|
|
624
618
|
};
|
|
625
619
|
/**
|
|
@@ -711,6 +705,7 @@ function compileExtractorConfig(tw) {
|
|
|
711
705
|
callees: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.callees, [...tw.callees ?? [], ...calleeExtractors.keys()], exclude?.callees),
|
|
712
706
|
tags: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.tags, tw.tags, exclude?.tags),
|
|
713
707
|
variablePatterns: [...filteredPatterns, ...compileRegexList(tw.variablePatterns)],
|
|
708
|
+
lookupTablePatterns: compileRegexList(tw.lookupTablePatterns),
|
|
714
709
|
calleeExtractors
|
|
715
710
|
};
|
|
716
711
|
}
|
|
@@ -987,13 +982,41 @@ function getPropertyName(key) {
|
|
|
987
982
|
/**
|
|
988
983
|
* Extracts class locations from a VariableDeclarator whose name matches variablePatterns.
|
|
989
984
|
* e.g. const className = "flex items-center"
|
|
985
|
+
*
|
|
986
|
+
* A name matching lookupTablePatterns whose initializer is an object literal is
|
|
987
|
+
* a lookup table instead: its values are read, not its keys.
|
|
988
|
+
* e.g. const TONE_CLASSES = { warning: "text-amber-700" }
|
|
990
989
|
*/
|
|
991
990
|
function extractFromVariableDeclarator(node, config = DEFAULT_EXTRACTOR_CONFIG) {
|
|
992
991
|
if (node.id.type !== "Identifier") return [];
|
|
993
|
-
|
|
992
|
+
const name = node.id.name;
|
|
993
|
+
if (node.init && config.lookupTablePatterns.some((p) => p.test(name))) {
|
|
994
|
+
const table = withoutTypeAssertion(node.init);
|
|
995
|
+
if (table.type === "ObjectExpression") return withOrigin(extractLookupTable(table), "variable");
|
|
996
|
+
}
|
|
997
|
+
if (!config.variablePatterns.some((p) => p.test(name))) return [];
|
|
994
998
|
if (!node.init) return [];
|
|
995
999
|
return withOrigin(extractFromExpression(node.init), "variable");
|
|
996
1000
|
}
|
|
1001
|
+
/** `{…} as const` and `{…} satisfies T` are the same object literal. */
|
|
1002
|
+
function withoutTypeAssertion(node) {
|
|
1003
|
+
let inner = node;
|
|
1004
|
+
while (inner.type === "TSAsExpression" || inner.type === "TSSatisfiesExpression") inner = inner.expression;
|
|
1005
|
+
return inner;
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* A lookup table's values, recursing into nested tables
|
|
1009
|
+
* (`{ sm: { root: "…", label: "…" } }`): there, too, the keys are names.
|
|
1010
|
+
*/
|
|
1011
|
+
function extractLookupTable(node, out = []) {
|
|
1012
|
+
for (const prop of node.properties) {
|
|
1013
|
+
if (prop.type !== "Property") continue;
|
|
1014
|
+
const value = withoutTypeAssertion(prop.value);
|
|
1015
|
+
if (value.type === "ObjectExpression") extractLookupTable(value, out);
|
|
1016
|
+
else extractFromExpression(value, out);
|
|
1017
|
+
}
|
|
1018
|
+
return out;
|
|
1019
|
+
}
|
|
997
1020
|
/**
|
|
998
1021
|
* Walk an expression and append every class-bearing location to `out`.
|
|
999
1022
|
*
|
|
@@ -1017,7 +1040,18 @@ function extractFromExpression(node, out = []) {
|
|
|
1017
1040
|
extractFromExpression(node.alternate, out);
|
|
1018
1041
|
return out;
|
|
1019
1042
|
}
|
|
1020
|
-
if (node.type === "LogicalExpression")
|
|
1043
|
+
if (node.type === "LogicalExpression") {
|
|
1044
|
+
const { operator, left, right } = node;
|
|
1045
|
+
if (operator !== "&&") extractFromExpression(left, out);
|
|
1046
|
+
return extractFromExpression(right, out);
|
|
1047
|
+
}
|
|
1048
|
+
if (node.type === "MemberExpression" && node.computed) {
|
|
1049
|
+
const object = withoutTypeAssertion(node.object);
|
|
1050
|
+
if (object.type === "ObjectExpression") {
|
|
1051
|
+
for (const prop of object.properties) if (prop.type === "Property") extractFromExpression(prop.value, out);
|
|
1052
|
+
} else if (object.type === "ArrayExpression") extractFromExpression(object, out);
|
|
1053
|
+
return out;
|
|
1054
|
+
}
|
|
1021
1055
|
if (node.type === "BinaryExpression" && node.operator === "+") return appendFromConcatenation(node, out);
|
|
1022
1056
|
if (node.type === "ArrayExpression") {
|
|
1023
1057
|
for (const element of node.elements) if (element && element.type !== "SpreadElement") extractFromExpression(element, out);
|
|
@@ -1160,8 +1194,7 @@ function getCalleeName(node) {
|
|
|
1160
1194
|
if (prop.type === "Identifier") return prop.name;
|
|
1161
1195
|
}
|
|
1162
1196
|
}
|
|
1163
|
-
|
|
1164
|
-
//#region src/utils/class-splitter.ts
|
|
1197
|
+
// src/utils/class-splitter.ts
|
|
1165
1198
|
function isWhitespace(char) {
|
|
1166
1199
|
return char === " " || char === " " || char === "\n" || char === "\r" || char === "\f" || char === "\v";
|
|
1167
1200
|
}
|
|
@@ -1295,8 +1328,7 @@ function rebuildClassString(split, newClasses, sourceIndices) {
|
|
|
1295
1328
|
const join = separators.slice(1, -1).find((s) => s.includes("\n")) ?? " ";
|
|
1296
1329
|
return separators[0] + newClasses.join(join) + separators[separators.length - 1];
|
|
1297
1330
|
}
|
|
1298
|
-
|
|
1299
|
-
//#region src/rules/no-duplicate-classes.ts
|
|
1331
|
+
// src/rules/no-duplicate-classes.ts
|
|
1300
1332
|
const noDuplicateClasses = defineRule({
|
|
1301
1333
|
meta: {
|
|
1302
1334
|
type: "problem",
|
|
@@ -1344,8 +1376,7 @@ const noDuplicateClasses = defineRule({
|
|
|
1344
1376
|
return createExtractorVisitors(context, check);
|
|
1345
1377
|
}
|
|
1346
1378
|
});
|
|
1347
|
-
|
|
1348
|
-
//#region src/rules/no-unnecessary-whitespace.ts
|
|
1379
|
+
// src/rules/no-unnecessary-whitespace.ts
|
|
1349
1380
|
const noUnnecessaryWhitespace = defineRule({
|
|
1350
1381
|
meta: {
|
|
1351
1382
|
type: "suggestion",
|
|
@@ -1388,8 +1419,7 @@ const noUnnecessaryWhitespace = defineRule({
|
|
|
1388
1419
|
return createExtractorVisitors(context, check, { raw: true });
|
|
1389
1420
|
}
|
|
1390
1421
|
});
|
|
1391
|
-
|
|
1392
|
-
//#region src/utils/report.ts
|
|
1422
|
+
// src/utils/report.ts
|
|
1393
1423
|
/**
|
|
1394
1424
|
* Shared reporters: `reportClassReplacements` for the "first-as-fix,
|
|
1395
1425
|
* rest-as-suggestion" pattern, `reportClassSuggestion` for a suggestion alone.
|
|
@@ -1481,8 +1511,7 @@ function reportClassSuggestion(context, loc, split, classes, { cls, replacement
|
|
|
1481
1511
|
}]
|
|
1482
1512
|
});
|
|
1483
1513
|
}
|
|
1484
|
-
|
|
1485
|
-
//#region src/utils/class-parser.ts
|
|
1514
|
+
// src/utils/class-parser.ts
|
|
1486
1515
|
/**
|
|
1487
1516
|
* Extracts variants from a class string, respecting bracket depth.
|
|
1488
1517
|
* e.g. "[&>svg]:hover:w-4" → ["[&>svg]", "hover"]
|
|
@@ -1752,8 +1781,7 @@ function isSelectorBarrier(variant, facts) {
|
|
|
1752
1781
|
function changesTarget(variant, facts) {
|
|
1753
1782
|
return isPseudoElementVariant(variant, facts) || isSelectorBarrier(variant, facts);
|
|
1754
1783
|
}
|
|
1755
|
-
|
|
1756
|
-
//#region src/design-system/css-declarations.ts
|
|
1784
|
+
// src/design-system/css-declarations.ts
|
|
1757
1785
|
const EMPTY_DECLS = [];
|
|
1758
1786
|
const EMPTY_VARS = [];
|
|
1759
1787
|
/** Splits a scope token into its decoded parts. Unknown tokens degrade to `element`. */
|
|
@@ -1848,8 +1876,7 @@ function isCssDeclarationIndex(value) {
|
|
|
1848
1876
|
const i = value;
|
|
1849
1877
|
return Array.isArray(i.scopes) && i.scopes.length > 0 && i.scopes[0] === "" && Array.isArray(i.props) && Array.isArray(i.values) && Array.isArray(i.vars) && Array.isArray(i.table) && Array.isArray(i.pureValues) && Array.isArray(i.partial) && typeof i.byClass === "object" && i.byClass !== null && typeof i.valueVars === "object" && i.valueVars !== null && typeof i.valueFallbackVars === "object" && i.valueFallbackVars !== null;
|
|
1850
1878
|
}
|
|
1851
|
-
|
|
1852
|
-
//#region src/utils/floating-point.ts
|
|
1879
|
+
// src/utils/floating-point.ts
|
|
1853
1880
|
/**
|
|
1854
1881
|
* Rounds rem/em/px values in class strings to avoid
|
|
1855
1882
|
* JavaScript floating point issues.
|
|
@@ -1863,8 +1890,7 @@ function roundRemValue(className) {
|
|
|
1863
1890
|
return `[${Number.parseFloat(Number.parseFloat(num).toFixed(6))}${unit}]`;
|
|
1864
1891
|
});
|
|
1865
1892
|
}
|
|
1866
|
-
|
|
1867
|
-
//#region src/design-system/cache.ts
|
|
1893
|
+
// src/design-system/cache.ts
|
|
1868
1894
|
const EMPTY_DECLARATIONS = [];
|
|
1869
1895
|
const EMPTY_TOKEN_VALUES = [];
|
|
1870
1896
|
/** Off-scale numeric value: `w-45`, `min-h-17.5`, `gap-13`. */
|
|
@@ -2424,8 +2450,7 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
2424
2450
|
return null;
|
|
2425
2451
|
}
|
|
2426
2452
|
};
|
|
2427
|
-
|
|
2428
|
-
//#region src/utils/fatal.ts
|
|
2453
|
+
// src/utils/fatal.ts
|
|
2429
2454
|
/**
|
|
2430
2455
|
* Fatal error types and reporter for the deterministic v1 design.
|
|
2431
2456
|
*
|
|
@@ -2538,8 +2563,7 @@ function softGetDS(getDS) {
|
|
|
2538
2563
|
throw err;
|
|
2539
2564
|
}
|
|
2540
2565
|
}
|
|
2541
|
-
|
|
2542
|
-
//#region src/design-system/tailwind-node.ts
|
|
2566
|
+
// src/design-system/tailwind-node.ts
|
|
2543
2567
|
/**
|
|
2544
2568
|
* Resolves the Tailwind engine (`@tailwindcss/node`) the plugin runs against.
|
|
2545
2569
|
*
|
|
@@ -2683,8 +2707,7 @@ function resolveTailwindNodeFor(cssPath) {
|
|
|
2683
2707
|
resolutionCache.set(cssDir, result);
|
|
2684
2708
|
return result;
|
|
2685
2709
|
}
|
|
2686
|
-
|
|
2687
|
-
//#region src/design-system/sync-loader.ts
|
|
2710
|
+
// src/design-system/sync-loader.ts
|
|
2688
2711
|
/**
|
|
2689
2712
|
* Synchronous design system loader using a worker_thread.
|
|
2690
2713
|
*
|
|
@@ -3603,6 +3626,18 @@ async function main() {
|
|
|
3603
3626
|
// SINGLE because a class that declares more than the original is not an
|
|
3604
3627
|
// equivalent: \`text-sm\` sets \`line-height\` too, so \`text-[14px]\` is not it.
|
|
3605
3628
|
const NUMERIC_LITERAL = /^-?\\d*\\.?\\d+(rem|px|em|%|s|ms|deg)?$/;
|
|
3629
|
+
// The utility a token class belongs to is the class minus the token's own
|
|
3630
|
+
// name: \`p-brand-md\` reads \`--spacing-brand-md\`, so its utility is \`p\`, not
|
|
3631
|
+
// \`p-brand\`. Cutting at the last dash only works for one-word token names.
|
|
3632
|
+
// A class whose variable shares no suffix with it keeps that last-dash cut.
|
|
3633
|
+
function tokenPrefix(cls, variable) {
|
|
3634
|
+
const name = variable.slice(2);
|
|
3635
|
+
for (let dash = cls.indexOf('-'); dash > 0; dash = cls.indexOf('-', dash + 1)) {
|
|
3636
|
+
if (name.endsWith(cls.slice(dash))) return cls.slice(0, dash);
|
|
3637
|
+
}
|
|
3638
|
+
const last = cls.lastIndexOf('-');
|
|
3639
|
+
return last > 0 ? cls.slice(0, last) : '';
|
|
3640
|
+
}
|
|
3606
3641
|
const tokenValues = {};
|
|
3607
3642
|
for (const cls of validClasses) {
|
|
3608
3643
|
if (cls.includes('[') || cls.includes('/')) continue;
|
|
@@ -3614,11 +3649,13 @@ async function main() {
|
|
|
3614
3649
|
const body = css.slice(open + 1, close).replace(/\\s+/g, ' ').replace(/;\\s*$/, '').trim();
|
|
3615
3650
|
const m = /^([a-z-]+):\\s*var\\((--[\\w-]+)\\)$/.exec(body);
|
|
3616
3651
|
if (!m) continue;
|
|
3652
|
+
// \`mt-1\` reads the bare \`--spacing\`: it is a step of the scale, the second
|
|
3653
|
+
// family, not a named token. Filed here it would tie with a project token
|
|
3654
|
+
// of the same value and win on name order.
|
|
3655
|
+
if (m[2] === '--spacing') continue;
|
|
3617
3656
|
const value = themeValues.get(m[2]);
|
|
3618
3657
|
if (!value || !NUMERIC_LITERAL.test(value)) continue;
|
|
3619
|
-
const
|
|
3620
|
-
if (dash <= 0) continue;
|
|
3621
|
-
const prefix = unpfx(cls).slice(0, unpfx(cls).lastIndexOf('-'));
|
|
3658
|
+
const prefix = tokenPrefix(unpfx(cls), m[2]);
|
|
3622
3659
|
if (!prefix) continue;
|
|
3623
3660
|
if (!tokenValues[prefix]) tokenValues[prefix] = [];
|
|
3624
3661
|
tokenValues[prefix].push([value, unpfx(cls)]);
|
|
@@ -4124,8 +4161,7 @@ function loadDesignSystemSync(cssPath, timeout, onPrecompute) {
|
|
|
4124
4161
|
pruneCacheDir();
|
|
4125
4162
|
return data;
|
|
4126
4163
|
}
|
|
4127
|
-
|
|
4128
|
-
//#region src/design-system/debug.ts
|
|
4164
|
+
// src/design-system/debug.ts
|
|
4129
4165
|
const PREFIX = "[oxlint-tailwindcss]";
|
|
4130
4166
|
let _enabled = null;
|
|
4131
4167
|
/**
|
|
@@ -4152,8 +4188,7 @@ function setDebugEnabled(enabled) {
|
|
|
4152
4188
|
function debugLog(message) {
|
|
4153
4189
|
if (_enabled || process.env.DEBUG === "oxlint-tailwindcss") console.error(`${PREFIX} ${message}`);
|
|
4154
4190
|
}
|
|
4155
|
-
|
|
4156
|
-
//#region src/design-system/engine-guard.ts
|
|
4191
|
+
// src/design-system/engine-guard.ts
|
|
4157
4192
|
/**
|
|
4158
4193
|
* Version safeguards for the consumer-resolved Tailwind engine.
|
|
4159
4194
|
*
|
|
@@ -4367,8 +4402,7 @@ function allowUntestedEngineFromSettings(settings) {
|
|
|
4367
4402
|
if (tw && typeof tw === "object" && "allowUntestedEngine" in tw) return tw.allowUntestedEngine === true;
|
|
4368
4403
|
return false;
|
|
4369
4404
|
}
|
|
4370
|
-
|
|
4371
|
-
//#region src/design-system/ds-worker.ts
|
|
4405
|
+
// src/design-system/ds-worker.ts
|
|
4372
4406
|
/**
|
|
4373
4407
|
* Generic worker-thread service wrapping `__unstable__loadDesignSystem`.
|
|
4374
4408
|
*
|
|
@@ -4724,8 +4758,7 @@ var DesignSystemWorker = class {
|
|
|
4724
4758
|
} catch {}
|
|
4725
4759
|
}
|
|
4726
4760
|
};
|
|
4727
|
-
|
|
4728
|
-
//#region src/design-system/canonicalize-service.ts
|
|
4761
|
+
// src/design-system/canonicalize-service.ts
|
|
4729
4762
|
/**
|
|
4730
4763
|
* Persistent canonicalize service backed by `DesignSystemWorker`.
|
|
4731
4764
|
*
|
|
@@ -5161,8 +5194,7 @@ function canonicalizeClassesSync(cssPath, classes, rem) {
|
|
|
5161
5194
|
}
|
|
5162
5195
|
return out;
|
|
5163
5196
|
}
|
|
5164
|
-
|
|
5165
|
-
//#region src/design-system/loader.ts
|
|
5197
|
+
// src/design-system/loader.ts
|
|
5166
5198
|
const dsCache = /* @__PURE__ */ new Map();
|
|
5167
5199
|
/**
|
|
5168
5200
|
* Memoizes DS-load FAILURES per entry point, keyed by `(resolvedPath, mtime)`.
|
|
@@ -5254,7 +5286,7 @@ function resolveByGlobMapping(mappings, filePath, baseDir) {
|
|
|
5254
5286
|
}
|
|
5255
5287
|
/**
|
|
5256
5288
|
* oxlint discovers nested configuration by walking up from each linted file
|
|
5257
|
-
* looking for files with these names (oxlint 1.
|
|
5289
|
+
* looking for files with these names (oxlint 1.89: JSON, JSONC, and the JS
|
|
5258
5290
|
* configs it loads through Node). We mirror that walk to find the config
|
|
5259
5291
|
* directory a relative `entryPoint` should be anchored to — which is also
|
|
5260
5292
|
* where an `oxlint.config.ts` passes it through `oxlint-tailwindcss/config`.
|
|
@@ -5601,8 +5633,7 @@ function validateClassesSync(cssPath, cache, classes) {
|
|
|
5601
5633
|
ask(cssPath, cache, classes);
|
|
5602
5634
|
return answersFor(cache);
|
|
5603
5635
|
}
|
|
5604
|
-
|
|
5605
|
-
//#region src/rules/no-unknown-classes.ts
|
|
5636
|
+
// src/rules/no-unknown-classes.ts
|
|
5606
5637
|
/**
|
|
5607
5638
|
* Utility used to probe a variant chain. Any always-valid utility works; `flex`
|
|
5608
5639
|
* is the shortest one every Tailwind build has.
|
|
@@ -5839,8 +5870,7 @@ const noUnknownClasses = defineRule({
|
|
|
5839
5870
|
return createExtractorVisitors(context, check);
|
|
5840
5871
|
}
|
|
5841
5872
|
});
|
|
5842
|
-
|
|
5843
|
-
//#region src/rules/no-conflicting-classes/spec.ts
|
|
5873
|
+
// src/rules/no-conflicting-classes/spec.ts
|
|
5844
5874
|
const COMPLEMENTARY_GROUPS = [{
|
|
5845
5875
|
pattern: /^prose(?:-|$)/,
|
|
5846
5876
|
reason: "`prose` + `prose-sm`/`prose-lg`/`prose-xl` modify the same scope and are designed to compose."
|
|
@@ -5867,8 +5897,7 @@ const COMPOSITION_PAIRS = [
|
|
|
5867
5897
|
reason: "`mask-{add,subtract,intersect,exclude}` are mask-composite modes that compose with mask-gradient utilities."
|
|
5868
5898
|
}
|
|
5869
5899
|
];
|
|
5870
|
-
|
|
5871
|
-
//#region src/rules/no-conflicting-classes/decide.ts
|
|
5900
|
+
// src/rules/no-conflicting-classes/decide.ts
|
|
5872
5901
|
/** Builds the comparison key. Same property on two different boxes never clashes. */
|
|
5873
5902
|
function declKey(decl) {
|
|
5874
5903
|
return decl.scope === "element" ? decl.prop : `${decl.pseudo || ">"}|${decl.prop}`;
|
|
@@ -6064,8 +6093,7 @@ function redundantSide(verdict) {
|
|
|
6064
6093
|
};
|
|
6065
6094
|
return null;
|
|
6066
6095
|
}
|
|
6067
|
-
|
|
6068
|
-
//#region src/rules/no-conflicting-classes.ts
|
|
6096
|
+
// src/rules/no-conflicting-classes.ts
|
|
6069
6097
|
/**
|
|
6070
6098
|
* Compiles the `allow` option.
|
|
6071
6099
|
*
|
|
@@ -6281,8 +6309,7 @@ const noConflictingClasses = defineRule({
|
|
|
6281
6309
|
return createExtractorVisitors(context, check);
|
|
6282
6310
|
}
|
|
6283
6311
|
});
|
|
6284
|
-
|
|
6285
|
-
//#region src/utils/replacement.ts
|
|
6312
|
+
// src/utils/replacement.ts
|
|
6286
6313
|
/**
|
|
6287
6314
|
* Returns a predicate that answers "would this replacement produce CSS?".
|
|
6288
6315
|
*
|
|
@@ -6295,8 +6322,7 @@ function makeReplacementGuard(cache) {
|
|
|
6295
6322
|
if (!cache) return () => true;
|
|
6296
6323
|
return (replacement) => cache.isValid(replacement);
|
|
6297
6324
|
}
|
|
6298
|
-
|
|
6299
|
-
//#region src/rules/no-deprecated-classes.ts
|
|
6325
|
+
// src/rules/no-deprecated-classes.ts
|
|
6300
6326
|
/**
|
|
6301
6327
|
* Fallback rename map, for when no design system is available.
|
|
6302
6328
|
*
|
|
@@ -6374,8 +6400,7 @@ const noDeprecatedClasses = defineRule({
|
|
|
6374
6400
|
return createExtractorVisitors(context, check);
|
|
6375
6401
|
}
|
|
6376
6402
|
});
|
|
6377
|
-
|
|
6378
|
-
//#region src/rules/enforce-canonical.ts
|
|
6403
|
+
// src/rules/enforce-canonical.ts
|
|
6379
6404
|
/**
|
|
6380
6405
|
* Preserve the user's `!` position after canonicalization.
|
|
6381
6406
|
*
|
|
@@ -6564,8 +6589,7 @@ const sortWorker = new DesignSystemWorker({
|
|
|
6564
6589
|
function sortClassesSync(cssPath, classes) {
|
|
6565
6590
|
return sortWorker.callSync(cssPath, classes);
|
|
6566
6591
|
}
|
|
6567
|
-
|
|
6568
|
-
//#region src/rules/enforce-sort-order.ts
|
|
6592
|
+
// src/rules/enforce-sort-order.ts
|
|
6569
6593
|
const enforceSortOrder = defineRule({
|
|
6570
6594
|
meta: {
|
|
6571
6595
|
type: "suggestion",
|
|
@@ -6663,8 +6687,7 @@ const enforceSortOrder = defineRule({
|
|
|
6663
6687
|
return createExtractorVisitors(context, check);
|
|
6664
6688
|
}
|
|
6665
6689
|
});
|
|
6666
|
-
|
|
6667
|
-
//#region src/utils/declared-values.ts
|
|
6690
|
+
// src/utils/declared-values.ts
|
|
6668
6691
|
/** A plain number or fraction: always the shared numeric/`--spacing` scale. */
|
|
6669
6692
|
const NUMERIC_VALUE_RE = /^\d+(?:\.\d+)?(?:\/\d+(?:\.\d+)?)?$/;
|
|
6670
6693
|
/** The value is a literal the user wrote, injected verbatim into every part. */
|
|
@@ -6688,8 +6711,7 @@ function sameValues(a, b) {
|
|
|
6688
6711
|
for (const value of a) if (!b.has(value)) return false;
|
|
6689
6712
|
return true;
|
|
6690
6713
|
}
|
|
6691
|
-
|
|
6692
|
-
//#region src/rules/enforce-shorthand.ts
|
|
6714
|
+
// src/rules/enforce-shorthand.ts
|
|
6693
6715
|
/**
|
|
6694
6716
|
* The `m`/`p` shape, shared by `margin`, `padding`, `scroll-margin` and
|
|
6695
6717
|
* `scroll-padding`: four sides, each axis, and the logical pairs (`ms`+`me` IS
|
|
@@ -7057,8 +7079,7 @@ const enforceShorthand = defineRule({
|
|
|
7057
7079
|
return createExtractorVisitors(context, check);
|
|
7058
7080
|
}
|
|
7059
7081
|
});
|
|
7060
|
-
|
|
7061
|
-
//#region src/rules/enforce-logical.ts
|
|
7082
|
+
// src/rules/enforce-logical.ts
|
|
7062
7083
|
const LOGICAL_PHYSICAL_SCHEMA = {
|
|
7063
7084
|
type: "object",
|
|
7064
7085
|
properties: {
|
|
@@ -7537,8 +7558,7 @@ const enforceLogical = defineRule({
|
|
|
7537
7558
|
return createExtractorVisitors(context, check);
|
|
7538
7559
|
}
|
|
7539
7560
|
});
|
|
7540
|
-
|
|
7541
|
-
//#region src/rules/enforce-physical.ts
|
|
7561
|
+
// src/rules/enforce-physical.ts
|
|
7542
7562
|
const PHYSICAL_MAPPINGS = invertAxisMappings(PHYSICAL_TO_LOGICAL_MAPPINGS);
|
|
7543
7563
|
const enforcePhysical = defineRule({
|
|
7544
7564
|
meta: {
|
|
@@ -7571,8 +7591,7 @@ const enforcePhysical = defineRule({
|
|
|
7571
7591
|
return createExtractorVisitors(context, check);
|
|
7572
7592
|
}
|
|
7573
7593
|
});
|
|
7574
|
-
|
|
7575
|
-
//#region src/rules/max-class-count.ts
|
|
7594
|
+
// src/rules/max-class-count.ts
|
|
7576
7595
|
const DEFAULT_MAX = 20;
|
|
7577
7596
|
const EXPRESSION = "\0";
|
|
7578
7597
|
/**
|
|
@@ -7635,8 +7654,7 @@ const maxClassCount = defineRule({
|
|
|
7635
7654
|
return createExtractorVisitors(context, check, { raw: true });
|
|
7636
7655
|
}
|
|
7637
7656
|
});
|
|
7638
|
-
|
|
7639
|
-
//#region src/rules/no-restricted-classes.ts
|
|
7657
|
+
// src/rules/no-restricted-classes.ts
|
|
7640
7658
|
const noRestrictedClasses = defineRule({
|
|
7641
7659
|
meta: {
|
|
7642
7660
|
type: "problem",
|
|
@@ -7728,8 +7746,7 @@ const noRestrictedClasses = defineRule({
|
|
|
7728
7746
|
return createExtractorVisitors(context, check);
|
|
7729
7747
|
}
|
|
7730
7748
|
});
|
|
7731
|
-
|
|
7732
|
-
//#region src/utils/measure.ts
|
|
7749
|
+
// src/utils/measure.ts
|
|
7733
7750
|
/** A length or plain number. Anything else can't be compared arithmetically. */
|
|
7734
7751
|
const LENGTH_RE = /^(-?\d*\.?\d+)(rem|px|em)?$/;
|
|
7735
7752
|
/**
|
|
@@ -7758,6 +7775,11 @@ function measure(value, rootFontSize) {
|
|
|
7758
7775
|
default: return null;
|
|
7759
7776
|
}
|
|
7760
7777
|
}
|
|
7778
|
+
/** The unit a length is written in (`'px'`, `'rem'`, `'em'`, `''` for none); null for anything else. */
|
|
7779
|
+
function lengthUnit(value) {
|
|
7780
|
+
const match = LENGTH_RE.exec(value.trim());
|
|
7781
|
+
return match ? match[2] ?? "" : null;
|
|
7782
|
+
}
|
|
7761
7783
|
/**
|
|
7762
7784
|
* Same value, allowing for float noise (`0.875rem` × 16 = 13.999999999999998).
|
|
7763
7785
|
* A unitless number and a length are never the same value, whatever the digits.
|
|
@@ -7808,20 +7830,23 @@ function closestOnScale(cache, bare, rootFontSize, limit = 3) {
|
|
|
7808
7830
|
distance: Math.abs(px - written.px)
|
|
7809
7831
|
});
|
|
7810
7832
|
};
|
|
7833
|
+
const sign = written.px < 0 ? -1 : 1;
|
|
7834
|
+
const named = (className) => sign < 0 ? `-${className}` : className;
|
|
7811
7835
|
for (const [literal, className] of cache.tokenValuesFor(prefix)) {
|
|
7812
7836
|
const token = measure(literal, rootFontSize);
|
|
7813
|
-
if (token
|
|
7837
|
+
if (token === null || token.unitless) continue;
|
|
7838
|
+
if (sign > 0 || cache.isValid(named(className))) add(named(className), sign * token.px);
|
|
7814
7839
|
}
|
|
7815
7840
|
const scale = cache.scale;
|
|
7816
7841
|
if (scale && cache.readsScale(prefix)) {
|
|
7817
7842
|
const unit = measure(scale.unit, rootFontSize);
|
|
7818
7843
|
if (unit !== null && !unit.unitless && unit.px > 0) {
|
|
7819
|
-
const steps = written.px / unit.px / scale.step;
|
|
7844
|
+
const steps = sign * written.px / unit.px / scale.step;
|
|
7820
7845
|
for (const n of /* @__PURE__ */ new Set([Math.floor(steps + 1e-9), Math.ceil(steps - 1e-9)])) {
|
|
7821
7846
|
const count = n * scale.step;
|
|
7822
|
-
if (count < 0) continue;
|
|
7823
|
-
const className = `${prefix}-${formatStep(count)}
|
|
7824
|
-
if (cache.isValid(className)) add(className, count * unit.px);
|
|
7847
|
+
if (count < 0 || sign < 0 && count === 0) continue;
|
|
7848
|
+
const className = named(`${prefix}-${formatStep(count)}`);
|
|
7849
|
+
if (cache.isValid(className)) add(className, sign * count * unit.px);
|
|
7825
7850
|
}
|
|
7826
7851
|
}
|
|
7827
7852
|
}
|
|
@@ -7843,8 +7868,7 @@ function formatOptions(options) {
|
|
|
7843
7868
|
const parts = options.map((o) => `${o.className} (${o.value})`);
|
|
7844
7869
|
return parts.length <= 1 ? parts[0] ?? "" : `${parts.slice(0, -1).join(", ")} or ${parts.at(-1)}`;
|
|
7845
7870
|
}
|
|
7846
|
-
|
|
7847
|
-
//#region src/rules/no-arbitrary-value.ts
|
|
7871
|
+
// src/rules/no-arbitrary-value.ts
|
|
7848
7872
|
const SHORTHAND_VAR = /^-?[a-z][\w-]*?-\((?:[a-z-]+:)?(--[\w-]+)\)(?:\/.+)?$/;
|
|
7849
7873
|
const EXPLICIT_VAR = /^-?[a-z][\w-]*?-\[(?:[a-z-]+:)?var\((--[\w-]+)(?:,[^\]]*)?\)\](?:\/.+)?$/;
|
|
7850
7874
|
/**
|
|
@@ -7961,8 +7985,7 @@ const noArbitraryValue = defineRule({
|
|
|
7961
7985
|
return createExtractorVisitors(context, check);
|
|
7962
7986
|
}
|
|
7963
7987
|
});
|
|
7964
|
-
|
|
7965
|
-
//#region src/rules/enforce-consistent-important-position.ts
|
|
7988
|
+
// src/rules/enforce-consistent-important-position.ts
|
|
7966
7989
|
const enforceConsistentImportantPosition = defineRule({
|
|
7967
7990
|
meta: {
|
|
7968
7991
|
type: "suggestion",
|
|
@@ -8016,8 +8039,7 @@ const enforceConsistentImportantPosition = defineRule({
|
|
|
8016
8039
|
return createExtractorVisitors(context, check);
|
|
8017
8040
|
}
|
|
8018
8041
|
});
|
|
8019
|
-
|
|
8020
|
-
//#region src/rules/enforce-negative-arbitrary-values.ts
|
|
8042
|
+
// src/rules/enforce-negative-arbitrary-values.ts
|
|
8021
8043
|
const SIMPLE_DIMENSION = /^\d*\.?\d+[a-z%]*$/;
|
|
8022
8044
|
function fixClass(cls) {
|
|
8023
8045
|
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
@@ -8074,8 +8096,7 @@ const enforceNegativeArbitraryValues = defineRule({
|
|
|
8074
8096
|
return createExtractorVisitors(context, check);
|
|
8075
8097
|
}
|
|
8076
8098
|
});
|
|
8077
|
-
|
|
8078
|
-
//#region src/rules/enforce-consistent-variable-syntax.ts
|
|
8099
|
+
// src/rules/enforce-consistent-variable-syntax.ts
|
|
8079
8100
|
const enforceConsistentVariableSyntax = defineRule({
|
|
8080
8101
|
meta: {
|
|
8081
8102
|
type: "suggestion",
|
|
@@ -8123,8 +8144,7 @@ const enforceConsistentVariableSyntax = defineRule({
|
|
|
8123
8144
|
return createExtractorVisitors(context, check);
|
|
8124
8145
|
}
|
|
8125
8146
|
});
|
|
8126
|
-
|
|
8127
|
-
//#region src/rules/no-dark-without-light.ts
|
|
8147
|
+
// src/rules/no-dark-without-light.ts
|
|
8128
8148
|
const DEFAULT_VARIANTS = ["dark"];
|
|
8129
8149
|
const KNOWN_PREFIXES = [
|
|
8130
8150
|
"rounded-tl",
|
|
@@ -8378,8 +8398,7 @@ const noDarkWithoutLight = defineRule({
|
|
|
8378
8398
|
return createExtractorVisitors(context, check);
|
|
8379
8399
|
}
|
|
8380
8400
|
});
|
|
8381
|
-
|
|
8382
|
-
//#region src/utils/color-literal.ts
|
|
8401
|
+
// src/utils/color-literal.ts
|
|
8383
8402
|
/**
|
|
8384
8403
|
* Does this CSS value contain a hardcoded color literal, anywhere in it?
|
|
8385
8404
|
*
|
|
@@ -8503,8 +8522,7 @@ function containsColorLiteral(value) {
|
|
|
8503
8522
|
}
|
|
8504
8523
|
return false;
|
|
8505
8524
|
}
|
|
8506
|
-
|
|
8507
|
-
//#region src/utils/theme-colors.ts
|
|
8525
|
+
// src/utils/theme-colors.ts
|
|
8508
8526
|
/** How many of the project's colors a message names before `(+N more)`. */
|
|
8509
8527
|
const LISTED = 12;
|
|
8510
8528
|
const listed = /* @__PURE__ */ new WeakMap();
|
|
@@ -8523,8 +8541,7 @@ function themeColorList(cache) {
|
|
|
8523
8541
|
}
|
|
8524
8542
|
return list;
|
|
8525
8543
|
}
|
|
8526
|
-
|
|
8527
|
-
//#region src/rules/no-hardcoded-colors.ts
|
|
8544
|
+
// src/rules/no-hardcoded-colors.ts
|
|
8528
8545
|
const VAR_REF_RE = /var\(\s*--[\w-]+/i;
|
|
8529
8546
|
/**
|
|
8530
8547
|
* Does the arbitrary value the user wrote carry a hardcoded colour?
|
|
@@ -8605,8 +8622,7 @@ const noHardcodedColors = defineRule({
|
|
|
8605
8622
|
return createExtractorVisitors(context, check);
|
|
8606
8623
|
}
|
|
8607
8624
|
});
|
|
8608
|
-
|
|
8609
|
-
//#region src/rules/no-contradicting-variants.ts
|
|
8625
|
+
// src/rules/no-contradicting-variants.ts
|
|
8610
8626
|
const STATIC_PROP_GROUPS = /* @__PURE__ */ new Map([
|
|
8611
8627
|
["block", "display"],
|
|
8612
8628
|
["inline-block", "display"],
|
|
@@ -8704,8 +8720,7 @@ const noContradictingVariants = defineRule({
|
|
|
8704
8720
|
return createExtractorVisitors(context, check);
|
|
8705
8721
|
}
|
|
8706
8722
|
});
|
|
8707
|
-
|
|
8708
|
-
//#region src/rules/consistent-variant-order.ts
|
|
8723
|
+
// src/rules/consistent-variant-order.ts
|
|
8709
8724
|
/**
|
|
8710
8725
|
* The order chains are written in, outermost first: where the page is
|
|
8711
8726
|
* (viewport, features, color scheme, container, media type, direction), then
|
|
@@ -8949,8 +8964,7 @@ const consistentVariantOrder = defineRule({
|
|
|
8949
8964
|
return createExtractorVisitors(context, check);
|
|
8950
8965
|
}
|
|
8951
8966
|
});
|
|
8952
|
-
|
|
8953
|
-
//#region src/rules/enforce-consistent-line-wrapping.ts
|
|
8967
|
+
// src/rules/enforce-consistent-line-wrapping.ts
|
|
8954
8968
|
const DEFAULT_PRINT_WIDTH = 80;
|
|
8955
8969
|
const DEFAULT_GROUP = "newLine";
|
|
8956
8970
|
const DEFAULT_WRAP_STRINGS = "never";
|
|
@@ -8959,6 +8973,31 @@ function isJsxAttributeString(loc) {
|
|
|
8959
8973
|
const node = loc.node;
|
|
8960
8974
|
return node.type === "Literal" && node.parent?.type === "JSXAttribute";
|
|
8961
8975
|
}
|
|
8976
|
+
/**
|
|
8977
|
+
* A JS string `wrapStrings: 'all'` turns into a template literal. Its place
|
|
8978
|
+
* takes any expression — a call argument (`cn("…")`), `className={"…"}`, an
|
|
8979
|
+
* array element, an object value, a ternary or `&&` branch, a variable's
|
|
8980
|
+
* initializer — but never an object key or a `+` operand. And a template reads
|
|
8981
|
+
* its text the same way: `raw` is the source between the quotes, so it must
|
|
8982
|
+
* equal the value (no escape sequence, which a template can read differently)
|
|
8983
|
+
* and hold no `` ` `` or `${`.
|
|
8984
|
+
*/
|
|
8985
|
+
function isConvertibleJsString(loc, raw) {
|
|
8986
|
+
const node = loc.node;
|
|
8987
|
+
if (node.type !== "Literal" || raw !== loc.value) return false;
|
|
8988
|
+
if (raw.includes("`") || raw.includes("${")) return false;
|
|
8989
|
+
const parent = node.parent;
|
|
8990
|
+
switch (parent?.type) {
|
|
8991
|
+
case "CallExpression": return parent.arguments?.includes(node) === true;
|
|
8992
|
+
case "Property": return parent.value === node;
|
|
8993
|
+
case "VariableDeclarator": return parent.init === node;
|
|
8994
|
+
case "ConditionalExpression": return parent.test !== node;
|
|
8995
|
+
case "ArrayExpression":
|
|
8996
|
+
case "LogicalExpression":
|
|
8997
|
+
case "JSXExpressionContainer": return true;
|
|
8998
|
+
default: return false;
|
|
8999
|
+
}
|
|
9000
|
+
}
|
|
8962
9001
|
/** One indentation level added below the statement's base indent for wrapped lines. */
|
|
8963
9002
|
const INDENT_UNIT = " ";
|
|
8964
9003
|
/** Group `classes` into chunks of at most `n`, each chunk space-joined. */
|
|
@@ -9042,7 +9081,7 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
9042
9081
|
recommended: false,
|
|
9043
9082
|
designSystem: "optional"
|
|
9044
9083
|
}),
|
|
9045
|
-
fixable: "
|
|
9084
|
+
fixable: "code",
|
|
9046
9085
|
schema: [{
|
|
9047
9086
|
type: "object",
|
|
9048
9087
|
properties: {
|
|
@@ -9063,7 +9102,11 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
9063
9102
|
},
|
|
9064
9103
|
wrapStrings: {
|
|
9065
9104
|
type: "string",
|
|
9066
|
-
enum: [
|
|
9105
|
+
enum: [
|
|
9106
|
+
"never",
|
|
9107
|
+
"jsx",
|
|
9108
|
+
"all"
|
|
9109
|
+
]
|
|
9067
9110
|
}
|
|
9068
9111
|
},
|
|
9069
9112
|
additionalProperties: false
|
|
@@ -9105,10 +9148,10 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
9105
9148
|
return "";
|
|
9106
9149
|
}
|
|
9107
9150
|
/**
|
|
9108
|
-
* The line ending a
|
|
9109
|
-
*
|
|
9110
|
-
*
|
|
9111
|
-
* string ends on.
|
|
9151
|
+
* The line ending a string's fix writes. A JSX attribute keeps the file's
|
|
9152
|
+
* `\r\n` in its value (a template's is LF already), so a CRLF file gets
|
|
9153
|
+
* CRLF breaks: from the value when it has any, else from the line the
|
|
9154
|
+
* string ends on — the only source for a JS string turned into a template.
|
|
9112
9155
|
*/
|
|
9113
9156
|
function lineEndingOf(loc) {
|
|
9114
9157
|
if (loc.value.includes("\r\n")) return "\r\n";
|
|
@@ -9203,15 +9246,19 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
9203
9246
|
const group = getGroup();
|
|
9204
9247
|
const prefix = wrapLines === "all" && group !== "never" && classesPerLine === void 0 ? softGetDS(getDS)?.cache.prefix ?? "" : "";
|
|
9205
9248
|
const wrapStrings = getWrapStrings();
|
|
9249
|
+
const text = wrapStrings === "all" ? safeSourceCode(context)?.text : void 0;
|
|
9206
9250
|
for (const written of locations) {
|
|
9207
|
-
const wrapsString = wrapStrings
|
|
9208
|
-
const
|
|
9209
|
-
const
|
|
9251
|
+
const wrapsString = wrapStrings !== "never" && isJsxAttributeString(written);
|
|
9252
|
+
const convertsString = wrapStrings === "all" && !wrapsString && isConvertibleJsString(written, text?.slice(written.range[0], written.range[1]));
|
|
9253
|
+
const fixable = written.node.type === "TemplateElement" || wrapsString || convertsString;
|
|
9254
|
+
const eol = wrapsString || convertsString ? lineEndingOf(written) : "\n";
|
|
9210
9255
|
const loc = eol === "\n" ? written : {
|
|
9211
9256
|
...written,
|
|
9212
9257
|
value: written.value.replace(/\r\n/g, "\n")
|
|
9213
9258
|
};
|
|
9214
9259
|
const toSource = (value) => eol === "\n" ? value : value.replace(/\n/g, eol);
|
|
9260
|
+
const fixRange = convertsString ? loc.node.range : loc.range;
|
|
9261
|
+
const toFix = (value) => convertsString ? "`" + toSource(value) + "`" : toSource(value);
|
|
9215
9262
|
let maxLine = 0;
|
|
9216
9263
|
for (const line of loc.value.split("\n")) {
|
|
9217
9264
|
if (line.length <= maxLine) continue;
|
|
@@ -9231,7 +9278,7 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
9231
9278
|
messageId: maxLine > printWidth ? "tooLong" : "inconsistentWrapping",
|
|
9232
9279
|
data,
|
|
9233
9280
|
fix(fixer) {
|
|
9234
|
-
return fixer.replaceTextRange(
|
|
9281
|
+
return fixer.replaceTextRange(fixRange, toFix(fixedValue));
|
|
9235
9282
|
}
|
|
9236
9283
|
});
|
|
9237
9284
|
} else if (maxLine > printWidth) context.report({
|
|
@@ -9258,7 +9305,7 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
9258
9305
|
messageId: "tooManyPerLine",
|
|
9259
9306
|
data,
|
|
9260
9307
|
fix(fixer) {
|
|
9261
|
-
return fixer.replaceTextRange(
|
|
9308
|
+
return fixer.replaceTextRange(fixRange, toFix(preserveSpaces(loc, fixedValue)));
|
|
9262
9309
|
}
|
|
9263
9310
|
});
|
|
9264
9311
|
} else context.report({
|
|
@@ -9273,8 +9320,7 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
9273
9320
|
return createExtractorVisitors(context, check, { raw: true });
|
|
9274
9321
|
}
|
|
9275
9322
|
});
|
|
9276
|
-
|
|
9277
|
-
//#region src/rules/no-unnecessary-arbitrary-value.ts
|
|
9323
|
+
// src/rules/no-unnecessary-arbitrary-value.ts
|
|
9278
9324
|
const noUnnecessaryArbitraryValue = defineRule({
|
|
9279
9325
|
meta: {
|
|
9280
9326
|
type: "suggestion",
|
|
@@ -9324,8 +9370,7 @@ const noUnnecessaryArbitraryValue = defineRule({
|
|
|
9324
9370
|
return createExtractorVisitors(context, check);
|
|
9325
9371
|
}
|
|
9326
9372
|
});
|
|
9327
|
-
|
|
9328
|
-
//#region src/rules/prefer-theme-tokens.ts
|
|
9373
|
+
// src/rules/prefer-theme-tokens.ts
|
|
9329
9374
|
/**
|
|
9330
9375
|
* Match `prefix-(--name)` or `prefix-(--name)/modifier`.
|
|
9331
9376
|
* Captures: 1=prefix, 2=variable name, 3=optional `/modifier` (kept verbatim).
|
|
@@ -9407,8 +9452,7 @@ const preferThemeTokens = defineRule({
|
|
|
9407
9452
|
return createExtractorVisitors(context, check);
|
|
9408
9453
|
}
|
|
9409
9454
|
});
|
|
9410
|
-
|
|
9411
|
-
//#region src/rules/prefer-scale-token.ts
|
|
9455
|
+
// src/rules/prefer-scale-token.ts
|
|
9412
9456
|
const preferScaleToken = defineRule({
|
|
9413
9457
|
meta: {
|
|
9414
9458
|
type: "suggestion",
|
|
@@ -9427,7 +9471,8 @@ const preferScaleToken = defineRule({
|
|
|
9427
9471
|
allow: {
|
|
9428
9472
|
type: "array",
|
|
9429
9473
|
items: { type: "string" }
|
|
9430
|
-
}
|
|
9474
|
+
},
|
|
9475
|
+
sameUnit: { type: "boolean" }
|
|
9431
9476
|
},
|
|
9432
9477
|
additionalProperties: false
|
|
9433
9478
|
}],
|
|
@@ -9443,7 +9488,8 @@ const preferScaleToken = defineRule({
|
|
|
9443
9488
|
const getDS = createLazyLoader(context);
|
|
9444
9489
|
const getOptions = createLazyOptions(context, (o) => ({
|
|
9445
9490
|
step: typeof o?.step === "number" ? o.step : null,
|
|
9446
|
-
allow: o?.allow ?? []
|
|
9491
|
+
allow: o?.allow ?? [],
|
|
9492
|
+
sameUnit: o?.sameUnit === true
|
|
9447
9493
|
}));
|
|
9448
9494
|
const rootFontSize = createLazySettings(context, rootFontSizeFromSettings);
|
|
9449
9495
|
/**
|
|
@@ -9455,7 +9501,7 @@ const preferScaleToken = defineRule({
|
|
|
9455
9501
|
* from the design system, so neither is a name table.
|
|
9456
9502
|
*/
|
|
9457
9503
|
function equivalentOf(cache, bare) {
|
|
9458
|
-
const { step: stepOverride, allow } = getOptions();
|
|
9504
|
+
const { step: stepOverride, allow, sameUnit } = getOptions();
|
|
9459
9505
|
if (allow.some((prefix) => bare.startsWith(prefix))) return null;
|
|
9460
9506
|
if (cache.getNamedEquivalent(bare)) return null;
|
|
9461
9507
|
const value = getArbitraryValue(bare);
|
|
@@ -9464,15 +9510,21 @@ const preferScaleToken = defineRule({
|
|
|
9464
9510
|
if (written === null) return null;
|
|
9465
9511
|
const prefix = arbitraryPrefix(bare);
|
|
9466
9512
|
if (!prefix) return null;
|
|
9513
|
+
const writtenUnit = lengthUnit(value);
|
|
9514
|
+
const unitAllowed = (literal) => {
|
|
9515
|
+
const unit = lengthUnit(literal);
|
|
9516
|
+
return sameUnit ? unit === writtenUnit : unit === "em" === (writtenUnit === "em");
|
|
9517
|
+
};
|
|
9467
9518
|
for (const [literal, className] of cache.tokenValuesFor(prefix)) {
|
|
9468
9519
|
const token = measure(literal, rootFontSize());
|
|
9469
|
-
if (token !== null && sameMeasure(written, token)) return className;
|
|
9520
|
+
if (token !== null && sameMeasure(written, token) && unitAllowed(literal)) return className;
|
|
9470
9521
|
}
|
|
9471
9522
|
if (!cache.readsScale(prefix)) return null;
|
|
9472
9523
|
const scale = cache.scale;
|
|
9473
9524
|
if (!scale) return null;
|
|
9474
9525
|
const unit = measure(scale.unit, rootFontSize());
|
|
9475
9526
|
if (unit === null || unit.px <= 0 || unit.unitless !== written.unitless) return null;
|
|
9527
|
+
if (!unitAllowed(scale.unit)) return null;
|
|
9476
9528
|
const steps = written.px / unit.px;
|
|
9477
9529
|
if (steps < 0) return null;
|
|
9478
9530
|
if (!isOnStep(steps, stepOverride ?? scale.step)) return null;
|
|
@@ -9509,8 +9561,7 @@ const preferScaleToken = defineRule({
|
|
|
9509
9561
|
return createExtractorVisitors(context, check);
|
|
9510
9562
|
}
|
|
9511
9563
|
});
|
|
9512
|
-
|
|
9513
|
-
//#region src/rules/no-dynamic-classes.ts
|
|
9564
|
+
// src/rules/no-dynamic-classes.ts
|
|
9514
9565
|
const STATIC_UTILITY_ROOTS = [
|
|
9515
9566
|
"@container",
|
|
9516
9567
|
"accent",
|
|
@@ -9858,8 +9909,7 @@ const noDynamicClasses = defineRule({
|
|
|
9858
9909
|
return createExtractorVisitors(context, check, { raw: true });
|
|
9859
9910
|
}
|
|
9860
9911
|
});
|
|
9861
|
-
|
|
9862
|
-
//#region src/rules/no-default-palette.ts
|
|
9912
|
+
// src/rules/no-default-palette.ts
|
|
9863
9913
|
const COLOR_VAR = "--color-";
|
|
9864
9914
|
/** `white`, `gray-*` → a test on palette color names. */
|
|
9865
9915
|
function compileAllow(allow) {
|
|
@@ -9934,8 +9984,7 @@ const noDefaultPalette = defineRule({
|
|
|
9934
9984
|
return createExtractorVisitors(context, check);
|
|
9935
9985
|
}
|
|
9936
9986
|
});
|
|
9937
|
-
|
|
9938
|
-
//#region src/utils/component-scanner.ts
|
|
9987
|
+
// src/utils/component-scanner.ts
|
|
9939
9988
|
const PUNCT = /* @__PURE__ */ new Set([
|
|
9940
9989
|
"(",
|
|
9941
9990
|
")",
|
|
@@ -10300,8 +10349,7 @@ function rootClasses(p, start, end, definitions) {
|
|
|
10300
10349
|
};
|
|
10301
10350
|
}
|
|
10302
10351
|
}
|
|
10303
|
-
|
|
10304
|
-
//#region src/utils/style-signature.ts
|
|
10352
|
+
// src/utils/style-signature.ts
|
|
10305
10353
|
/**
|
|
10306
10354
|
* Where the element sits and how it lays out its children — which a copy
|
|
10307
10355
|
* adapts to its page — rather than what it looks like.
|
|
@@ -10527,8 +10575,7 @@ function resemblance(component, element) {
|
|
|
10527
10575
|
sharedSurface
|
|
10528
10576
|
};
|
|
10529
10577
|
}
|
|
10530
|
-
|
|
10531
|
-
//#region src/rules/no-borrowed-component-styles.ts
|
|
10578
|
+
// src/rules/no-borrowed-component-styles.ts
|
|
10532
10579
|
/** Fewer shared declarations than this is a coincidence, not a copy. */
|
|
10533
10580
|
const MIN_SHARED = 4;
|
|
10534
10581
|
/** Shared declarations over all the declarations either side sets. */
|
|
@@ -10630,8 +10677,7 @@ function nativeTag(attribute) {
|
|
|
10630
10677
|
if (element?.type !== "JSXOpeningElement" || element.name.type !== "JSXIdentifier") return null;
|
|
10631
10678
|
return /^[a-z]/.test(element.name.name) ? element.name : null;
|
|
10632
10679
|
}
|
|
10633
|
-
|
|
10634
|
-
//#region src/index.ts
|
|
10680
|
+
// src/index.ts
|
|
10635
10681
|
const plugin = definePlugin({
|
|
10636
10682
|
meta: { name: "tailwindcss" },
|
|
10637
10683
|
rules: {
|
|
@@ -10753,5 +10799,4 @@ const plugin = definePlugin({
|
|
|
10753
10799
|
})
|
|
10754
10800
|
}
|
|
10755
10801
|
});
|
|
10756
|
-
//#endregion
|
|
10757
10802
|
export { plugin as default };
|