oxlint-tailwindcss 1.10.2 → 1.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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.80.0/node_modules/@oxlint/plugins/index.js
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
- const CACHE_DIR = join(tmpdir(), cacheDirName());
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 = 64 * 1024;
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`. The error is sticky for the lifetime
3689
- * of the process (per cssPath) so subsequent calls don't pay another
3690
- * init-timeout cost. Callers wrap via `safeGetDS` to surface the failure as a
3691
- * single `designSystemUnavailable` diagnostic.
3692
- */
3693
- const BUFFER_SIZE = 4 * 1024 * 1024;
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 = HEADER_INTS * 4;
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, HEADER_INTS * 4, 4);
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 > BUFFER_SIZE - DATA_OFFSET) throw new SortServiceError(`${this.opts.serviceName} request payload is too large (${requestBytes.length} > ${BUFFER_SIZE - DATA_OFFSET} bytes).`, "This is unexpected with typical class lists; please open an issue.");
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, REQUEST_TIMEOUT) === "timed-out") {
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.dropWorker(cssPath);
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) => cache.prefix && k.startsWith(cache.prefix + ":") ? k.slice(cache.prefix.length + 1) : 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);
@@ -6611,6 +6707,32 @@ const noHardcodedColors = defineRule({
6611
6707
  });
6612
6708
  //#endregion
6613
6709
  //#region src/rules/no-contradicting-variants.ts
6710
+ const STATIC_PROP_GROUPS = /* @__PURE__ */ new Map([
6711
+ ["block", "display"],
6712
+ ["inline-block", "display"],
6713
+ ["inline", "display"],
6714
+ ["flex", "display"],
6715
+ ["inline-flex", "display"],
6716
+ ["grid", "display"],
6717
+ ["inline-grid", "display"],
6718
+ ["table", "display"],
6719
+ ["inline-table", "display"],
6720
+ ["table-caption", "display"],
6721
+ ["table-cell", "display"],
6722
+ ["table-column", "display"],
6723
+ ["table-column-group", "display"],
6724
+ ["table-footer-group", "display"],
6725
+ ["table-header-group", "display"],
6726
+ ["table-row-group", "display"],
6727
+ ["table-row", "display"],
6728
+ ["flow-root", "display"],
6729
+ ["contents", "display"],
6730
+ ["list-item", "display"],
6731
+ ["hidden", "display"],
6732
+ ["visible", "visibility"],
6733
+ ["invisible", "visibility"],
6734
+ ["collapse", "visibility"]
6735
+ ]);
6614
6736
  const noContradictingVariants = defineRule({
6615
6737
  meta: {
6616
6738
  type: "suggestion",
@@ -6625,24 +6747,42 @@ const noContradictingVariants = defineRule({
6625
6747
  },
6626
6748
  createOnce(context) {
6627
6749
  const getDS = createLazyLoader(context);
6628
- function variantFactsLookup() {
6629
- const ds = softGetDS(getDS);
6630
- if (!ds) return () => void 0;
6631
- return (variant) => ds.cache.getVariantFacts(variant);
6632
- }
6633
6750
  function check(locations) {
6634
- const factsFor = variantFactsLookup();
6751
+ const ds = softGetDS(getDS);
6752
+ const cache = ds ? ds.cache : null;
6753
+ const factsFor = (v) => ds ? ds.cache.getVariantFacts(v) : void 0;
6754
+ const propsOf = (bare) => {
6755
+ if (cache) {
6756
+ const props = cache.getCssProperties(bare);
6757
+ if (props.length > 0) return props;
6758
+ }
6759
+ const group = STATIC_PROP_GROUPS.get(bare);
6760
+ return group ? [group] : [];
6761
+ };
6635
6762
  for (const loc of locations) {
6636
6763
  if (!isFinalClassList(loc)) continue;
6637
6764
  const classes = splitClasses(loc.value);
6638
6765
  const baseUtilities = /* @__PURE__ */ new Set();
6639
6766
  for (const cls of classes) if (extractVariants(cls).length === 0) baseUtilities.add(cls);
6640
- for (const cls of classes) {
6767
+ for (let i = 0; i < classes.length; i++) {
6768
+ const cls = classes[i];
6641
6769
  const variants = extractVariants(cls);
6642
6770
  if (variants.length === 0) continue;
6643
6771
  if (variants.some((v) => changesTarget(v, factsFor(v)))) continue;
6644
6772
  const utility = extractUtility(cls);
6645
- if (baseUtilities.has(utility)) context.report({
6773
+ if (!baseUtilities.has(utility)) continue;
6774
+ const bare = splitImportant(utility).bare;
6775
+ const candidateProps = propsOf(bare);
6776
+ if (candidateProps.length > 0) {
6777
+ if (classes.some((other, j) => {
6778
+ if (j === i) return false;
6779
+ if (extractVariants(other).some((v) => changesTarget(v, factsFor(v)))) return false;
6780
+ const otherBare = splitImportant(extractUtility(other)).bare;
6781
+ if (otherBare === bare) return false;
6782
+ return propsOf(otherBare).some((p) => candidateProps.includes(p));
6783
+ })) continue;
6784
+ }
6785
+ context.report({
6646
6786
  node: loc.node,
6647
6787
  messageId: "redundantVariant",
6648
6788
  data: {
@@ -6797,12 +6937,7 @@ const consistentVariantOrder = defineRule({
6797
6937
  }
6798
6938
  function reorderClass(cls) {
6799
6939
  const { priorityOf, prefix, factsFor } = resolveForFile();
6800
- let pfx = "";
6801
- let body = cls;
6802
- if (prefix && cls.startsWith(prefix + ":")) {
6803
- pfx = prefix + ":";
6804
- body = cls.slice(prefix.length + 1);
6805
- }
6940
+ const { prefix: pfx, body } = stripProjectPrefix(cls, prefix);
6806
6941
  const variants = extractVariants(body);
6807
6942
  if (variants.length < 2) return null;
6808
6943
  const pseudo = [];
@@ -6883,6 +7018,7 @@ const consistentVariantOrder = defineRule({
6883
7018
  //#endregion
6884
7019
  //#region src/rules/enforce-consistent-line-wrapping.ts
6885
7020
  const DEFAULT_PRINT_WIDTH = 80;
7021
+ const DEFAULT_GROUP = "newLine";
6886
7022
  /** One indentation level added below the statement's base indent for wrapped lines. */
6887
7023
  const INDENT_UNIT = " ";
6888
7024
  /** Group `classes` into chunks of at most `n`, each chunk space-joined. */
@@ -6891,28 +7027,114 @@ function chunkList(classes, n) {
6891
7027
  for (let i = 0; i < classes.length; i += n) chunks.push(classes.slice(i, i + n).join(" "));
6892
7028
  return chunks;
6893
7029
  }
7030
+ /**
7031
+ * Greedily pack `classes` into space-joined lines: a line takes classes until
7032
+ * `indent` + the next one would exceed `width`; a single class over the
7033
+ * budget still gets its own line. Widths count characters, so a tab in
7034
+ * `indent` is 1 column (detection uses the same yardstick, so tabs converge).
7035
+ */
7036
+ function packToWidth(classes, indent, width) {
7037
+ const lines = [];
7038
+ let current = "";
7039
+ for (const cls of classes) {
7040
+ const candidate = current === "" ? cls : current + " " + cls;
7041
+ if (current !== "" && indent.length + candidate.length > width) {
7042
+ lines.push(current);
7043
+ current = cls;
7044
+ } else current = candidate;
7045
+ }
7046
+ if (current !== "") lines.push(current);
7047
+ return lines;
7048
+ }
7049
+ /**
7050
+ * Variant chain used as the grouping key. A Tailwind v4 project prefix
7051
+ * (`tw:`) is structurally a variant but pinned first, so it is stripped
7052
+ * before the key is computed — `tw:flex` keys as a base utility (grouping
7053
+ * with unprefixed component classes) and `tw:hover:x` keys as `hover:`,
7054
+ * matching how consistent-variant-order / enforce-sort-order treat the
7055
+ * prefix. Grouping only: emitted classes are never rewritten.
7056
+ */
7057
+ function groupingKey(cls, prefix) {
7058
+ return getVariantPrefix(stripProjectPrefix(cls, prefix).body);
7059
+ }
7060
+ /**
7061
+ * Split `classes` into runs of consecutive classes sharing the same variant
7062
+ * chain ("hover:", "md:hover:", "" for base utilities), so wrapping breaks
7063
+ * between variant groups rather than mid-group.
7064
+ */
7065
+ function groupByVariantRun(classes, prefix) {
7066
+ const groups = [];
7067
+ let current = [];
7068
+ let currentVariant = null;
7069
+ for (const cls of classes) {
7070
+ const variant = groupingKey(cls, prefix);
7071
+ if (currentVariant !== null && variant !== currentVariant) {
7072
+ groups.push(current);
7073
+ current = [];
7074
+ }
7075
+ currentVariant = variant;
7076
+ current.push(cls);
7077
+ }
7078
+ if (current.length > 0) groups.push(current);
7079
+ return groups;
7080
+ }
7081
+ /**
7082
+ * Pack `classes` per the `group` mode: 'never' packs greedily across
7083
+ * variant-run boundaries, 'newLine' starts each run on its own line(s), and
7084
+ * 'emptyLine' additionally inserts an extra line between runs — emitted as a
7085
+ * blank line with no indent.
7086
+ */
7087
+ function packGroupedToWidth(classes, indent, width, group, prefix) {
7088
+ if (group === "never") return packToWidth(classes, indent, width);
7089
+ const lines = [];
7090
+ for (const run of groupByVariantRun(classes, prefix)) {
7091
+ if (group === "emptyLine" && lines.length > 0) lines.push("");
7092
+ lines.push(...packToWidth(run, indent, width));
7093
+ }
7094
+ return lines;
7095
+ }
6894
7096
  const enforceConsistentLineWrapping = defineRule({
6895
7097
  meta: {
6896
7098
  type: "suggestion",
6897
- docs: { description: "Warn when a class string exceeds the configured print width" },
7099
+ docs: { description: "Warn (and optionally autofix) when a class string exceeds the configured print width or classes-per-line budget" },
6898
7100
  fixable: "whitespace",
6899
7101
  schema: [{
6900
7102
  type: "object",
6901
7103
  properties: {
7104
+ entryPoint: { type: "string" },
6902
7105
  printWidth: { type: "number" },
6903
- classesPerLine: { type: "number" }
7106
+ classesPerLine: { type: "number" },
7107
+ wrapLines: {
7108
+ type: "string",
7109
+ enum: ["overWidth", "all"]
7110
+ },
7111
+ group: {
7112
+ type: "string",
7113
+ enum: [
7114
+ "newLine",
7115
+ "emptyLine",
7116
+ "never"
7117
+ ]
7118
+ }
6904
7119
  },
6905
7120
  additionalProperties: false
6906
7121
  }],
6907
- defaultOptions: [{ printWidth: DEFAULT_PRINT_WIDTH }],
7122
+ defaultOptions: [{
7123
+ printWidth: DEFAULT_PRINT_WIDTH,
7124
+ group: DEFAULT_GROUP
7125
+ }],
6908
7126
  messages: {
6909
7127
  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}}."
7128
+ tooManyPerLine: "Too many classes on a single line ({{count}}). Maximum allowed per line is {{max}}.",
7129
+ inconsistentWrapping: "Class string is not wrapped consistently. Classes should be re-wrapped to the configured layout within the print width of {{printWidth}}."
6911
7130
  }
6912
7131
  },
6913
7132
  createOnce(context) {
6914
7133
  const getPrintWidth = createLazyOptions(context, (o) => o?.printWidth ?? DEFAULT_PRINT_WIDTH);
6915
7134
  const getClassesPerLine = createLazyOptions(context, (o) => o?.classesPerLine);
7135
+ const getWrapLines = createLazyOptions(context, (o) => o?.wrapLines);
7136
+ const getGroup = createLazyOptions(context, (o) => o?.group ?? DEFAULT_GROUP);
7137
+ const getDS = createLazyLoader(context);
6916
7138
  /**
6917
7139
  * The statement's real base indentation — the leading whitespace of the
6918
7140
  * source line the opening backtick sits on. NOT `node.loc.start.column`,
@@ -6922,7 +7144,7 @@ const enforceConsistentLineWrapping = defineRule({
6922
7144
  */
6923
7145
  function deriveBaseIndent(loc) {
6924
7146
  const sc = safeSourceCode(context);
6925
- const line = loc.node.loc?.start.line;
7147
+ const line = loc.templateLine ?? loc.node.loc?.start.line;
6926
7148
  if (sc?.lines && typeof line === "number" && line >= 1 && line <= sc.lines.length) {
6927
7149
  const src = sc.lines[line - 1] ?? "";
6928
7150
  const m = /^[ \t]*/.exec(src);
@@ -6955,19 +7177,93 @@ const enforceConsistentLineWrapping = defineRule({
6955
7177
  return chunkList(classes, classesPerLine).map((c) => lineIndent + c).join("\n");
6956
7178
  }).join("\n");
6957
7179
  }
7180
+ /**
7181
+ * `wrapLines: 'all'` fixer (also the single-line conversion for
7182
+ * 'overWidth', which passes `group: 'never'`): the WHOLE quasi is
7183
+ * re-laid-out into `printWidth`-packed lines per the `group` mode, in the
7184
+ * BLOCK form regardless of position — every class run lands on its own
7185
+ * indented line below the backtick.
7186
+ *
7187
+ * A quasi that follows a `${}` (`preserveLeadingSpace`) starts on its own
7188
+ * fresh interior-indented line rather than hanging inline after the
7189
+ * interpolation, and a `${}` that follows the quasi
7190
+ * (`preserveTrailingSpace`) lands alone on the closing interior-indented
7191
+ * line. So no emitted line ever shares its physical row with the opaque
7192
+ * `${expr}`, and every line stays within `printWidth` — bounding the
7193
+ * hanging-join over-width case that per-quasi measurement cannot re-detect.
7194
+ *
7195
+ * The returned value BEGINS with `\n` and ENDS with indentation, so the
7196
+ * newlines already separate it from any bordering `${}`: it must NOT be run
7197
+ * through `preserveSpaces`, which would prepend a stray space before the
7198
+ * leading `\n`.
7199
+ */
7200
+ function rewrapTemplateToWidth(loc, printWidth, group, prefix) {
7201
+ const baseIndent = deriveBaseIndent(loc);
7202
+ const interiorIndent = baseIndent + INDENT_UNIT;
7203
+ const classes = splitClasses(loc.value);
7204
+ if (classes.length === 0) return loc.value;
7205
+ const packed = packGroupedToWidth(classes, interiorIndent, printWidth, group, prefix);
7206
+ const close = loc.preserveTrailingSpace ? interiorIndent : baseIndent;
7207
+ return "\n" + packed.map((c) => c === "" ? c : interiorIndent + c).join("\n") + "\n" + close;
7208
+ }
7209
+ /**
7210
+ * `wrapLines: 'overWidth'` fixer: non-destructive like `rewrapTemplate`
7211
+ * — only lines exceeding `printWidth` are greedily re-packed, each
7212
+ * keeping its own indent; conforming lines are left verbatim. A
7213
+ * single-line value has no layout to preserve and converts to the block
7214
+ * form. Returns the FINAL value, `${}` boundary spaces included — never
7215
+ * run it through `preserveSpaces`, which would prepend a stray space to
7216
+ * a quasi that legitimately starts with `\n`.
7217
+ */
7218
+ function rewrapOverBudgetLinesToWidth(loc, printWidth) {
7219
+ const lines = loc.value.split("\n");
7220
+ if (lines.length === 1) return rewrapTemplateToWidth(loc, printWidth, "never", "");
7221
+ const interiorIndent = deriveBaseIndent(loc) + INDENT_UNIT;
7222
+ const width = printWidth - (loc.preserveTrailingSpace ? 1 : 0);
7223
+ const fixed = lines.map((line) => {
7224
+ const classes = splitClasses(line);
7225
+ if (line.length <= printWidth || classes.length <= 1) return line;
7226
+ const m = /^[ \t]*/.exec(line);
7227
+ const lead = m ? m[0] : "";
7228
+ const contIndent = lead.length > 0 ? lead : interiorIndent;
7229
+ return packToWidth(classes, contIndent, width).map((c, i) => i === 0 ? lead + c : contIndent + c).join("\n");
7230
+ }).join("\n");
7231
+ if (loc.preserveTrailingSpace && !/\s$/.test(fixed)) return fixed + " ";
7232
+ return fixed;
7233
+ }
6958
7234
  function check(locations) {
6959
7235
  const printWidth = getPrintWidth();
6960
7236
  const classesPerLine = getClassesPerLine();
7237
+ const wrapLines = getWrapLines();
7238
+ const group = getGroup();
7239
+ const prefix = wrapLines === "all" && group !== "never" && classesPerLine === void 0 ? softGetDS(getDS)?.cache.prefix ?? "" : "";
6961
7240
  for (const loc of locations) {
6962
7241
  let maxLine = 0;
6963
- for (const line of loc.value.split("\n")) if (line.length > maxLine) maxLine = line.length;
6964
- if (maxLine > printWidth) context.report({
7242
+ for (const line of loc.value.split("\n")) {
7243
+ if (line.length <= maxLine) continue;
7244
+ if (line.length > printWidth && splitClasses(line).length <= 1) continue;
7245
+ maxLine = line.length;
7246
+ }
7247
+ const data = {
7248
+ length: String(maxLine),
7249
+ printWidth: String(printWidth)
7250
+ };
7251
+ const isMultiline = loc.value.includes("\n");
7252
+ const glued = loc.preserveLeadingSpace === true && !/^\s/.test(loc.value) || loc.preserveTrailingSpace === true && !/\s$/.test(loc.value);
7253
+ if (wrapLines !== void 0 && classesPerLine === void 0 && loc.node.type === "TemplateElement" && !glued && (maxLine > printWidth || wrapLines === "all" && isMultiline)) {
7254
+ const fixedValue = wrapLines === "all" ? rewrapTemplateToWidth(loc, printWidth, group, prefix) : rewrapOverBudgetLinesToWidth(loc, printWidth);
7255
+ if (fixedValue !== loc.value) context.report({
7256
+ node: loc.node,
7257
+ messageId: maxLine > printWidth ? "tooLong" : "inconsistentWrapping",
7258
+ data,
7259
+ fix(fixer) {
7260
+ return fixer.replaceTextRange(loc.range, fixedValue);
7261
+ }
7262
+ });
7263
+ } else if (maxLine > printWidth) context.report({
6965
7264
  node: loc.node,
6966
7265
  messageId: "tooLong",
6967
- data: {
6968
- length: String(maxLine),
6969
- printWidth: String(printWidth)
6970
- }
7266
+ data
6971
7267
  });
6972
7268
  if (classesPerLine !== void 0) {
6973
7269
  const lines = loc.value.split("\n");
@@ -6981,7 +7277,7 @@ const enforceConsistentLineWrapping = defineRule({
6981
7277
  count: String(maxPerLine),
6982
7278
  max: String(classesPerLine)
6983
7279
  };
6984
- if (loc.node.type === "TemplateElement") {
7280
+ if (loc.node.type === "TemplateElement" && !glued) {
6985
7281
  const fixedValue = rewrapTemplate(loc, lines, classesPerLine);
6986
7282
  context.report({
6987
7283
  node: loc.node,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxlint-tailwindcss",
3
- "version": "1.10.2",
3
+ "version": "1.11.1",
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.2.0",
60
+ "@types/node": "^26.5.0",
61
61
  "oxlint": "catalog:",
62
62
  "tailwindcss-animate": "^1.0.7",
63
- "tsdown": "^0.22.14",
63
+ "tsdown": "^0.23.0",
64
64
  "tw-animate-css": "^1.4.0",
65
65
  "typescript": "^7.0.2",
66
- "vitest": "^4.1.10"
66
+ "vitest": "^5.0.0"
67
67
  },
68
68
  "engines": {
69
69
  "node": ">=20"