oxlint-tailwindcss 1.10.2 → 1.11.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 +24 -3
- package/dist/index.cjs +299 -47
- package/dist/index.d.cts +16 -26
- package/dist/index.d.mts +16 -26
- package/dist/index.mjs +299 -47
- package/package.json +4 -4
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.82.0/node_modules/@oxlint/plugins/index.js
|
|
11
11
|
/**
|
|
12
12
|
* Define a plugin.
|
|
13
13
|
*
|
|
@@ -119,6 +119,7 @@ function preserveSpaces(loc, fixed) {
|
|
|
119
119
|
}
|
|
120
120
|
const DEFAULT_EXTRACTOR_CONFIG = {
|
|
121
121
|
attributes: ["className", "class"],
|
|
122
|
+
attributePatterns: [],
|
|
122
123
|
callees: [
|
|
123
124
|
"cn",
|
|
124
125
|
"clsx",
|
|
@@ -182,6 +183,7 @@ function getExtractorConfig(context) {
|
|
|
182
183
|
const filteredPatterns = excludedPatternSources.size > 0 ? DEFAULT_EXTRACTOR_CONFIG.variablePatterns.filter((re) => !excludedPatternSources.has(re.source)) : DEFAULT_EXTRACTOR_CONFIG.variablePatterns;
|
|
183
184
|
const resolved = {
|
|
184
185
|
attributes: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.attributes, tw.attributes, exclude?.attributes),
|
|
186
|
+
attributePatterns: compileRegexList(tw.attributePatterns),
|
|
185
187
|
callees: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.callees, tw.callees, exclude?.callees),
|
|
186
188
|
tags: mergeUnique(DEFAULT_EXTRACTOR_CONFIG.tags, tw.tags, exclude?.tags),
|
|
187
189
|
variablePatterns: [...filteredPatterns, ...compileRegexList(tw.variablePatterns)]
|
|
@@ -241,7 +243,7 @@ function jsxHostOrigin(node) {
|
|
|
241
243
|
*/
|
|
242
244
|
function extractFromJSXAttribute(node, config = DEFAULT_EXTRACTOR_CONFIG) {
|
|
243
245
|
const name = node.name.type === "JSXIdentifier" ? node.name.name : void 0;
|
|
244
|
-
if (!name || !config.attributes.includes(name)) return [];
|
|
246
|
+
if (!name || !config.attributes.includes(name) && !config.attributePatterns.some((p) => p.test(name))) return [];
|
|
245
247
|
if (!node.value) return [];
|
|
246
248
|
const hostOrigin = jsxHostOrigin(node);
|
|
247
249
|
if (node.value.type === "Literal" && typeof node.value.value === "string") return [{
|
|
@@ -465,7 +467,8 @@ function appendFromTemplateLiteral(node, out) {
|
|
|
465
467
|
node: quasi,
|
|
466
468
|
range: [start, start + value.length],
|
|
467
469
|
preserveLeadingSpace: i > 0,
|
|
468
|
-
preserveTrailingSpace: i < node.quasis.length - 1
|
|
470
|
+
preserveTrailingSpace: i < node.quasis.length - 1,
|
|
471
|
+
templateLine: node.loc?.start.line
|
|
469
472
|
});
|
|
470
473
|
}
|
|
471
474
|
}
|
|
@@ -796,6 +799,26 @@ function splitUtilityAndVariant(cls) {
|
|
|
796
799
|
};
|
|
797
800
|
}
|
|
798
801
|
/**
|
|
802
|
+
* Strips a Tailwind v4 project prefix (`@import "tailwindcss" prefix(tw)` → `tw`)
|
|
803
|
+
* off a class, returning the matched prefix marker (`"tw:"`, or `""`) and the
|
|
804
|
+
* remaining body. The project prefix is structurally a variant but pinned FIRST
|
|
805
|
+
* (`tw:hover:flex`, never `hover:tw:flex`), so grouping/ordering rules strip it
|
|
806
|
+
* before reading the real variant chain — the prefix invariant shared by
|
|
807
|
+
* enforce-sort-order, consistent-variant-order and enforce-consistent-line-wrapping.
|
|
808
|
+
* `prefix === ""` (no project prefix / no design system) or a non-matching class
|
|
809
|
+
* passes through untouched.
|
|
810
|
+
*/
|
|
811
|
+
function stripProjectPrefix(cls, prefix) {
|
|
812
|
+
if (prefix !== "" && cls.startsWith(prefix + ":")) return {
|
|
813
|
+
prefix: prefix + ":",
|
|
814
|
+
body: cls.slice(prefix.length + 1)
|
|
815
|
+
};
|
|
816
|
+
return {
|
|
817
|
+
prefix: "",
|
|
818
|
+
body: cls
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
799
822
|
* Checks if a class has an arbitrary value (bracket syntax in the utility part).
|
|
800
823
|
* Distinguishes from arbitrary variants: [&>svg]:w-4 does NOT have an arbitrary value,
|
|
801
824
|
* but w-[200px] does.
|
|
@@ -2773,7 +2796,30 @@ function cacheDirName() {
|
|
|
2773
2796
|
return "oxlint-tailwindcss";
|
|
2774
2797
|
}
|
|
2775
2798
|
}
|
|
2776
|
-
|
|
2799
|
+
/**
|
|
2800
|
+
* The disk-cache directory.
|
|
2801
|
+
*
|
|
2802
|
+
* Defaults to a per-uid dir under the system temp dir (see `cacheDirName`), but
|
|
2803
|
+
* honours `OXLINT_TAILWINDCSS_CACHE_DIR` when set to a non-empty value. Two uses:
|
|
2804
|
+
* - CI / sandboxed builds that want the cache at a controlled, pruneable
|
|
2805
|
+
* location instead of the shared system temp dir.
|
|
2806
|
+
* - The test suite, which points each `pnpm test` invocation at its OWN dir
|
|
2807
|
+
* (`vitest.config.ts`) so two concurrent runs — a background run and the
|
|
2808
|
+
* stop-hook's run, or a dev's editor running oxlint alongside the tests —
|
|
2809
|
+
* never share cache files and race on them (the source of the
|
|
2810
|
+
* `canonicalize-persistence` EISDIR / stale-read flakes).
|
|
2811
|
+
*
|
|
2812
|
+
* The dir the plugin creates is still `mode 0o700` (see `computeWithLock`), so
|
|
2813
|
+
* an override the plugin creates stays private to its owner; pointing the
|
|
2814
|
+
* override at a pre-existing world-writable dir re-opens the poisoning vector
|
|
2815
|
+
* `cacheDirName` closes, so that is the caller's responsibility.
|
|
2816
|
+
*/
|
|
2817
|
+
function resolveCacheDir() {
|
|
2818
|
+
const override = process.env.OXLINT_TAILWINDCSS_CACHE_DIR;
|
|
2819
|
+
if (typeof override === "string" && override.trim() !== "") return override.trim();
|
|
2820
|
+
return join(tmpdir(), cacheDirName());
|
|
2821
|
+
}
|
|
2822
|
+
const CACHE_DIR = resolveCacheDir();
|
|
2777
2823
|
/** md5 of the precompute script (no version) — the version is folded in per entry point. */
|
|
2778
2824
|
const SCRIPT_HASH = createHash("md5").update(PRECOMPUTE_SCRIPT).digest("hex").slice(0, 8);
|
|
2779
2825
|
/**
|
|
@@ -2916,7 +2962,7 @@ function reclaimStaleLock$1(lockPath) {
|
|
|
2916
2962
|
}
|
|
2917
2963
|
/** control[2] — the worker's ready/done signal (0=loading, 1=done, -1=error). */
|
|
2918
2964
|
const PRECOMPUTE_SIGNAL_INDEX = 2;
|
|
2919
|
-
const ERR_BUFFER_SIZE =
|
|
2965
|
+
const ERR_BUFFER_SIZE = 65536;
|
|
2920
2966
|
let precomputeSeq = 0;
|
|
2921
2967
|
/**
|
|
2922
2968
|
* Choose the diagnostic hint based on the underlying error code. ENOMEM/EAGAIN
|
|
@@ -3685,17 +3731,38 @@ function resolveEntryPointForFile(ruleOptionEntry, settingsEntry, filePath, cwd
|
|
|
3685
3731
|
* — SharedArrayBuffer layout, state machine, lifecycle, fail-loud — and each
|
|
3686
3732
|
* service shrinks to ~40 LOC of singleton + public signature.
|
|
3687
3733
|
*
|
|
3688
|
-
* v1: failures throw `SortServiceError`.
|
|
3689
|
-
*
|
|
3690
|
-
* init-timeout cost.
|
|
3691
|
-
*
|
|
3692
|
-
|
|
3693
|
-
|
|
3734
|
+
* v1: failures throw `SortServiceError`. Init/spawn/crash/DS-load failures are
|
|
3735
|
+
* HARD sticky per cssPath for the process lifetime, so subsequent calls don't
|
|
3736
|
+
* pay another init-timeout cost. Per-request failures (timeout / non-JSON /
|
|
3737
|
+
* null) are SOFT sticky (#145): unbounded retrying re-pays the full request
|
|
3738
|
+
* timeout on every class list (O(files)), so after a few consecutive failures
|
|
3739
|
+
* the error goes sticky for a backoff window and the rest of the run fails fast;
|
|
3740
|
+
* any success clears it. Callers wrap via `safeGetDS` to surface the failure as
|
|
3741
|
+
* a single `designSystemUnavailable` diagnostic.
|
|
3742
|
+
*/
|
|
3743
|
+
const BUFFER_SIZE = 4194304;
|
|
3694
3744
|
const HEADER_INTS = 4;
|
|
3695
|
-
const LENGTH_OFFSET =
|
|
3745
|
+
const LENGTH_OFFSET = 16;
|
|
3696
3746
|
const DATA_OFFSET = 20;
|
|
3697
3747
|
const INIT_TIMEOUT = 6e4;
|
|
3698
3748
|
const REQUEST_TIMEOUT = 3e4;
|
|
3749
|
+
const MAX_CONSECUTIVE_REQUEST_FAILURES = 3;
|
|
3750
|
+
const REQUEST_STICKY_BACKOFF_MS = 6e4;
|
|
3751
|
+
/**
|
|
3752
|
+
* Per-request timeout override for slow-but-functional machines (#145). A
|
|
3753
|
+
* machine whose cold canonicalize sits close to the 30 s default times out
|
|
3754
|
+
* spuriously; raising this lets the request COMPLETE (the rule keeps working)
|
|
3755
|
+
* rather than only failing fast. An env var — not a `settings.tailwindcss` key —
|
|
3756
|
+
* keeps the documented invariant that worker services don't read
|
|
3757
|
+
* `settings.tailwindcss.timeout`, and sidesteps the settings-timing problem
|
|
3758
|
+
* (settings throw inside `createOnce`). Read once per worker construction.
|
|
3759
|
+
*/
|
|
3760
|
+
function envRequestTimeout() {
|
|
3761
|
+
const raw = process.env.OXLINT_TAILWINDCSS_WORKER_REQUEST_TIMEOUT;
|
|
3762
|
+
if (raw === void 0 || raw === "") return void 0;
|
|
3763
|
+
const n = Number(raw);
|
|
3764
|
+
return Number.isFinite(n) && n > 0 ? n : void 0;
|
|
3765
|
+
}
|
|
3699
3766
|
const MAX_WORKERS = 8;
|
|
3700
3767
|
/**
|
|
3701
3768
|
* Build the worker script shared by `sort-service` and `canonicalize-service`.
|
|
@@ -3782,15 +3849,41 @@ var DesignSystemWorker = class {
|
|
|
3782
3849
|
opts;
|
|
3783
3850
|
workers = /* @__PURE__ */ new Map();
|
|
3784
3851
|
errors = /* @__PURE__ */ new Map();
|
|
3852
|
+
requestFailCount = /* @__PURE__ */ new Map();
|
|
3853
|
+
requestStick = /* @__PURE__ */ new Map();
|
|
3854
|
+
/** Resolved per-request timeout (option > env var > REQUEST_TIMEOUT). */
|
|
3855
|
+
requestTimeoutMs;
|
|
3856
|
+
/** Resolved consecutive-failure budget before a per-request error goes soft-sticky. */
|
|
3857
|
+
maxConsecutiveRequestFailures;
|
|
3785
3858
|
constructor(opts) {
|
|
3786
3859
|
this.opts = opts;
|
|
3860
|
+
this.requestTimeoutMs = opts.requestTimeoutMs ?? envRequestTimeout() ?? REQUEST_TIMEOUT;
|
|
3861
|
+
this.maxConsecutiveRequestFailures = opts.maxConsecutiveRequestFailures ?? MAX_CONSECUTIVE_REQUEST_FAILURES;
|
|
3787
3862
|
}
|
|
3788
|
-
/** Record an error as sticky for `cssPath` and return it for `throw`. */
|
|
3863
|
+
/** Record an error as HARD sticky for `cssPath` and return it for `throw`. */
|
|
3789
3864
|
remember(cssPath, err) {
|
|
3790
3865
|
this.errors.set(cssPath, err);
|
|
3791
3866
|
return err;
|
|
3792
3867
|
}
|
|
3793
3868
|
/**
|
|
3869
|
+
* Handle a per-request (SOFT) failure (#145): drop the worker so the next call
|
|
3870
|
+
* re-spawns, count consecutive failures for this cssPath, and once the budget
|
|
3871
|
+
* is spent record a soft sticky good for a backoff window so the rest of the
|
|
3872
|
+
* run fails fast instead of re-paying the timeout per class list. A later
|
|
3873
|
+
* success (see `callSync`) clears the count and the soft sticky. Returns the
|
|
3874
|
+
* error for `throw` (mirrors `remember`).
|
|
3875
|
+
*/
|
|
3876
|
+
failRequest(cssPath, err) {
|
|
3877
|
+
this.dropWorker(cssPath);
|
|
3878
|
+
const count = (this.requestFailCount.get(cssPath) ?? 0) + 1;
|
|
3879
|
+
this.requestFailCount.set(cssPath, count);
|
|
3880
|
+
if (count >= this.maxConsecutiveRequestFailures) this.requestStick.set(cssPath, {
|
|
3881
|
+
err,
|
|
3882
|
+
until: Date.now() + REQUEST_STICKY_BACKOFF_MS
|
|
3883
|
+
});
|
|
3884
|
+
return err;
|
|
3885
|
+
}
|
|
3886
|
+
/**
|
|
3794
3887
|
* Ensure the worker is running and pointed at `cssPath`. Returns the
|
|
3795
3888
|
* ready state. Throws `SortServiceError` on any failure (init timeout,
|
|
3796
3889
|
* spawn error, DS-load error). Sticky: subsequent calls for the same
|
|
@@ -3799,6 +3892,12 @@ var DesignSystemWorker = class {
|
|
|
3799
3892
|
ensure(cssPath) {
|
|
3800
3893
|
const sticky = this.errors.get(cssPath);
|
|
3801
3894
|
if (sticky) throw sticky;
|
|
3895
|
+
const soft = this.requestStick.get(cssPath);
|
|
3896
|
+
if (soft) {
|
|
3897
|
+
if (Date.now() < soft.until) throw soft.err;
|
|
3898
|
+
this.requestStick.delete(cssPath);
|
|
3899
|
+
this.requestFailCount.delete(cssPath);
|
|
3900
|
+
}
|
|
3802
3901
|
const existing = this.workers.get(cssPath);
|
|
3803
3902
|
if (existing) {
|
|
3804
3903
|
this.workers.delete(cssPath);
|
|
@@ -3809,7 +3908,7 @@ var DesignSystemWorker = class {
|
|
|
3809
3908
|
if (tailwindNodePath === null) throw this.remember(cssPath, new SortServiceError(`Could not resolve '@tailwindcss/node' for the ${this.opts.serviceName} worker.`, "Install '@tailwindcss/node' (or upgrade oxlint-tailwindcss) and re-run."));
|
|
3810
3909
|
const sharedBuffer = new SharedArrayBuffer(BUFFER_SIZE);
|
|
3811
3910
|
const controlArray = new Int32Array(sharedBuffer, 0, HEADER_INTS);
|
|
3812
|
-
const lengthView = new DataView(sharedBuffer,
|
|
3911
|
+
const lengthView = new DataView(sharedBuffer, 16, 4);
|
|
3813
3912
|
const dataArea = new Uint8Array(sharedBuffer, DATA_OFFSET);
|
|
3814
3913
|
let worker;
|
|
3815
3914
|
try {
|
|
@@ -3868,15 +3967,12 @@ var DesignSystemWorker = class {
|
|
|
3868
3967
|
callSync(cssPath, req) {
|
|
3869
3968
|
const state = this.ensure(cssPath);
|
|
3870
3969
|
const requestBytes = Buffer.from(JSON.stringify(req), "utf-8");
|
|
3871
|
-
if (requestBytes.length >
|
|
3970
|
+
if (requestBytes.length > 4194284) throw new SortServiceError(`${this.opts.serviceName} request payload is too large (${requestBytes.length} > 4194284 bytes).`, "This is unexpected with typical class lists; please open an issue.");
|
|
3872
3971
|
state.dataArea.set(requestBytes, 0);
|
|
3873
3972
|
state.lengthView.setUint32(0, requestBytes.length);
|
|
3874
3973
|
Atomics.store(state.controlArray, 0, 1);
|
|
3875
3974
|
Atomics.notify(state.controlArray, 0);
|
|
3876
|
-
if (Atomics.wait(state.controlArray, 1, 0,
|
|
3877
|
-
this.dropWorker(cssPath);
|
|
3878
|
-
throw new SortServiceError(`${this.opts.serviceName} worker request timed out after ${REQUEST_TIMEOUT}ms.`, "This is unexpected for typical class lists; please open an issue if it persists.");
|
|
3879
|
-
}
|
|
3975
|
+
if (Atomics.wait(state.controlArray, 1, 0, this.requestTimeoutMs) === "timed-out") 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."));
|
|
3880
3976
|
const responseLen = state.lengthView.getUint32(0);
|
|
3881
3977
|
const responseStr = Buffer.from(state.dataArea.slice(0, responseLen)).toString("utf-8");
|
|
3882
3978
|
Atomics.store(state.controlArray, 1, 0);
|
|
@@ -3884,19 +3980,19 @@ var DesignSystemWorker = class {
|
|
|
3884
3980
|
try {
|
|
3885
3981
|
parsed = JSON.parse(responseStr);
|
|
3886
3982
|
} catch (cause) {
|
|
3887
|
-
this.
|
|
3888
|
-
throw new SortServiceError(`${this.opts.serviceName} worker returned non-JSON response.`, "This is a bug; please open an issue.", { cause: cause instanceof Error ? cause : void 0 });
|
|
3889
|
-
}
|
|
3890
|
-
if (parsed === null) {
|
|
3891
|
-
this.dropWorker(cssPath);
|
|
3892
|
-
throw new SortServiceError(`${this.opts.serviceName} worker returned null — the request body was rejected or its response did not fit the buffer.`, "This is a bug; please open an issue with the input that triggered it.");
|
|
3983
|
+
throw this.failRequest(cssPath, new SortServiceError(`${this.opts.serviceName} worker returned non-JSON response.`, "This is a bug; please open an issue.", { cause: cause instanceof Error ? cause : void 0 }));
|
|
3893
3984
|
}
|
|
3985
|
+
if (parsed === null) throw this.failRequest(cssPath, new SortServiceError(`${this.opts.serviceName} worker returned null — the request body was rejected or its response did not fit the buffer.`, "This is a bug; please open an issue with the input that triggered it."));
|
|
3986
|
+
this.requestFailCount.delete(cssPath);
|
|
3987
|
+
this.requestStick.delete(cssPath);
|
|
3894
3988
|
return parsed;
|
|
3895
3989
|
}
|
|
3896
3990
|
reset() {
|
|
3897
3991
|
for (const state of this.workers.values()) this.terminateWorker(state.worker);
|
|
3898
3992
|
this.workers.clear();
|
|
3899
3993
|
this.errors.clear();
|
|
3994
|
+
this.requestFailCount.clear();
|
|
3995
|
+
this.requestStick.clear();
|
|
3900
3996
|
}
|
|
3901
3997
|
/** Terminate and forget the worker for a single cssPath (on request failure). */
|
|
3902
3998
|
dropWorker(cssPath) {
|
|
@@ -4856,7 +4952,7 @@ const noDeprecatedClasses = defineRule({
|
|
|
4856
4952
|
return createExtractorVisitors(context, check);
|
|
4857
4953
|
}
|
|
4858
4954
|
});
|
|
4859
|
-
const WORKER_SCRIPT = makeWorkerScript(`(ds, request) => {
|
|
4955
|
+
const WORKER_SCRIPT$1 = makeWorkerScript(`(ds, request) => {
|
|
4860
4956
|
const { classes, rem } = request;
|
|
4861
4957
|
const options = rem ? { rem } : undefined;
|
|
4862
4958
|
const declsOf = (cls) => {
|
|
@@ -4889,7 +4985,7 @@ const WORKER_SCRIPT = makeWorkerScript(`(ds, request) => {
|
|
|
4889
4985
|
});
|
|
4890
4986
|
}`);
|
|
4891
4987
|
const canonWorker = new DesignSystemWorker({
|
|
4892
|
-
workerScript: WORKER_SCRIPT,
|
|
4988
|
+
workerScript: WORKER_SCRIPT$1,
|
|
4893
4989
|
serviceName: "canonicalize"
|
|
4894
4990
|
});
|
|
4895
4991
|
/**
|
|
@@ -4923,7 +5019,7 @@ const canonCache = /* @__PURE__ */ new Map();
|
|
|
4923
5019
|
* Best-effort everywhere: a missing/corrupt/unwritable cache file must never
|
|
4924
5020
|
* break linting — it only costs worker round-trips.
|
|
4925
5021
|
*/
|
|
4926
|
-
const CANON_LOGIC_HASH = createHash("md5").update(WORKER_SCRIPT + roundRemValue.toString()).digest("hex").slice(0, 8);
|
|
5022
|
+
const CANON_LOGIC_HASH = createHash("md5").update(WORKER_SCRIPT$1 + roundRemValue.toString()).digest("hex").slice(0, 8);
|
|
4927
5023
|
let tmpSeq = 0;
|
|
4928
5024
|
const LOCK_STALE_MS = 1e4;
|
|
4929
5025
|
/** One persistence state per `${cssPath}\0${rem}\0` cache prefix. */
|
|
@@ -5287,7 +5383,7 @@ const enforceSortOrder = defineRule({
|
|
|
5287
5383
|
groupClasses.length = 0;
|
|
5288
5384
|
for (const [name] of ordered) groupClasses.push(name);
|
|
5289
5385
|
}
|
|
5290
|
-
const stripKey = (k) =>
|
|
5386
|
+
const stripKey = (k) => stripProjectPrefix(k, cache.prefix).body;
|
|
5291
5387
|
const sortedGroupKeys = [...groups.keys()].sort((ka, kb) => {
|
|
5292
5388
|
const a = stripKey(ka);
|
|
5293
5389
|
const b = stripKey(kb);
|
|
@@ -6797,12 +6893,7 @@ const consistentVariantOrder = defineRule({
|
|
|
6797
6893
|
}
|
|
6798
6894
|
function reorderClass(cls) {
|
|
6799
6895
|
const { priorityOf, prefix, factsFor } = resolveForFile();
|
|
6800
|
-
|
|
6801
|
-
let body = cls;
|
|
6802
|
-
if (prefix && cls.startsWith(prefix + ":")) {
|
|
6803
|
-
pfx = prefix + ":";
|
|
6804
|
-
body = cls.slice(prefix.length + 1);
|
|
6805
|
-
}
|
|
6896
|
+
const { prefix: pfx, body } = stripProjectPrefix(cls, prefix);
|
|
6806
6897
|
const variants = extractVariants(body);
|
|
6807
6898
|
if (variants.length < 2) return null;
|
|
6808
6899
|
const pseudo = [];
|
|
@@ -6883,6 +6974,7 @@ const consistentVariantOrder = defineRule({
|
|
|
6883
6974
|
//#endregion
|
|
6884
6975
|
//#region src/rules/enforce-consistent-line-wrapping.ts
|
|
6885
6976
|
const DEFAULT_PRINT_WIDTH = 80;
|
|
6977
|
+
const DEFAULT_GROUP = "newLine";
|
|
6886
6978
|
/** One indentation level added below the statement's base indent for wrapped lines. */
|
|
6887
6979
|
const INDENT_UNIT = " ";
|
|
6888
6980
|
/** Group `classes` into chunks of at most `n`, each chunk space-joined. */
|
|
@@ -6891,28 +6983,114 @@ function chunkList(classes, n) {
|
|
|
6891
6983
|
for (let i = 0; i < classes.length; i += n) chunks.push(classes.slice(i, i + n).join(" "));
|
|
6892
6984
|
return chunks;
|
|
6893
6985
|
}
|
|
6986
|
+
/**
|
|
6987
|
+
* Greedily pack `classes` into space-joined lines: a line takes classes until
|
|
6988
|
+
* `indent` + the next one would exceed `width`; a single class over the
|
|
6989
|
+
* budget still gets its own line. Widths count characters, so a tab in
|
|
6990
|
+
* `indent` is 1 column (detection uses the same yardstick, so tabs converge).
|
|
6991
|
+
*/
|
|
6992
|
+
function packToWidth(classes, indent, width) {
|
|
6993
|
+
const lines = [];
|
|
6994
|
+
let current = "";
|
|
6995
|
+
for (const cls of classes) {
|
|
6996
|
+
const candidate = current === "" ? cls : current + " " + cls;
|
|
6997
|
+
if (current !== "" && indent.length + candidate.length > width) {
|
|
6998
|
+
lines.push(current);
|
|
6999
|
+
current = cls;
|
|
7000
|
+
} else current = candidate;
|
|
7001
|
+
}
|
|
7002
|
+
if (current !== "") lines.push(current);
|
|
7003
|
+
return lines;
|
|
7004
|
+
}
|
|
7005
|
+
/**
|
|
7006
|
+
* Variant chain used as the grouping key. A Tailwind v4 project prefix
|
|
7007
|
+
* (`tw:`) is structurally a variant but pinned first, so it is stripped
|
|
7008
|
+
* before the key is computed — `tw:flex` keys as a base utility (grouping
|
|
7009
|
+
* with unprefixed component classes) and `tw:hover:x` keys as `hover:`,
|
|
7010
|
+
* matching how consistent-variant-order / enforce-sort-order treat the
|
|
7011
|
+
* prefix. Grouping only: emitted classes are never rewritten.
|
|
7012
|
+
*/
|
|
7013
|
+
function groupingKey(cls, prefix) {
|
|
7014
|
+
return getVariantPrefix(stripProjectPrefix(cls, prefix).body);
|
|
7015
|
+
}
|
|
7016
|
+
/**
|
|
7017
|
+
* Split `classes` into runs of consecutive classes sharing the same variant
|
|
7018
|
+
* chain ("hover:", "md:hover:", "" for base utilities), so wrapping breaks
|
|
7019
|
+
* between variant groups rather than mid-group.
|
|
7020
|
+
*/
|
|
7021
|
+
function groupByVariantRun(classes, prefix) {
|
|
7022
|
+
const groups = [];
|
|
7023
|
+
let current = [];
|
|
7024
|
+
let currentVariant = null;
|
|
7025
|
+
for (const cls of classes) {
|
|
7026
|
+
const variant = groupingKey(cls, prefix);
|
|
7027
|
+
if (currentVariant !== null && variant !== currentVariant) {
|
|
7028
|
+
groups.push(current);
|
|
7029
|
+
current = [];
|
|
7030
|
+
}
|
|
7031
|
+
currentVariant = variant;
|
|
7032
|
+
current.push(cls);
|
|
7033
|
+
}
|
|
7034
|
+
if (current.length > 0) groups.push(current);
|
|
7035
|
+
return groups;
|
|
7036
|
+
}
|
|
7037
|
+
/**
|
|
7038
|
+
* Pack `classes` per the `group` mode: 'never' packs greedily across
|
|
7039
|
+
* variant-run boundaries, 'newLine' starts each run on its own line(s), and
|
|
7040
|
+
* 'emptyLine' additionally inserts an extra line between runs — emitted as a
|
|
7041
|
+
* blank line with no indent.
|
|
7042
|
+
*/
|
|
7043
|
+
function packGroupedToWidth(classes, indent, width, group, prefix) {
|
|
7044
|
+
if (group === "never") return packToWidth(classes, indent, width);
|
|
7045
|
+
const lines = [];
|
|
7046
|
+
for (const run of groupByVariantRun(classes, prefix)) {
|
|
7047
|
+
if (group === "emptyLine" && lines.length > 0) lines.push("");
|
|
7048
|
+
lines.push(...packToWidth(run, indent, width));
|
|
7049
|
+
}
|
|
7050
|
+
return lines;
|
|
7051
|
+
}
|
|
6894
7052
|
const enforceConsistentLineWrapping = defineRule({
|
|
6895
7053
|
meta: {
|
|
6896
7054
|
type: "suggestion",
|
|
6897
|
-
docs: { description: "Warn when a class string exceeds the configured print width" },
|
|
7055
|
+
docs: { description: "Warn (and optionally autofix) when a class string exceeds the configured print width or classes-per-line budget" },
|
|
6898
7056
|
fixable: "whitespace",
|
|
6899
7057
|
schema: [{
|
|
6900
7058
|
type: "object",
|
|
6901
7059
|
properties: {
|
|
7060
|
+
entryPoint: { type: "string" },
|
|
6902
7061
|
printWidth: { type: "number" },
|
|
6903
|
-
classesPerLine: { type: "number" }
|
|
7062
|
+
classesPerLine: { type: "number" },
|
|
7063
|
+
wrapLines: {
|
|
7064
|
+
type: "string",
|
|
7065
|
+
enum: ["overWidth", "all"]
|
|
7066
|
+
},
|
|
7067
|
+
group: {
|
|
7068
|
+
type: "string",
|
|
7069
|
+
enum: [
|
|
7070
|
+
"newLine",
|
|
7071
|
+
"emptyLine",
|
|
7072
|
+
"never"
|
|
7073
|
+
]
|
|
7074
|
+
}
|
|
6904
7075
|
},
|
|
6905
7076
|
additionalProperties: false
|
|
6906
7077
|
}],
|
|
6907
|
-
defaultOptions: [{
|
|
7078
|
+
defaultOptions: [{
|
|
7079
|
+
printWidth: DEFAULT_PRINT_WIDTH,
|
|
7080
|
+
group: DEFAULT_GROUP
|
|
7081
|
+
}],
|
|
6908
7082
|
messages: {
|
|
6909
7083
|
tooLong: "Class string exceeds the print width of {{printWidth}} (longest line is {{length}} characters). Consider splitting into multiple lines or extracting into a component.",
|
|
6910
|
-
tooManyPerLine: "Too many classes on a single line ({{count}}). Maximum allowed per line is {{max}}."
|
|
7084
|
+
tooManyPerLine: "Too many classes on a single line ({{count}}). Maximum allowed per line is {{max}}.",
|
|
7085
|
+
inconsistentWrapping: "Class string is not wrapped consistently. Classes should be re-wrapped to the configured layout within the print width of {{printWidth}}."
|
|
6911
7086
|
}
|
|
6912
7087
|
},
|
|
6913
7088
|
createOnce(context) {
|
|
6914
7089
|
const getPrintWidth = createLazyOptions(context, (o) => o?.printWidth ?? DEFAULT_PRINT_WIDTH);
|
|
6915
7090
|
const getClassesPerLine = createLazyOptions(context, (o) => o?.classesPerLine);
|
|
7091
|
+
const getWrapLines = createLazyOptions(context, (o) => o?.wrapLines);
|
|
7092
|
+
const getGroup = createLazyOptions(context, (o) => o?.group ?? DEFAULT_GROUP);
|
|
7093
|
+
const getDS = createLazyLoader(context);
|
|
6916
7094
|
/**
|
|
6917
7095
|
* The statement's real base indentation — the leading whitespace of the
|
|
6918
7096
|
* source line the opening backtick sits on. NOT `node.loc.start.column`,
|
|
@@ -6922,7 +7100,7 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
6922
7100
|
*/
|
|
6923
7101
|
function deriveBaseIndent(loc) {
|
|
6924
7102
|
const sc = safeSourceCode(context);
|
|
6925
|
-
const line = loc.node.loc?.start.line;
|
|
7103
|
+
const line = loc.templateLine ?? loc.node.loc?.start.line;
|
|
6926
7104
|
if (sc?.lines && typeof line === "number" && line >= 1 && line <= sc.lines.length) {
|
|
6927
7105
|
const src = sc.lines[line - 1] ?? "";
|
|
6928
7106
|
const m = /^[ \t]*/.exec(src);
|
|
@@ -6955,19 +7133,93 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
6955
7133
|
return chunkList(classes, classesPerLine).map((c) => lineIndent + c).join("\n");
|
|
6956
7134
|
}).join("\n");
|
|
6957
7135
|
}
|
|
7136
|
+
/**
|
|
7137
|
+
* `wrapLines: 'all'` fixer (also the single-line conversion for
|
|
7138
|
+
* 'overWidth', which passes `group: 'never'`): the WHOLE quasi is
|
|
7139
|
+
* re-laid-out into `printWidth`-packed lines per the `group` mode, in the
|
|
7140
|
+
* BLOCK form regardless of position — every class run lands on its own
|
|
7141
|
+
* indented line below the backtick.
|
|
7142
|
+
*
|
|
7143
|
+
* A quasi that follows a `${}` (`preserveLeadingSpace`) starts on its own
|
|
7144
|
+
* fresh interior-indented line rather than hanging inline after the
|
|
7145
|
+
* interpolation, and a `${}` that follows the quasi
|
|
7146
|
+
* (`preserveTrailingSpace`) lands alone on the closing interior-indented
|
|
7147
|
+
* line. So no emitted line ever shares its physical row with the opaque
|
|
7148
|
+
* `${expr}`, and every line stays within `printWidth` — bounding the
|
|
7149
|
+
* hanging-join over-width case that per-quasi measurement cannot re-detect.
|
|
7150
|
+
*
|
|
7151
|
+
* The returned value BEGINS with `\n` and ENDS with indentation, so the
|
|
7152
|
+
* newlines already separate it from any bordering `${}`: it must NOT be run
|
|
7153
|
+
* through `preserveSpaces`, which would prepend a stray space before the
|
|
7154
|
+
* leading `\n`.
|
|
7155
|
+
*/
|
|
7156
|
+
function rewrapTemplateToWidth(loc, printWidth, group, prefix) {
|
|
7157
|
+
const baseIndent = deriveBaseIndent(loc);
|
|
7158
|
+
const interiorIndent = baseIndent + INDENT_UNIT;
|
|
7159
|
+
const classes = splitClasses(loc.value);
|
|
7160
|
+
if (classes.length === 0) return loc.value;
|
|
7161
|
+
const packed = packGroupedToWidth(classes, interiorIndent, printWidth, group, prefix);
|
|
7162
|
+
const close = loc.preserveTrailingSpace ? interiorIndent : baseIndent;
|
|
7163
|
+
return "\n" + packed.map((c) => c === "" ? c : interiorIndent + c).join("\n") + "\n" + close;
|
|
7164
|
+
}
|
|
7165
|
+
/**
|
|
7166
|
+
* `wrapLines: 'overWidth'` fixer: non-destructive like `rewrapTemplate`
|
|
7167
|
+
* — only lines exceeding `printWidth` are greedily re-packed, each
|
|
7168
|
+
* keeping its own indent; conforming lines are left verbatim. A
|
|
7169
|
+
* single-line value has no layout to preserve and converts to the block
|
|
7170
|
+
* form. Returns the FINAL value, `${}` boundary spaces included — never
|
|
7171
|
+
* run it through `preserveSpaces`, which would prepend a stray space to
|
|
7172
|
+
* a quasi that legitimately starts with `\n`.
|
|
7173
|
+
*/
|
|
7174
|
+
function rewrapOverBudgetLinesToWidth(loc, printWidth) {
|
|
7175
|
+
const lines = loc.value.split("\n");
|
|
7176
|
+
if (lines.length === 1) return rewrapTemplateToWidth(loc, printWidth, "never", "");
|
|
7177
|
+
const interiorIndent = deriveBaseIndent(loc) + INDENT_UNIT;
|
|
7178
|
+
const width = printWidth - (loc.preserveTrailingSpace ? 1 : 0);
|
|
7179
|
+
const fixed = lines.map((line) => {
|
|
7180
|
+
const classes = splitClasses(line);
|
|
7181
|
+
if (line.length <= printWidth || classes.length <= 1) return line;
|
|
7182
|
+
const m = /^[ \t]*/.exec(line);
|
|
7183
|
+
const lead = m ? m[0] : "";
|
|
7184
|
+
const contIndent = lead.length > 0 ? lead : interiorIndent;
|
|
7185
|
+
return packToWidth(classes, contIndent, width).map((c, i) => i === 0 ? lead + c : contIndent + c).join("\n");
|
|
7186
|
+
}).join("\n");
|
|
7187
|
+
if (loc.preserveTrailingSpace && !/\s$/.test(fixed)) return fixed + " ";
|
|
7188
|
+
return fixed;
|
|
7189
|
+
}
|
|
6958
7190
|
function check(locations) {
|
|
6959
7191
|
const printWidth = getPrintWidth();
|
|
6960
7192
|
const classesPerLine = getClassesPerLine();
|
|
7193
|
+
const wrapLines = getWrapLines();
|
|
7194
|
+
const group = getGroup();
|
|
7195
|
+
const prefix = wrapLines === "all" && group !== "never" && classesPerLine === void 0 ? softGetDS(getDS)?.cache.prefix ?? "" : "";
|
|
6961
7196
|
for (const loc of locations) {
|
|
6962
7197
|
let maxLine = 0;
|
|
6963
|
-
for (const line of loc.value.split("\n"))
|
|
6964
|
-
|
|
7198
|
+
for (const line of loc.value.split("\n")) {
|
|
7199
|
+
if (line.length <= maxLine) continue;
|
|
7200
|
+
if (line.length > printWidth && splitClasses(line).length <= 1) continue;
|
|
7201
|
+
maxLine = line.length;
|
|
7202
|
+
}
|
|
7203
|
+
const data = {
|
|
7204
|
+
length: String(maxLine),
|
|
7205
|
+
printWidth: String(printWidth)
|
|
7206
|
+
};
|
|
7207
|
+
const isMultiline = loc.value.includes("\n");
|
|
7208
|
+
const glued = loc.preserveLeadingSpace === true && !/^\s/.test(loc.value) || loc.preserveTrailingSpace === true && !/\s$/.test(loc.value);
|
|
7209
|
+
if (wrapLines !== void 0 && classesPerLine === void 0 && loc.node.type === "TemplateElement" && !glued && (maxLine > printWidth || wrapLines === "all" && isMultiline)) {
|
|
7210
|
+
const fixedValue = wrapLines === "all" ? rewrapTemplateToWidth(loc, printWidth, group, prefix) : rewrapOverBudgetLinesToWidth(loc, printWidth);
|
|
7211
|
+
if (fixedValue !== loc.value) context.report({
|
|
7212
|
+
node: loc.node,
|
|
7213
|
+
messageId: maxLine > printWidth ? "tooLong" : "inconsistentWrapping",
|
|
7214
|
+
data,
|
|
7215
|
+
fix(fixer) {
|
|
7216
|
+
return fixer.replaceTextRange(loc.range, fixedValue);
|
|
7217
|
+
}
|
|
7218
|
+
});
|
|
7219
|
+
} else if (maxLine > printWidth) context.report({
|
|
6965
7220
|
node: loc.node,
|
|
6966
7221
|
messageId: "tooLong",
|
|
6967
|
-
data
|
|
6968
|
-
length: String(maxLine),
|
|
6969
|
-
printWidth: String(printWidth)
|
|
6970
|
-
}
|
|
7222
|
+
data
|
|
6971
7223
|
});
|
|
6972
7224
|
if (classesPerLine !== void 0) {
|
|
6973
7225
|
const lines = loc.value.split("\n");
|
|
@@ -6981,7 +7233,7 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
6981
7233
|
count: String(maxPerLine),
|
|
6982
7234
|
max: String(classesPerLine)
|
|
6983
7235
|
};
|
|
6984
|
-
if (loc.node.type === "TemplateElement") {
|
|
7236
|
+
if (loc.node.type === "TemplateElement" && !glued) {
|
|
6985
7237
|
const fixedValue = rewrapTemplate(loc, lines, classesPerLine);
|
|
6986
7238
|
context.report({
|
|
6987
7239
|
node: loc.node,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oxlint-tailwindcss",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "Tailwind CSS linting rules for oxlint",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"css",
|
|
@@ -57,13 +57,13 @@
|
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@oxlint/plugins": "catalog:",
|
|
59
59
|
"@tailwindcss/typography": "^0.5.20",
|
|
60
|
-
"@types/node": "^26.
|
|
60
|
+
"@types/node": "^26.5.0",
|
|
61
61
|
"oxlint": "catalog:",
|
|
62
62
|
"tailwindcss-animate": "^1.0.7",
|
|
63
|
-
"tsdown": "^0.
|
|
63
|
+
"tsdown": "^0.23.0",
|
|
64
64
|
"tw-animate-css": "^1.4.0",
|
|
65
65
|
"typescript": "^7.0.2",
|
|
66
|
-
"vitest": "^
|
|
66
|
+
"vitest": "^5.0.0"
|
|
67
67
|
},
|
|
68
68
|
"engines": {
|
|
69
69
|
"node": ">=20"
|