oxlint-tailwindcss 1.17.1 → 1.17.3
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.d.cts +28 -0
- package/dist/config.d.mts +28 -0
- package/dist/index.cjs +104 -26
- package/dist/index.mjs +104 -26
- package/package.json +5 -5
package/dist/config.d.cts
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `oxlint-tailwindcss/config`: the plugin and its recommended rules as an
|
|
3
|
+
* oxlint config object, for `extends` in an `oxlint.config.ts` and in the
|
|
4
|
+
* shared configs that compose it (#218).
|
|
5
|
+
*
|
|
6
|
+
* import tailwindcss from 'oxlint-tailwindcss/config'
|
|
7
|
+
* export default defineConfig({
|
|
8
|
+
* extends: [tailwindcss()],
|
|
9
|
+
* settings: { tailwindcss: { entryPoint: 'src/styles.css' } },
|
|
10
|
+
* })
|
|
11
|
+
*
|
|
12
|
+
* A config that reaches oxlint through `extends` can't register its JS plugin
|
|
13
|
+
* by package name: oxlint resolves `"oxlint-tailwindcss"` from the project,
|
|
14
|
+
* where a shared config's own dependency isn't installed under pnpm, and it
|
|
15
|
+
* rejects a relative specifier there outright. This module knows where the
|
|
16
|
+
* plugin is — its sibling `index.mjs`, the file the bare name resolves to, so
|
|
17
|
+
* a project that also lists the name registers the same plugin — and hands
|
|
18
|
+
* oxlint that absolute path.
|
|
19
|
+
*
|
|
20
|
+
* It carries no settings, on purpose: oxlint never takes `settings` from an
|
|
21
|
+
* extended config (JSON or TS), so an `entryPoint` passed through here would be
|
|
22
|
+
* dropped in silence. The settings stay in the config that is linted with.
|
|
23
|
+
*
|
|
24
|
+
* It imports nothing at runtime from the plugin: the entry stays a few lines,
|
|
25
|
+
* the build keeps `dist/index.cjs` a single `module.exports = plugin`, and the
|
|
26
|
+
* recommended severities come from a static map a test holds equal to the
|
|
27
|
+
* rules' own metadata.
|
|
28
|
+
*/
|
|
1
29
|
interface ExtractorExclusions {
|
|
2
30
|
/** Default attribute names to exclude */
|
|
3
31
|
attributes?: string[];
|
package/dist/config.d.mts
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `oxlint-tailwindcss/config`: the plugin and its recommended rules as an
|
|
3
|
+
* oxlint config object, for `extends` in an `oxlint.config.ts` and in the
|
|
4
|
+
* shared configs that compose it (#218).
|
|
5
|
+
*
|
|
6
|
+
* import tailwindcss from 'oxlint-tailwindcss/config'
|
|
7
|
+
* export default defineConfig({
|
|
8
|
+
* extends: [tailwindcss()],
|
|
9
|
+
* settings: { tailwindcss: { entryPoint: 'src/styles.css' } },
|
|
10
|
+
* })
|
|
11
|
+
*
|
|
12
|
+
* A config that reaches oxlint through `extends` can't register its JS plugin
|
|
13
|
+
* by package name: oxlint resolves `"oxlint-tailwindcss"` from the project,
|
|
14
|
+
* where a shared config's own dependency isn't installed under pnpm, and it
|
|
15
|
+
* rejects a relative specifier there outright. This module knows where the
|
|
16
|
+
* plugin is — its sibling `index.mjs`, the file the bare name resolves to, so
|
|
17
|
+
* a project that also lists the name registers the same plugin — and hands
|
|
18
|
+
* oxlint that absolute path.
|
|
19
|
+
*
|
|
20
|
+
* It carries no settings, on purpose: oxlint never takes `settings` from an
|
|
21
|
+
* extended config (JSON or TS), so an `entryPoint` passed through here would be
|
|
22
|
+
* dropped in silence. The settings stay in the config that is linted with.
|
|
23
|
+
*
|
|
24
|
+
* It imports nothing at runtime from the plugin: the entry stays a few lines,
|
|
25
|
+
* the build keeps `dist/index.cjs` a single `module.exports = plugin`, and the
|
|
26
|
+
* recommended severities come from a static map a test holds equal to the
|
|
27
|
+
* rules' own metadata.
|
|
28
|
+
*/
|
|
1
29
|
interface ExtractorExclusions {
|
|
2
30
|
/** Default attribute names to exclude */
|
|
3
31
|
attributes?: string[];
|
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,7 @@ let node_crypto = require("node:crypto");
|
|
|
4
4
|
let node_fs = require("node:fs");
|
|
5
5
|
let node_path = require("node:path");
|
|
6
6
|
let node_os = require("node:os");
|
|
7
|
-
// ../../node_modules/.pnpm/@oxlint+plugins@1.
|
|
7
|
+
// ../../node_modules/.pnpm/@oxlint+plugins@1.93.0/node_modules/@oxlint/plugins/index.js
|
|
8
8
|
/**
|
|
9
9
|
* Define a plugin.
|
|
10
10
|
*
|
|
@@ -376,7 +376,7 @@ let bufC = /* @__PURE__ */ new Int32Array(64);
|
|
|
376
376
|
* value greater than `max`. Every cell is at most the one above it plus 1, so
|
|
377
377
|
* once a whole row is past `max`, every later row is too.
|
|
378
378
|
*/
|
|
379
|
-
function levenshtein(a, b, max =
|
|
379
|
+
function levenshtein(a, b, max = 1e400) {
|
|
380
380
|
if (a.length === 0) return b.length;
|
|
381
381
|
if (b.length === 0) return a.length;
|
|
382
382
|
const n = b.length;
|
|
@@ -568,7 +568,7 @@ function reportSettingsProblems(context, program) {
|
|
|
568
568
|
* the single home for that decision so it can't drift between them.
|
|
569
569
|
*/
|
|
570
570
|
function isFinalClassList(loc) {
|
|
571
|
-
return loc.origin === "jsx-native";
|
|
571
|
+
return loc.origin === "jsx-native" && loc.partial !== true;
|
|
572
572
|
}
|
|
573
573
|
/**
|
|
574
574
|
* Preserves leading/trailing spaces in fixed class strings for template literals.
|
|
@@ -1024,6 +1024,7 @@ function extractLookupTable(node, out = []) {
|
|
|
1024
1024
|
* receive a fresh array.
|
|
1025
1025
|
*/
|
|
1026
1026
|
function extractFromExpression(node, out = []) {
|
|
1027
|
+
while (node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" || node.type === "TSNonNullExpression" || node.type === "TSTypeAssertion") node = node.expression;
|
|
1027
1028
|
if (node.type === "Literal" && typeof node.value === "string") {
|
|
1028
1029
|
out.push({
|
|
1029
1030
|
value: node.value,
|
|
@@ -1081,9 +1082,22 @@ function isStyleDeclaration(key, value) {
|
|
|
1081
1082
|
if (CUSTOM_PROPERTY.test(key) || VENDOR_PROPERTY.test(key) || CSS_PROPERTY_NAMES.has(key)) return true;
|
|
1082
1083
|
return value.type === "TemplateLiteral" || value.type === "Literal" && (typeof value.value === "string" || typeof value.value === "number");
|
|
1083
1084
|
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Every quasi of a template, and the classes in each `${}` between them (#259):
|
|
1087
|
+
* `` `flex ${ok ? "bg-green-500" : "bg-brand"}` `` holds three. The strings in
|
|
1088
|
+
* an expression are read like the operands of a `+` concatenation: glued to a
|
|
1089
|
+
* neighbouring quasi that doesn't end (or start) with whitespace, or to an
|
|
1090
|
+
* adjacent expression, and a glued last token carries its `runtimeClass`
|
|
1091
|
+
* (`${big ? "p" : "m"}-${size}` → `p-${size}`). A template with an expression
|
|
1092
|
+
* is one class list assembled at runtime, so every piece of it is `partial`.
|
|
1093
|
+
*/
|
|
1084
1094
|
function appendFromTemplateLiteral(node, out) {
|
|
1085
|
-
|
|
1086
|
-
|
|
1095
|
+
const { quasis, expressions } = node;
|
|
1096
|
+
const partial = expressions.length > 0 ? true : void 0;
|
|
1097
|
+
let operands = null;
|
|
1098
|
+
let strings = null;
|
|
1099
|
+
for (let i = 0; i < quasis.length; i++) {
|
|
1100
|
+
const quasi = quasis[i];
|
|
1087
1101
|
const value = quasi.value.raw;
|
|
1088
1102
|
if (value.trim().length > 0) {
|
|
1089
1103
|
const start = quasi.range[0] + 1;
|
|
@@ -1092,10 +1106,41 @@ function appendFromTemplateLiteral(node, out) {
|
|
|
1092
1106
|
node: quasi,
|
|
1093
1107
|
range: [start, start + value.length],
|
|
1094
1108
|
preserveLeadingSpace: i > 0,
|
|
1095
|
-
preserveTrailingSpace: i <
|
|
1096
|
-
templateLine: node.loc?.start.line
|
|
1109
|
+
preserveTrailingSpace: i < quasis.length - 1,
|
|
1110
|
+
templateLine: node.loc?.start.line,
|
|
1111
|
+
partial
|
|
1097
1112
|
});
|
|
1098
1113
|
}
|
|
1114
|
+
if (i >= expressions.length) continue;
|
|
1115
|
+
const inner = extractFromExpression(expressions[i], []);
|
|
1116
|
+
if (inner.length === 0) continue;
|
|
1117
|
+
const before = value;
|
|
1118
|
+
const after = quasis[i + 1].value.raw;
|
|
1119
|
+
const glueBefore = before.length > 0 ? !/\s$/.test(before) : i > 0;
|
|
1120
|
+
const glueAfter = after.length > 0 ? !/^\s/.test(after) : i + 1 < expressions.length;
|
|
1121
|
+
for (const loc of inner) {
|
|
1122
|
+
loc.partial = true;
|
|
1123
|
+
if (glueBefore) loc.preserveLeadingSpace = true;
|
|
1124
|
+
if (glueAfter) {
|
|
1125
|
+
loc.preserveTrailingSpace = true;
|
|
1126
|
+
if (!/\s$/.test(loc.value)) {
|
|
1127
|
+
if (!operands || !strings) {
|
|
1128
|
+
operands = [];
|
|
1129
|
+
strings = [];
|
|
1130
|
+
for (let j = 0; j < quasis.length; j++) {
|
|
1131
|
+
operands.push(quasis[j]);
|
|
1132
|
+
strings.push(quasis[j].value.raw);
|
|
1133
|
+
if (j < expressions.length) {
|
|
1134
|
+
operands.push(expressions[j]);
|
|
1135
|
+
strings.push(void 0);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
loc.runtimeClass ??= runtimeClass(loc.value, operands, strings, 2 * i + 1);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
out.push(loc);
|
|
1143
|
+
}
|
|
1099
1144
|
}
|
|
1100
1145
|
return out;
|
|
1101
1146
|
}
|
|
@@ -1141,6 +1186,7 @@ function appendFromConcatenation(node, out) {
|
|
|
1141
1186
|
if (value === void 0) {
|
|
1142
1187
|
const inner = extractFromExpression(operands[i], []);
|
|
1143
1188
|
for (const loc of inner) {
|
|
1189
|
+
loc.partial = true;
|
|
1144
1190
|
if (glueBefore) loc.preserveLeadingSpace = true;
|
|
1145
1191
|
if (glueAfter) {
|
|
1146
1192
|
loc.preserveTrailingSpace = true;
|
|
@@ -1157,7 +1203,8 @@ function appendFromConcatenation(node, out) {
|
|
|
1157
1203
|
node: operand,
|
|
1158
1204
|
range: [operand.range[0] + 1, operand.range[1] - 1],
|
|
1159
1205
|
preserveLeadingSpace: glueBefore,
|
|
1160
|
-
preserveTrailingSpace: glueAfter
|
|
1206
|
+
preserveTrailingSpace: glueAfter,
|
|
1207
|
+
partial: true
|
|
1161
1208
|
};
|
|
1162
1209
|
if (glueAfter && !/\s$/.test(value)) loc.runtimeClass = runtimeClass(value, operands, strings, i);
|
|
1163
1210
|
out.push(loc);
|
|
@@ -1899,6 +1946,13 @@ const DYNAMIC_NUMERIC_RE = /^(.+)-\d+\.?\d*$/;
|
|
|
1899
1946
|
* `from-33.5%`, so a decimal here would be tolerance with nothing behind it.
|
|
1900
1947
|
*/
|
|
1901
1948
|
const DYNAMIC_PERCENT_RE = /^(.+)-\d+%$/;
|
|
1949
|
+
/** `--color-red-500` (or `--tw-color-red-500` under `prefix(tw)`) → `red-500`. */
|
|
1950
|
+
function colorNameOf(varName, prefix) {
|
|
1951
|
+
if (varName.startsWith("--color-")) return varName.slice(8);
|
|
1952
|
+
if (prefix === "") return null;
|
|
1953
|
+
const namespace = `--${prefix}-color-`;
|
|
1954
|
+
return varName.startsWith(namespace) ? varName.slice(namespace.length) : null;
|
|
1955
|
+
}
|
|
1902
1956
|
var DesignSystemCache = class DesignSystemCache {
|
|
1903
1957
|
canonicalMap = /* @__PURE__ */ new Map();
|
|
1904
1958
|
deprecatedMap = /* @__PURE__ */ new Map();
|
|
@@ -1954,7 +2008,7 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
1954
2008
|
}
|
|
1955
2009
|
for (const name of data.definedVars ?? []) cache.definedVarSet.add(name);
|
|
1956
2010
|
for (const name of data.paletteVars ?? []) cache.paletteVarSet.add(name);
|
|
1957
|
-
cache.projectColorNames = (data.projectColorVars ?? []).map((name) => name.
|
|
2011
|
+
cache.projectColorNames = (data.projectColorVars ?? []).map((name) => colorNameOf(name, data.prefix ?? "") ?? name).sort((a, b) => a.localeCompare(b));
|
|
1958
2012
|
if (data.themeRefs) for (const [name, refs] of Object.entries(data.themeRefs)) cache.themeRefs.set(name, refs);
|
|
1959
2013
|
for (const [prefix, entries] of Object.entries(data.tokenValues ?? {})) cache.tokenValuesMap.set(prefix, entries);
|
|
1960
2014
|
if (data.scale) cache.scaleFacts = {
|
|
@@ -2412,6 +2466,14 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
2412
2466
|
isPaletteVar(varName) {
|
|
2413
2467
|
return this.paletteVarSet.has(varName);
|
|
2414
2468
|
}
|
|
2469
|
+
/**
|
|
2470
|
+
* The color a theme color variable names (`--color-red-500` → `red-500`), or
|
|
2471
|
+
* `null` for any other variable. Under a project prefix the theme's colors are
|
|
2472
|
+
* `--tw-color-*` (#253), and both spellings are accepted.
|
|
2473
|
+
*/
|
|
2474
|
+
themeColorName(varName) {
|
|
2475
|
+
return colorNameOf(varName, this._prefix);
|
|
2476
|
+
}
|
|
2415
2477
|
/** The colors the project's theme declares, by name (`brand`, `primary`), sorted. */
|
|
2416
2478
|
projectColors() {
|
|
2417
2479
|
return this.projectColorNames;
|
|
@@ -3521,10 +3583,11 @@ async function main() {
|
|
|
3521
3583
|
//
|
|
3522
3584
|
// Functional variants (\`group-*\`, \`peer-*\`, \`data-*\`, \`nth-*\`) are skipped:
|
|
3523
3585
|
// probing them would need a value, and none of them retargets the selector.
|
|
3524
|
-
// Measured in Tailwind 4.3.
|
|
3525
|
-
//
|
|
3526
|
-
//
|
|
3527
|
-
//
|
|
3586
|
+
// Measured in Tailwind 4.3.5: \`group-hover\`/\`peer-checked\` compile to
|
|
3587
|
+
// \`:is(:where(.group):hover .x)\` (since tailwindlabs/tailwindcss#20513; 4.3.3
|
|
3588
|
+
// printed \`&:is(:where(.group):hover *)\`) — either way a condition on the
|
|
3589
|
+
// element itself — so two of them in either order produce equivalent selectors
|
|
3590
|
+
// and neither is a reordering barrier.
|
|
3528
3591
|
const variantFacts = {};
|
|
3529
3592
|
const probeNames = [];
|
|
3530
3593
|
for (let i = 0; i < variants.length; i++) {
|
|
@@ -3596,13 +3659,15 @@ async function main() {
|
|
|
3596
3659
|
// Tailwind's default palette (\`@theme default\`, theme option DEFAULT = 4)
|
|
3597
3660
|
// apart from the colors the project declares, for no-default-palette. A
|
|
3598
3661
|
// project that redefines a palette color owns it: its entry loses the flag.
|
|
3662
|
+
// Under a prefix the theme names them \`--tw-color-*\`, as the CSS reads them (#253).
|
|
3599
3663
|
const paletteVars = [];
|
|
3600
3664
|
const projectColorVars = [];
|
|
3665
|
+
const colorNamespace = prefix ? '--' + prefix + '-color-' : '--color-';
|
|
3601
3666
|
if (ds.theme && typeof ds.theme.entries === 'function') {
|
|
3602
3667
|
for (const [name, entry] of ds.theme.entries()) {
|
|
3603
3668
|
const value = entry && typeof entry.value === 'string' ? entry.value : '';
|
|
3604
3669
|
themeValues.set(name, value);
|
|
3605
|
-
if (name.startsWith(
|
|
3670
|
+
if (name.startsWith(colorNamespace)) {
|
|
3606
3671
|
if (entry && (entry.options & 4)) paletteVars.push(name);
|
|
3607
3672
|
else projectColorVars.push(name);
|
|
3608
3673
|
}
|
|
@@ -4587,7 +4652,10 @@ async function main() {
|
|
|
4587
4652
|
const handler = ${handlerExpr};
|
|
4588
4653
|
|
|
4589
4654
|
while (true) {
|
|
4590
|
-
|
|
4655
|
+
// Wait on the flag, not on the wake-up: the host's \`notify\` is a separate
|
|
4656
|
+
// step from its \`store\`, so a late one can land on this wait after the
|
|
4657
|
+
// request it announced was already served (#251).
|
|
4658
|
+
while (Atomics.load(control, 0) === 0) Atomics.wait(control, 0, 0);
|
|
4591
4659
|
const len = lengthView.getUint32(0);
|
|
4592
4660
|
const requestStr = Buffer.from(dataArea.slice(0, len)).toString('utf-8');
|
|
4593
4661
|
Atomics.store(control, 0, 0);
|
|
@@ -4777,7 +4845,16 @@ var DesignSystemWorker = class {
|
|
|
4777
4845
|
state.lengthView.setUint32(0, requestBytes.length);
|
|
4778
4846
|
Atomics.store(state.controlArray, 0, 1);
|
|
4779
4847
|
Atomics.notify(state.controlArray, 0);
|
|
4780
|
-
|
|
4848
|
+
const deadline = Date.now() + this.requestTimeoutMs;
|
|
4849
|
+
let timedOut = false;
|
|
4850
|
+
while (Atomics.load(state.controlArray, 1) === 0) {
|
|
4851
|
+
const left = deadline - Date.now();
|
|
4852
|
+
if (left <= 0 || Atomics.wait(state.controlArray, 1, 0, left) === "timed-out") {
|
|
4853
|
+
timedOut = Atomics.load(state.controlArray, 1) === 0;
|
|
4854
|
+
break;
|
|
4855
|
+
}
|
|
4856
|
+
}
|
|
4857
|
+
if (timedOut) throw this.failRequest(cssPath, new SortServiceError(`${this.opts.serviceName} worker request timed out after ${this.requestTimeoutMs}ms.`, "A slow machine or CI runner can cause this. If the class lists are valid, raise OXLINT_TAILWINDCSS_WORKER_REQUEST_TIMEOUT; otherwise please open an issue."));
|
|
4781
4858
|
const responseLen = state.lengthView.getUint32(0);
|
|
4782
4859
|
const responseStr = Buffer.from(state.dataArea.slice(0, responseLen)).toString("utf-8");
|
|
4783
4860
|
Atomics.store(state.controlArray, 1, 0);
|
|
@@ -5342,7 +5419,7 @@ function resolveByGlobMapping(mappings, filePath, baseDir) {
|
|
|
5342
5419
|
}
|
|
5343
5420
|
/**
|
|
5344
5421
|
* oxlint discovers nested configuration by walking up from each linted file
|
|
5345
|
-
* looking for files with these names (oxlint 1.
|
|
5422
|
+
* looking for files with these names (oxlint 1.93: JSON, JSONC, and the JS
|
|
5346
5423
|
* configs it loads through Node). We mirror that walk to find the config
|
|
5347
5424
|
* directory a relative `entryPoint` should be anchored to — which is also
|
|
5348
5425
|
* where an `oxlint.config.ts` passes it through `oxlint-tailwindcss/config`.
|
|
@@ -8284,16 +8361,16 @@ function withoutVarGroups(value) {
|
|
|
8284
8361
|
}
|
|
8285
8362
|
/**
|
|
8286
8363
|
* The colour property a class sets, read from the CSS it emits — a colour
|
|
8287
|
-
* property, a read of a `--color-*` theme variable
|
|
8288
|
-
* null when it sets none. Descendant and pseudo-element declarations count
|
|
8364
|
+
* property, a read of a `--color-*` theme variable (`--tw-color-*` under a
|
|
8365
|
+
* prefix, #253), or a colour literal — or null when it sets none. Descendant and pseudo-element declarations count
|
|
8289
8366
|
* (`divide-*`, `placeholder-*` colour other boxes); `@media`-conditional ones
|
|
8290
8367
|
* don't.
|
|
8291
8368
|
*/
|
|
8292
|
-
function colorPropertyOf(decls) {
|
|
8369
|
+
function colorPropertyOf(decls, cache) {
|
|
8293
8370
|
const own = decls.filter((d) => !d.conditional);
|
|
8294
8371
|
for (const d of own) if (COLOR_PROPERTY.test(d.prop)) return d.prop;
|
|
8295
8372
|
for (const d of own) {
|
|
8296
|
-
if (d.readsVars.some((v) =>
|
|
8373
|
+
if (d.readsVars.some((v) => cache.themeColorName(v) !== null)) return d.prop;
|
|
8297
8374
|
if (COLOR_LITERAL.test(withoutVarGroups(d.value))) return d.prop;
|
|
8298
8375
|
}
|
|
8299
8376
|
return null;
|
|
@@ -8411,8 +8488,8 @@ const noDarkWithoutLight = defineRule({
|
|
|
8411
8488
|
if (variant !== void 0) {
|
|
8412
8489
|
const decls = cache ? cache.getCssDeclarations(bare) : [];
|
|
8413
8490
|
let colorProperty;
|
|
8414
|
-
if (decls.length > 0) {
|
|
8415
|
-
const found = colorPropertyOf(decls);
|
|
8491
|
+
if (cache && decls.length > 0) {
|
|
8492
|
+
const found = colorPropertyOf(decls, cache);
|
|
8416
8493
|
if (found === null) continue;
|
|
8417
8494
|
colorProperty = found;
|
|
8418
8495
|
} else if (isNeverColorStatic(bare)) continue;
|
|
@@ -9966,7 +10043,8 @@ const noDynamicClasses = defineRule({
|
|
|
9966
10043
|
}
|
|
9967
10044
|
});
|
|
9968
10045
|
// src/rules/no-default-palette.ts
|
|
9969
|
-
|
|
10046
|
+
/** An arbitrary value reading a theme color: `var(--color-…)`, or `var(--tw-color-…)` under a prefix. */
|
|
10047
|
+
const COLOR_VAR_READ = /var\(--(?:[a-z0-9]+-)?color-/;
|
|
9970
10048
|
/** `white`, `gray-*` → a test on palette color names. */
|
|
9971
10049
|
function compileAllow(allow) {
|
|
9972
10050
|
const exact = new Set(allow.filter((a) => !a.endsWith("*")));
|
|
@@ -9978,11 +10056,11 @@ function paletteColorOf(cls, cache, entryPoint) {
|
|
|
9978
10056
|
const { bare } = splitImportant(splitUtilityAndVariant(cls).utility);
|
|
9979
10057
|
const base = bare.replace(/\/[^/\]]+$/, "");
|
|
9980
10058
|
let decls = cache.getCssDeclarations(base);
|
|
9981
|
-
if (decls.length === 0 &&
|
|
10059
|
+
if (decls.length === 0 && COLOR_VAR_READ.test(base)) {
|
|
9982
10060
|
resolveDeclarationsSync(entryPoint, cache, [base]);
|
|
9983
10061
|
decls = cache.getCssDeclarations(base);
|
|
9984
10062
|
}
|
|
9985
|
-
for (const decl of decls) for (const read of decl.readsVars) if (cache.isPaletteVar(read)) return
|
|
10063
|
+
for (const decl of decls) for (const read of decl.readsVars) if (cache.isPaletteVar(read)) return cache.themeColorName(read);
|
|
9986
10064
|
return null;
|
|
9987
10065
|
}
|
|
9988
10066
|
const noDefaultPalette = defineRule({
|
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { dirname, extname, 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
|
-
// ../../node_modules/.pnpm/@oxlint+plugins@1.
|
|
9
|
+
// ../../node_modules/.pnpm/@oxlint+plugins@1.93.0/node_modules/@oxlint/plugins/index.js
|
|
10
10
|
/**
|
|
11
11
|
* Define a plugin.
|
|
12
12
|
*
|
|
@@ -378,7 +378,7 @@ let bufC = /* @__PURE__ */ new Int32Array(64);
|
|
|
378
378
|
* value greater than `max`. Every cell is at most the one above it plus 1, so
|
|
379
379
|
* once a whole row is past `max`, every later row is too.
|
|
380
380
|
*/
|
|
381
|
-
function levenshtein(a, b, max =
|
|
381
|
+
function levenshtein(a, b, max = 1e400) {
|
|
382
382
|
if (a.length === 0) return b.length;
|
|
383
383
|
if (b.length === 0) return a.length;
|
|
384
384
|
const n = b.length;
|
|
@@ -570,7 +570,7 @@ function reportSettingsProblems(context, program) {
|
|
|
570
570
|
* the single home for that decision so it can't drift between them.
|
|
571
571
|
*/
|
|
572
572
|
function isFinalClassList(loc) {
|
|
573
|
-
return loc.origin === "jsx-native";
|
|
573
|
+
return loc.origin === "jsx-native" && loc.partial !== true;
|
|
574
574
|
}
|
|
575
575
|
/**
|
|
576
576
|
* Preserves leading/trailing spaces in fixed class strings for template literals.
|
|
@@ -1026,6 +1026,7 @@ function extractLookupTable(node, out = []) {
|
|
|
1026
1026
|
* receive a fresh array.
|
|
1027
1027
|
*/
|
|
1028
1028
|
function extractFromExpression(node, out = []) {
|
|
1029
|
+
while (node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression" || node.type === "TSNonNullExpression" || node.type === "TSTypeAssertion") node = node.expression;
|
|
1029
1030
|
if (node.type === "Literal" && typeof node.value === "string") {
|
|
1030
1031
|
out.push({
|
|
1031
1032
|
value: node.value,
|
|
@@ -1083,9 +1084,22 @@ function isStyleDeclaration(key, value) {
|
|
|
1083
1084
|
if (CUSTOM_PROPERTY.test(key) || VENDOR_PROPERTY.test(key) || CSS_PROPERTY_NAMES.has(key)) return true;
|
|
1084
1085
|
return value.type === "TemplateLiteral" || value.type === "Literal" && (typeof value.value === "string" || typeof value.value === "number");
|
|
1085
1086
|
}
|
|
1087
|
+
/**
|
|
1088
|
+
* Every quasi of a template, and the classes in each `${}` between them (#259):
|
|
1089
|
+
* `` `flex ${ok ? "bg-green-500" : "bg-brand"}` `` holds three. The strings in
|
|
1090
|
+
* an expression are read like the operands of a `+` concatenation: glued to a
|
|
1091
|
+
* neighbouring quasi that doesn't end (or start) with whitespace, or to an
|
|
1092
|
+
* adjacent expression, and a glued last token carries its `runtimeClass`
|
|
1093
|
+
* (`${big ? "p" : "m"}-${size}` → `p-${size}`). A template with an expression
|
|
1094
|
+
* is one class list assembled at runtime, so every piece of it is `partial`.
|
|
1095
|
+
*/
|
|
1086
1096
|
function appendFromTemplateLiteral(node, out) {
|
|
1087
|
-
|
|
1088
|
-
|
|
1097
|
+
const { quasis, expressions } = node;
|
|
1098
|
+
const partial = expressions.length > 0 ? true : void 0;
|
|
1099
|
+
let operands = null;
|
|
1100
|
+
let strings = null;
|
|
1101
|
+
for (let i = 0; i < quasis.length; i++) {
|
|
1102
|
+
const quasi = quasis[i];
|
|
1089
1103
|
const value = quasi.value.raw;
|
|
1090
1104
|
if (value.trim().length > 0) {
|
|
1091
1105
|
const start = quasi.range[0] + 1;
|
|
@@ -1094,10 +1108,41 @@ function appendFromTemplateLiteral(node, out) {
|
|
|
1094
1108
|
node: quasi,
|
|
1095
1109
|
range: [start, start + value.length],
|
|
1096
1110
|
preserveLeadingSpace: i > 0,
|
|
1097
|
-
preserveTrailingSpace: i <
|
|
1098
|
-
templateLine: node.loc?.start.line
|
|
1111
|
+
preserveTrailingSpace: i < quasis.length - 1,
|
|
1112
|
+
templateLine: node.loc?.start.line,
|
|
1113
|
+
partial
|
|
1099
1114
|
});
|
|
1100
1115
|
}
|
|
1116
|
+
if (i >= expressions.length) continue;
|
|
1117
|
+
const inner = extractFromExpression(expressions[i], []);
|
|
1118
|
+
if (inner.length === 0) continue;
|
|
1119
|
+
const before = value;
|
|
1120
|
+
const after = quasis[i + 1].value.raw;
|
|
1121
|
+
const glueBefore = before.length > 0 ? !/\s$/.test(before) : i > 0;
|
|
1122
|
+
const glueAfter = after.length > 0 ? !/^\s/.test(after) : i + 1 < expressions.length;
|
|
1123
|
+
for (const loc of inner) {
|
|
1124
|
+
loc.partial = true;
|
|
1125
|
+
if (glueBefore) loc.preserveLeadingSpace = true;
|
|
1126
|
+
if (glueAfter) {
|
|
1127
|
+
loc.preserveTrailingSpace = true;
|
|
1128
|
+
if (!/\s$/.test(loc.value)) {
|
|
1129
|
+
if (!operands || !strings) {
|
|
1130
|
+
operands = [];
|
|
1131
|
+
strings = [];
|
|
1132
|
+
for (let j = 0; j < quasis.length; j++) {
|
|
1133
|
+
operands.push(quasis[j]);
|
|
1134
|
+
strings.push(quasis[j].value.raw);
|
|
1135
|
+
if (j < expressions.length) {
|
|
1136
|
+
operands.push(expressions[j]);
|
|
1137
|
+
strings.push(void 0);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
loc.runtimeClass ??= runtimeClass(loc.value, operands, strings, 2 * i + 1);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
out.push(loc);
|
|
1145
|
+
}
|
|
1101
1146
|
}
|
|
1102
1147
|
return out;
|
|
1103
1148
|
}
|
|
@@ -1143,6 +1188,7 @@ function appendFromConcatenation(node, out) {
|
|
|
1143
1188
|
if (value === void 0) {
|
|
1144
1189
|
const inner = extractFromExpression(operands[i], []);
|
|
1145
1190
|
for (const loc of inner) {
|
|
1191
|
+
loc.partial = true;
|
|
1146
1192
|
if (glueBefore) loc.preserveLeadingSpace = true;
|
|
1147
1193
|
if (glueAfter) {
|
|
1148
1194
|
loc.preserveTrailingSpace = true;
|
|
@@ -1159,7 +1205,8 @@ function appendFromConcatenation(node, out) {
|
|
|
1159
1205
|
node: operand,
|
|
1160
1206
|
range: [operand.range[0] + 1, operand.range[1] - 1],
|
|
1161
1207
|
preserveLeadingSpace: glueBefore,
|
|
1162
|
-
preserveTrailingSpace: glueAfter
|
|
1208
|
+
preserveTrailingSpace: glueAfter,
|
|
1209
|
+
partial: true
|
|
1163
1210
|
};
|
|
1164
1211
|
if (glueAfter && !/\s$/.test(value)) loc.runtimeClass = runtimeClass(value, operands, strings, i);
|
|
1165
1212
|
out.push(loc);
|
|
@@ -1901,6 +1948,13 @@ const DYNAMIC_NUMERIC_RE = /^(.+)-\d+\.?\d*$/;
|
|
|
1901
1948
|
* `from-33.5%`, so a decimal here would be tolerance with nothing behind it.
|
|
1902
1949
|
*/
|
|
1903
1950
|
const DYNAMIC_PERCENT_RE = /^(.+)-\d+%$/;
|
|
1951
|
+
/** `--color-red-500` (or `--tw-color-red-500` under `prefix(tw)`) → `red-500`. */
|
|
1952
|
+
function colorNameOf(varName, prefix) {
|
|
1953
|
+
if (varName.startsWith("--color-")) return varName.slice(8);
|
|
1954
|
+
if (prefix === "") return null;
|
|
1955
|
+
const namespace = `--${prefix}-color-`;
|
|
1956
|
+
return varName.startsWith(namespace) ? varName.slice(namespace.length) : null;
|
|
1957
|
+
}
|
|
1904
1958
|
var DesignSystemCache = class DesignSystemCache {
|
|
1905
1959
|
canonicalMap = /* @__PURE__ */ new Map();
|
|
1906
1960
|
deprecatedMap = /* @__PURE__ */ new Map();
|
|
@@ -1956,7 +2010,7 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
1956
2010
|
}
|
|
1957
2011
|
for (const name of data.definedVars ?? []) cache.definedVarSet.add(name);
|
|
1958
2012
|
for (const name of data.paletteVars ?? []) cache.paletteVarSet.add(name);
|
|
1959
|
-
cache.projectColorNames = (data.projectColorVars ?? []).map((name) => name.
|
|
2013
|
+
cache.projectColorNames = (data.projectColorVars ?? []).map((name) => colorNameOf(name, data.prefix ?? "") ?? name).sort((a, b) => a.localeCompare(b));
|
|
1960
2014
|
if (data.themeRefs) for (const [name, refs] of Object.entries(data.themeRefs)) cache.themeRefs.set(name, refs);
|
|
1961
2015
|
for (const [prefix, entries] of Object.entries(data.tokenValues ?? {})) cache.tokenValuesMap.set(prefix, entries);
|
|
1962
2016
|
if (data.scale) cache.scaleFacts = {
|
|
@@ -2414,6 +2468,14 @@ var DesignSystemCache = class DesignSystemCache {
|
|
|
2414
2468
|
isPaletteVar(varName) {
|
|
2415
2469
|
return this.paletteVarSet.has(varName);
|
|
2416
2470
|
}
|
|
2471
|
+
/**
|
|
2472
|
+
* The color a theme color variable names (`--color-red-500` → `red-500`), or
|
|
2473
|
+
* `null` for any other variable. Under a project prefix the theme's colors are
|
|
2474
|
+
* `--tw-color-*` (#253), and both spellings are accepted.
|
|
2475
|
+
*/
|
|
2476
|
+
themeColorName(varName) {
|
|
2477
|
+
return colorNameOf(varName, this._prefix);
|
|
2478
|
+
}
|
|
2417
2479
|
/** The colors the project's theme declares, by name (`brand`, `primary`), sorted. */
|
|
2418
2480
|
projectColors() {
|
|
2419
2481
|
return this.projectColorNames;
|
|
@@ -3523,10 +3585,11 @@ async function main() {
|
|
|
3523
3585
|
//
|
|
3524
3586
|
// Functional variants (\`group-*\`, \`peer-*\`, \`data-*\`, \`nth-*\`) are skipped:
|
|
3525
3587
|
// probing them would need a value, and none of them retargets the selector.
|
|
3526
|
-
// Measured in Tailwind 4.3.
|
|
3527
|
-
//
|
|
3528
|
-
//
|
|
3529
|
-
//
|
|
3588
|
+
// Measured in Tailwind 4.3.5: \`group-hover\`/\`peer-checked\` compile to
|
|
3589
|
+
// \`:is(:where(.group):hover .x)\` (since tailwindlabs/tailwindcss#20513; 4.3.3
|
|
3590
|
+
// printed \`&:is(:where(.group):hover *)\`) — either way a condition on the
|
|
3591
|
+
// element itself — so two of them in either order produce equivalent selectors
|
|
3592
|
+
// and neither is a reordering barrier.
|
|
3530
3593
|
const variantFacts = {};
|
|
3531
3594
|
const probeNames = [];
|
|
3532
3595
|
for (let i = 0; i < variants.length; i++) {
|
|
@@ -3598,13 +3661,15 @@ async function main() {
|
|
|
3598
3661
|
// Tailwind's default palette (\`@theme default\`, theme option DEFAULT = 4)
|
|
3599
3662
|
// apart from the colors the project declares, for no-default-palette. A
|
|
3600
3663
|
// project that redefines a palette color owns it: its entry loses the flag.
|
|
3664
|
+
// Under a prefix the theme names them \`--tw-color-*\`, as the CSS reads them (#253).
|
|
3601
3665
|
const paletteVars = [];
|
|
3602
3666
|
const projectColorVars = [];
|
|
3667
|
+
const colorNamespace = prefix ? '--' + prefix + '-color-' : '--color-';
|
|
3603
3668
|
if (ds.theme && typeof ds.theme.entries === 'function') {
|
|
3604
3669
|
for (const [name, entry] of ds.theme.entries()) {
|
|
3605
3670
|
const value = entry && typeof entry.value === 'string' ? entry.value : '';
|
|
3606
3671
|
themeValues.set(name, value);
|
|
3607
|
-
if (name.startsWith(
|
|
3672
|
+
if (name.startsWith(colorNamespace)) {
|
|
3608
3673
|
if (entry && (entry.options & 4)) paletteVars.push(name);
|
|
3609
3674
|
else projectColorVars.push(name);
|
|
3610
3675
|
}
|
|
@@ -4589,7 +4654,10 @@ async function main() {
|
|
|
4589
4654
|
const handler = ${handlerExpr};
|
|
4590
4655
|
|
|
4591
4656
|
while (true) {
|
|
4592
|
-
|
|
4657
|
+
// Wait on the flag, not on the wake-up: the host's \`notify\` is a separate
|
|
4658
|
+
// step from its \`store\`, so a late one can land on this wait after the
|
|
4659
|
+
// request it announced was already served (#251).
|
|
4660
|
+
while (Atomics.load(control, 0) === 0) Atomics.wait(control, 0, 0);
|
|
4593
4661
|
const len = lengthView.getUint32(0);
|
|
4594
4662
|
const requestStr = Buffer.from(dataArea.slice(0, len)).toString('utf-8');
|
|
4595
4663
|
Atomics.store(control, 0, 0);
|
|
@@ -4779,7 +4847,16 @@ var DesignSystemWorker = class {
|
|
|
4779
4847
|
state.lengthView.setUint32(0, requestBytes.length);
|
|
4780
4848
|
Atomics.store(state.controlArray, 0, 1);
|
|
4781
4849
|
Atomics.notify(state.controlArray, 0);
|
|
4782
|
-
|
|
4850
|
+
const deadline = Date.now() + this.requestTimeoutMs;
|
|
4851
|
+
let timedOut = false;
|
|
4852
|
+
while (Atomics.load(state.controlArray, 1) === 0) {
|
|
4853
|
+
const left = deadline - Date.now();
|
|
4854
|
+
if (left <= 0 || Atomics.wait(state.controlArray, 1, 0, left) === "timed-out") {
|
|
4855
|
+
timedOut = Atomics.load(state.controlArray, 1) === 0;
|
|
4856
|
+
break;
|
|
4857
|
+
}
|
|
4858
|
+
}
|
|
4859
|
+
if (timedOut) throw this.failRequest(cssPath, new SortServiceError(`${this.opts.serviceName} worker request timed out after ${this.requestTimeoutMs}ms.`, "A slow machine or CI runner can cause this. If the class lists are valid, raise OXLINT_TAILWINDCSS_WORKER_REQUEST_TIMEOUT; otherwise please open an issue."));
|
|
4783
4860
|
const responseLen = state.lengthView.getUint32(0);
|
|
4784
4861
|
const responseStr = Buffer.from(state.dataArea.slice(0, responseLen)).toString("utf-8");
|
|
4785
4862
|
Atomics.store(state.controlArray, 1, 0);
|
|
@@ -5344,7 +5421,7 @@ function resolveByGlobMapping(mappings, filePath, baseDir) {
|
|
|
5344
5421
|
}
|
|
5345
5422
|
/**
|
|
5346
5423
|
* oxlint discovers nested configuration by walking up from each linted file
|
|
5347
|
-
* looking for files with these names (oxlint 1.
|
|
5424
|
+
* looking for files with these names (oxlint 1.93: JSON, JSONC, and the JS
|
|
5348
5425
|
* configs it loads through Node). We mirror that walk to find the config
|
|
5349
5426
|
* directory a relative `entryPoint` should be anchored to — which is also
|
|
5350
5427
|
* where an `oxlint.config.ts` passes it through `oxlint-tailwindcss/config`.
|
|
@@ -8286,16 +8363,16 @@ function withoutVarGroups(value) {
|
|
|
8286
8363
|
}
|
|
8287
8364
|
/**
|
|
8288
8365
|
* The colour property a class sets, read from the CSS it emits — a colour
|
|
8289
|
-
* property, a read of a `--color-*` theme variable
|
|
8290
|
-
* null when it sets none. Descendant and pseudo-element declarations count
|
|
8366
|
+
* property, a read of a `--color-*` theme variable (`--tw-color-*` under a
|
|
8367
|
+
* prefix, #253), or a colour literal — or null when it sets none. Descendant and pseudo-element declarations count
|
|
8291
8368
|
* (`divide-*`, `placeholder-*` colour other boxes); `@media`-conditional ones
|
|
8292
8369
|
* don't.
|
|
8293
8370
|
*/
|
|
8294
|
-
function colorPropertyOf(decls) {
|
|
8371
|
+
function colorPropertyOf(decls, cache) {
|
|
8295
8372
|
const own = decls.filter((d) => !d.conditional);
|
|
8296
8373
|
for (const d of own) if (COLOR_PROPERTY.test(d.prop)) return d.prop;
|
|
8297
8374
|
for (const d of own) {
|
|
8298
|
-
if (d.readsVars.some((v) =>
|
|
8375
|
+
if (d.readsVars.some((v) => cache.themeColorName(v) !== null)) return d.prop;
|
|
8299
8376
|
if (COLOR_LITERAL.test(withoutVarGroups(d.value))) return d.prop;
|
|
8300
8377
|
}
|
|
8301
8378
|
return null;
|
|
@@ -8413,8 +8490,8 @@ const noDarkWithoutLight = defineRule({
|
|
|
8413
8490
|
if (variant !== void 0) {
|
|
8414
8491
|
const decls = cache ? cache.getCssDeclarations(bare) : [];
|
|
8415
8492
|
let colorProperty;
|
|
8416
|
-
if (decls.length > 0) {
|
|
8417
|
-
const found = colorPropertyOf(decls);
|
|
8493
|
+
if (cache && decls.length > 0) {
|
|
8494
|
+
const found = colorPropertyOf(decls, cache);
|
|
8418
8495
|
if (found === null) continue;
|
|
8419
8496
|
colorProperty = found;
|
|
8420
8497
|
} else if (isNeverColorStatic(bare)) continue;
|
|
@@ -9968,7 +10045,8 @@ const noDynamicClasses = defineRule({
|
|
|
9968
10045
|
}
|
|
9969
10046
|
});
|
|
9970
10047
|
// src/rules/no-default-palette.ts
|
|
9971
|
-
|
|
10048
|
+
/** An arbitrary value reading a theme color: `var(--color-…)`, or `var(--tw-color-…)` under a prefix. */
|
|
10049
|
+
const COLOR_VAR_READ = /var\(--(?:[a-z0-9]+-)?color-/;
|
|
9972
10050
|
/** `white`, `gray-*` → a test on palette color names. */
|
|
9973
10051
|
function compileAllow(allow) {
|
|
9974
10052
|
const exact = new Set(allow.filter((a) => !a.endsWith("*")));
|
|
@@ -9980,11 +10058,11 @@ function paletteColorOf(cls, cache, entryPoint) {
|
|
|
9980
10058
|
const { bare } = splitImportant(splitUtilityAndVariant(cls).utility);
|
|
9981
10059
|
const base = bare.replace(/\/[^/\]]+$/, "");
|
|
9982
10060
|
let decls = cache.getCssDeclarations(base);
|
|
9983
|
-
if (decls.length === 0 &&
|
|
10061
|
+
if (decls.length === 0 && COLOR_VAR_READ.test(base)) {
|
|
9984
10062
|
resolveDeclarationsSync(entryPoint, cache, [base]);
|
|
9985
10063
|
decls = cache.getCssDeclarations(base);
|
|
9986
10064
|
}
|
|
9987
|
-
for (const decl of decls) for (const read of decl.readsVars) if (cache.isPaletteVar(read)) return
|
|
10065
|
+
for (const decl of decls) for (const read of decl.readsVars) if (cache.isPaletteVar(read)) return cache.themeColorName(read);
|
|
9988
10066
|
return null;
|
|
9989
10067
|
}
|
|
9990
10068
|
const noDefaultPalette = defineRule({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oxlint-tailwindcss",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.3",
|
|
4
4
|
"description": "Tailwind CSS v4 lint rules for oxlint that read your design system: unknown, conflicting and deprecated classes, theme colors, class order — with autofixes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"classnames",
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"prepublishOnly": "pnpm run build"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@tailwindcss/node": "^4.3.
|
|
70
|
-
"tailwindcss": "^4.3.
|
|
69
|
+
"@tailwindcss/node": "^4.3.5",
|
|
70
|
+
"tailwindcss": "^4.3.5"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@oxlint/plugins": "catalog:",
|
|
@@ -75,10 +75,10 @@
|
|
|
75
75
|
"@types/node": "^26.6.6",
|
|
76
76
|
"oxlint": "catalog:",
|
|
77
77
|
"tailwindcss-animate": "^1.0.7",
|
|
78
|
-
"tsdown": "^0.23.
|
|
78
|
+
"tsdown": "^0.23.7",
|
|
79
79
|
"tw-animate-css": "^1.4.0",
|
|
80
80
|
"typescript": "^7.0.2",
|
|
81
|
-
"vitest": "^5.0
|
|
81
|
+
"vitest": "^5.1.0"
|
|
82
82
|
},
|
|
83
83
|
"engines": {
|
|
84
84
|
"node": "^20.19.0 || >=22.12.0"
|