oxlint-tailwindcss 1.14.0 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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
- //#region ../../node_modules/.pnpm/@oxlint+plugins@1.85.0/node_modules/@oxlint/plugins/index.js
7
+ //#region ../../node_modules/.pnpm/@oxlint+plugins@1.87.0/node_modules/@oxlint/plugins/index.js
8
8
  /**
9
9
  * Define a plugin.
10
10
  *
@@ -248,6 +248,124 @@ function settingsKey(settings) {
248
248
  return JSON.stringify(settings?.tailwindcss) ?? "";
249
249
  }
250
250
  //#endregion
251
+ //#region src/utils/css-properties.ts
252
+ /**
253
+ * CSS property names (standard, SVG and `-ms-`), from csstype's `*PropertiesHyphen`
254
+ * interfaces, minus the 15 that are also Tailwind classes (`flex`, `grid`, `border`,
255
+ * `container`, `transition`, …). A test holds that no name here is a class.
256
+ *
257
+ * An object key with one of these names is a style declaration, never a class:
258
+ * Solid, Vue, Qwik and Lit's `styleMap` take kebab-case keys, which the default
259
+ * `^styles?$` variable pattern reaches (`const style = { 'background-color': c }`).
260
+ * `-webkit-` / `-moz-` keys are matched by prefix instead; `-ms-` only by name,
261
+ * since `-ms-4` is a negative margin.
262
+ */
263
+ const CSS_PROPERTY_NAMES = new Set(`
264
+ -ms-accelerator -ms-block-progression -ms-content-zoom-chaining -ms-content-zoom-limit
265
+ -ms-content-zoom-limit-max -ms-content-zoom-limit-min -ms-content-zoom-snap
266
+ -ms-content-zoom-snap-points -ms-content-zoom-snap-type -ms-content-zooming -ms-filter -ms-flex
267
+ -ms-flex-direction -ms-flex-positive -ms-flow-from -ms-flow-into -ms-grid-columns -ms-grid-rows
268
+ -ms-high-contrast-adjust -ms-hyphenate-limit-chars -ms-hyphenate-limit-lines
269
+ -ms-hyphenate-limit-zone -ms-hyphens -ms-ime-align -ms-line-break -ms-order -ms-overflow-style
270
+ -ms-overflow-x -ms-overflow-y -ms-scroll-chaining -ms-scroll-limit -ms-scroll-limit-x-max
271
+ -ms-scroll-limit-x-min -ms-scroll-limit-y-max -ms-scroll-limit-y-min -ms-scroll-rails
272
+ -ms-scroll-snap-points-x -ms-scroll-snap-points-y -ms-scroll-snap-type -ms-scroll-snap-x
273
+ -ms-scroll-snap-y -ms-scroll-translation -ms-scrollbar-arrow-color -ms-scrollbar-base-color
274
+ -ms-scrollbar-darkshadow-color -ms-scrollbar-face-color -ms-scrollbar-highlight-color
275
+ -ms-scrollbar-shadow-color -ms-scrollbar-track-color -ms-text-autospace
276
+ -ms-text-combine-horizontal -ms-text-overflow -ms-touch-action -ms-touch-select -ms-transform
277
+ -ms-transform-origin -ms-transition -ms-transition-delay -ms-transition-duration
278
+ -ms-transition-property -ms-transition-timing-function -ms-user-select -ms-word-break
279
+ -ms-wrap-flow -ms-wrap-margin -ms-wrap-through -ms-writing-mode accent-color align-content
280
+ align-items align-self align-tracks alignment-baseline all anchor-name anchor-scope animation
281
+ animation-composition animation-delay animation-direction animation-duration
282
+ animation-fill-mode animation-iteration-count animation-name animation-play-state
283
+ animation-range animation-range-end animation-range-start animation-timeline
284
+ animation-timing-function appearance aspect-ratio backdrop-filter backface-visibility
285
+ background background-attachment background-blend-mode background-clip background-color
286
+ background-image background-origin background-position background-position-x
287
+ background-position-y background-repeat background-size baseline-shift block-size border-block
288
+ border-block-color border-block-end border-block-end-color border-block-end-style
289
+ border-block-end-width border-block-start border-block-start-color border-block-start-style
290
+ border-block-start-width border-block-style border-block-width border-bottom
291
+ border-bottom-color border-bottom-left-radius border-bottom-right-radius border-bottom-style
292
+ border-bottom-width border-color border-end-end-radius border-end-start-radius border-image
293
+ border-image-outset border-image-repeat border-image-slice border-image-source
294
+ border-image-width border-inline border-inline-color border-inline-end border-inline-end-color
295
+ border-inline-end-style border-inline-end-width border-inline-start border-inline-start-color
296
+ border-inline-start-style border-inline-start-width border-inline-style border-inline-width
297
+ border-left border-left-color border-left-style border-left-width border-radius border-right
298
+ border-right-color border-right-style border-right-width border-spacing border-start-end-radius
299
+ border-start-start-radius border-style border-top border-top-color border-top-left-radius
300
+ border-top-right-radius border-top-style border-top-width border-width bottom
301
+ box-decoration-break box-shadow box-sizing break-after break-before break-inside caption-side
302
+ caret caret-color caret-shape clear clip clip-path clip-rule color color-adjust
303
+ color-interpolation color-interpolation-filters color-rendering color-scheme column-count
304
+ column-fill column-gap column-rule column-rule-color column-rule-style column-rule-width
305
+ column-span column-width columns contain contain-intrinsic-block-size contain-intrinsic-height
306
+ contain-intrinsic-inline-size contain-intrinsic-size contain-intrinsic-width container-name
307
+ container-type content content-visibility counter-increment counter-reset counter-set cursor cx
308
+ cy d direction display dominant-baseline empty-cells field-sizing fill fill-opacity fill-rule
309
+ filter flex-basis flex-direction flex-flow float flood-color flood-opacity font font-family
310
+ font-feature-settings font-kerning font-language-override font-optical-sizing font-palette
311
+ font-size font-size-adjust font-smooth font-stretch font-style font-synthesis
312
+ font-synthesis-position font-synthesis-small-caps font-synthesis-style font-synthesis-weight
313
+ font-variant font-variant-alternates font-variant-caps font-variant-east-asian
314
+ font-variant-emoji font-variant-ligatures font-variant-numeric font-variant-position
315
+ font-variation-settings font-weight font-width forced-color-adjust gap
316
+ glyph-orientation-vertical grid-area grid-auto-columns grid-auto-flow grid-auto-rows
317
+ grid-column grid-column-end grid-column-start grid-row grid-row-end grid-row-start
318
+ grid-template grid-template-areas grid-template-columns grid-template-rows hanging-punctuation
319
+ height hyphenate-character hyphenate-limit-chars hyphens image-orientation image-rendering
320
+ image-resolution initial-letter initial-letter-align inline-size inset inset-block
321
+ inset-block-end inset-block-start inset-inline inset-inline-end inset-inline-start
322
+ interpolate-size isolation justify-content justify-items justify-self justify-tracks left
323
+ letter-spacing lighting-color line-break line-clamp line-height line-height-step list-style
324
+ list-style-image list-style-position list-style-type margin margin-block margin-block-end
325
+ margin-block-start margin-bottom margin-inline margin-inline-end margin-inline-start
326
+ margin-left margin-right margin-top margin-trim marker marker-end marker-mid marker-start mask
327
+ mask-border mask-border-mode mask-border-outset mask-border-repeat mask-border-slice
328
+ mask-border-source mask-border-width mask-clip mask-composite mask-image mask-mode mask-origin
329
+ mask-position mask-size mask-type masonry-auto-flow math-depth math-shift math-style
330
+ max-block-size max-height max-inline-size max-lines max-width min-block-size min-height
331
+ min-inline-size min-width mix-blend-mode motion motion-distance motion-path motion-rotation
332
+ object-fit object-position object-view-box offset offset-anchor offset-distance offset-path
333
+ offset-position offset-rotate offset-rotation opacity order orphans outline-color
334
+ outline-offset outline-style outline-width overflow overflow-anchor overflow-block
335
+ overflow-clip-box overflow-clip-margin overflow-inline overflow-wrap overflow-x overflow-y
336
+ overlay overscroll-behavior overscroll-behavior-block overscroll-behavior-inline
337
+ overscroll-behavior-x overscroll-behavior-y padding padding-block padding-block-end
338
+ padding-block-start padding-bottom padding-inline padding-inline-end padding-inline-start
339
+ padding-left padding-right padding-top page paint-order perspective perspective-origin
340
+ place-content place-items place-self pointer-events position position-anchor position-area
341
+ position-try position-try-fallbacks position-try-order position-visibility print-color-adjust
342
+ quotes r right rotate row-gap ruby-align ruby-merge ruby-overhang ruby-position rx ry scale
343
+ scroll-behavior scroll-initial-target scroll-margin scroll-margin-block scroll-margin-block-end
344
+ scroll-margin-block-start scroll-margin-bottom scroll-margin-inline scroll-margin-inline-end
345
+ scroll-margin-inline-start scroll-margin-left scroll-margin-right scroll-margin-top
346
+ scroll-padding scroll-padding-block scroll-padding-block-end scroll-padding-block-start
347
+ scroll-padding-bottom scroll-padding-inline scroll-padding-inline-end
348
+ scroll-padding-inline-start scroll-padding-left scroll-padding-right scroll-padding-top
349
+ scroll-snap-align scroll-snap-margin scroll-snap-margin-bottom scroll-snap-margin-left
350
+ scroll-snap-margin-right scroll-snap-margin-top scroll-snap-stop scroll-snap-type
351
+ scroll-timeline scroll-timeline-axis scroll-timeline-name scrollbar-color scrollbar-gutter
352
+ scrollbar-width shape-image-threshold shape-margin shape-outside shape-rendering speak-as
353
+ stop-color stop-opacity stroke stroke-color stroke-dasharray stroke-dashoffset stroke-linecap
354
+ stroke-linejoin stroke-miterlimit stroke-opacity stroke-width tab-size table-layout text-align
355
+ text-align-last text-anchor text-autospace text-box text-box-edge text-box-trim
356
+ text-combine-upright text-decoration text-decoration-color text-decoration-line
357
+ text-decoration-skip text-decoration-skip-ink text-decoration-style text-decoration-thickness
358
+ text-emphasis text-emphasis-color text-emphasis-position text-emphasis-style text-indent
359
+ text-orientation text-overflow text-rendering text-shadow text-size-adjust text-spacing-trim
360
+ text-transform text-underline-offset text-underline-position text-wrap-mode text-wrap-style
361
+ timeline-scope top touch-action transform-box transform-origin transform-style
362
+ transition-behavior transition-delay transition-duration transition-property
363
+ transition-timing-function translate unicode-bidi user-select vector-effect vertical-align
364
+ view-timeline view-timeline-axis view-timeline-inset view-timeline-name view-transition-class
365
+ view-transition-name visibility white-space white-space-collapse widows width will-change
366
+ word-break word-spacing word-wrap writing-mode x y z-index zoom
367
+ `.trim().split(/\s+/));
368
+ //#endregion
251
369
  //#region src/utils/levenshtein.ts
252
370
  let bufA = /* @__PURE__ */ new Int32Array(64);
253
371
  let bufB = /* @__PURE__ */ new Int32Array(64);
@@ -903,7 +1021,7 @@ function extractFromExpression(node, out = []) {
903
1021
  return out;
904
1022
  }
905
1023
  if (node.type === "ObjectExpression") {
906
- for (const prop of node.properties) if (prop.type === "Property" && prop.key.type === "Literal" && typeof prop.key.value === "string") out.push({
1024
+ for (const prop of node.properties) if (prop.type === "Property" && prop.key.type === "Literal" && typeof prop.key.value === "string" && !isStyleDeclaration(prop.key.value, prop.value)) out.push({
907
1025
  value: prop.key.value,
908
1026
  node: prop.key,
909
1027
  range: [prop.key.range[0] + 1, prop.key.range[1] - 1]
@@ -912,6 +1030,22 @@ function extractFromExpression(node, out = []) {
912
1030
  }
913
1031
  return out;
914
1032
  }
1033
+ const CUSTOM_PROPERTY = /^--\S+$/;
1034
+ const VENDOR_PROPERTY = /^-(?:webkit|moz)-[a-z-]+$/;
1035
+ /**
1036
+ * Whether an object entry is a style declaration rather than a conditional
1037
+ * class. The default `^styles?$` variable pattern reaches style objects of
1038
+ * every framework: React's `CSSProperties` (custom properties are quoted),
1039
+ * Solid / Vue / Qwik / Lit's kebab-case keys, Angular's `'width.px': 100`.
1040
+ *
1041
+ * - The key is a custom property, a vendor-prefixed or a CSS property name.
1042
+ * - Or the value is a string, number or template literal: in a class map the
1043
+ * value is a condition, and a constant one never is (`{ flex: '1 1 0%' }`).
1044
+ */
1045
+ function isStyleDeclaration(key, value) {
1046
+ if (CUSTOM_PROPERTY.test(key) || VENDOR_PROPERTY.test(key) || CSS_PROPERTY_NAMES.has(key)) return true;
1047
+ return value.type === "TemplateLiteral" || value.type === "Literal" && (typeof value.value === "string" || typeof value.value === "number");
1048
+ }
915
1049
  function appendFromTemplateLiteral(node, out) {
916
1050
  for (let i = 0; i < node.quasis.length; i++) {
917
1051
  const quasi = node.quasis[i];
@@ -1252,6 +1386,99 @@ const noUnnecessaryWhitespace = defineRule({
1252
1386
  }
1253
1387
  });
1254
1388
  //#endregion
1389
+ //#region src/utils/report.ts
1390
+ /**
1391
+ * Shared reporters: `reportClassReplacements` for the "first-as-fix,
1392
+ * rest-as-suggestion" pattern, `reportClassSuggestion` for a suggestion alone.
1393
+ *
1394
+ * Nine rules (enforce-canonical, enforce-logical, enforce-physical,
1395
+ * enforce-consistent-variable-syntax, enforce-consistent-important-position,
1396
+ * enforce-negative-arbitrary-values, no-deprecated-classes,
1397
+ * no-unnecessary-arbitrary-value, prefer-theme-tokens) all emit
1398
+ * replacements via the same shape:
1399
+ *
1400
+ * 1. Collect `{ cls, replacement }` entries from a class string.
1401
+ * 2. Rebuild the full class string with replacements applied.
1402
+ * 3. Emit ONE diagnostic with the autofix attached.
1403
+ * 4. Emit one MORE diagnostic per remaining offender, each carrying
1404
+ * the same autofix as a `suggest`.
1405
+ *
1406
+ * oxlint's fixer is single-shot per AST node, so multiple offenders in the
1407
+ * same class string can only get one mechanical fix; the rest stay as
1408
+ * suggestions the IDE can offer interactively.
1409
+ */
1410
+ /**
1411
+ * Emit autofix + suggestion diagnostics for a list of class replacements.
1412
+ *
1413
+ * If `offending` is empty, no-op. The fixer's `replaceTextRange` is shared
1414
+ * across all diagnostics — the first one is the primary fix, the rest carry
1415
+ * the same fix as a suggestion (oxlint can only apply one autofix per node).
1416
+ */
1417
+ function reportClassReplacements(context, loc, split, classes, offending, options) {
1418
+ if (offending.length === 0) return;
1419
+ const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
1420
+ const fixedValue = rebuildClassString(split, classes.map((c) => replacements.get(c) ?? c));
1421
+ const replacementKey = options.replacementKey ?? "replacement";
1422
+ const suggestMessageId = options.suggestMessageId ?? "suggestReplace";
1423
+ const applyFix = (fixer) => fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
1424
+ const report = context.report;
1425
+ for (let i = 0; i < offending.length; i++) {
1426
+ const { cls, replacement } = offending[i];
1427
+ const messageId = offending[i].messageId ?? options.messageId;
1428
+ const primaryData = {
1429
+ className: cls,
1430
+ [replacementKey]: replacement
1431
+ };
1432
+ if (i === 0) report({
1433
+ node: loc.node,
1434
+ messageId,
1435
+ data: primaryData,
1436
+ fix: applyFix
1437
+ });
1438
+ else report({
1439
+ node: loc.node,
1440
+ messageId,
1441
+ data: primaryData,
1442
+ suggest: [{
1443
+ messageId: suggestMessageId,
1444
+ data: {
1445
+ className: cls,
1446
+ replacement
1447
+ },
1448
+ fix: applyFix
1449
+ }]
1450
+ });
1451
+ }
1452
+ }
1453
+ /**
1454
+ * Report ONE class with a quick-fix suggestion and no autofix: for rewrites the
1455
+ * rule can name but must not apply on its own (`prefer-scale-token`'s numeric
1456
+ * equivalence, a typo's closest class, a canonical form that is not the same
1457
+ * CSS).
1458
+ *
1459
+ * The suggestion replaces only `cls`, never the other offenders of the string,
1460
+ * and it is rebuilt through the splitter, so the `\n` + indent that
1461
+ * `enforce-consistent-line-wrapping` introduces survives it. It never reaches
1462
+ * `reportClassReplacements`' shared autofix.
1463
+ */
1464
+ function reportClassSuggestion(context, loc, split, classes, { cls, replacement }, options) {
1465
+ const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? replacement : c));
1466
+ const report = context.report;
1467
+ report({
1468
+ node: loc.node,
1469
+ messageId: options.messageId,
1470
+ data: options.data,
1471
+ suggest: [{
1472
+ messageId: options.suggestMessageId ?? "suggestReplace",
1473
+ data: {
1474
+ className: cls,
1475
+ replacement
1476
+ },
1477
+ fix: (fixer) => fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue))
1478
+ }]
1479
+ });
1480
+ }
1481
+ //#endregion
1255
1482
  //#region src/utils/class-parser.ts
1256
1483
  /**
1257
1484
  * Extracts variants from a class string, respecting bracket depth.
@@ -4511,41 +4738,107 @@ var DesignSystemWorker = class {
4511
4738
  * after the first few files any given class has been seen, and every
4512
4739
  * subsequent lookup is O(1).
4513
4740
  */
4514
- const isReason = (x) => x === "variant" || x === "selector" || x === "value";
4515
- /** A persisted `[canonical, safe, reason?]` entry, or null when it isn't one. */
4741
+ const isReason = (x) => x === "variant" || x === "selector" || x === "value" || x === "variable";
4742
+ const isVariableList = (x) => Array.isArray(x) && x.length > 0 && x.every((v) => typeof v === "string" && v.startsWith("--"));
4743
+ /**
4744
+ * A persisted `[canonical, safe, reason?, variables?]` entry, or null when it
4745
+ * isn't one. The variables come with `'variable'` and only with it: a
4746
+ * `'variable'` entry without them would render a message naming nothing.
4747
+ */
4516
4748
  function fromPersisted(entry) {
4517
4749
  if (!Array.isArray(entry) || typeof entry[0] !== "string" || typeof entry[1] !== "boolean") return null;
4518
- if (entry.length > 2 && !isReason(entry[2])) return null;
4519
- return entry.length > 2 ? {
4750
+ if (entry.length === 2) return {
4751
+ canonical: entry[0],
4752
+ safe: entry[1]
4753
+ };
4754
+ if (!isReason(entry[2])) return null;
4755
+ if (entry[2] !== "variable") return entry.length === 3 ? {
4520
4756
  canonical: entry[0],
4521
4757
  safe: entry[1],
4522
4758
  reason: entry[2]
4523
- } : {
4759
+ } : null;
4760
+ if (entry.length !== 4 || !isVariableList(entry[3])) return null;
4761
+ return {
4524
4762
  canonical: entry[0],
4525
- safe: entry[1]
4763
+ safe: entry[1],
4764
+ reason: entry[2],
4765
+ variables: entry[3]
4526
4766
  };
4527
4767
  }
4528
- const toPersisted = (r) => r.reason ? [
4529
- r.canonical,
4530
- r.safe,
4531
- r.reason
4532
- ] : [r.canonical, r.safe];
4768
+ function toPersisted(r) {
4769
+ if (r.reason === "variable") return [
4770
+ r.canonical,
4771
+ r.safe,
4772
+ r.reason,
4773
+ r.variables
4774
+ ];
4775
+ return r.reason ? [
4776
+ r.canonical,
4777
+ r.safe,
4778
+ r.reason
4779
+ ] : [r.canonical, r.safe];
4780
+ }
4533
4781
  const WORKER_SCRIPT$2 = makeWorkerScript(`async (ds, request, env) => {
4534
4782
  const { classes, rem } = request;
4535
4783
  const options = rem ? { rem } : undefined;
4536
4784
  const OWN_CLASS = /("(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*')|(^|[{};])(\\s*)\\.(?:\\\\[0-9a-fA-F]{1,6}\\s?|\\\\[^0-9a-fA-F\\s]|[\\w-])+/g;
4537
- const declsOf = (d, cls) => {
4785
+ const rawOf = (d, cls) => {
4538
4786
  let out;
4539
4787
  try { out = d.candidatesToCss([cls]); } catch (e) { return null; }
4540
- if (!out || !out[0]) return null;
4541
- return out[0]
4542
- .replace(OWN_CLASS, (m, str, start, ws) => (str !== undefined ? str : start + ws + '.__c'))
4543
- .replace(/\\s+/g, ' ')
4544
- .trim();
4788
+ return out && out[0] ? out[0] : null;
4545
4789
  };
4790
+ const own = (css) => css
4791
+ .replace(OWN_CLASS, (m, str, start, ws) => (str !== undefined ? str : start + ws + '.__c'))
4792
+ .replace(/\\s+/g, ' ')
4793
+ .trim();
4546
4794
  // Declarations only, selectors and at-rule preludes dropped: equal for two
4547
4795
  // rules that set the same things on different selectors.
4548
4796
  const declarationsOf = (css) => css.replace(/[^{};]+\\{/g, '').replace(/\\}/g, '').replace(/\\s+/g, ' ').trim();
4797
+ // A mirror (#217) is a --tw-* declaration that repeats, verbatim, the value of
4798
+ // a sibling real property in the same block: "--tw-font-weight: var(--x)" next
4799
+ // to "font-weight: var(--x)". Tailwind drops exactly these (and their
4800
+ // @property rules) when it signs a class to canonicalize it, which is why it
4801
+ // proposes "[font-weight:var(--x)]" -> "font-(--x)". Other utilities read
4802
+ // those variables (a text-* size reads --tw-font-weight), so the two forms are
4803
+ // not the same CSS. candidatesToCss prints one declaration per line, so this
4804
+ // walks lines: a value holding a ";" (content: ';') stays whole.
4805
+ const stripMirrors = (css) => {
4806
+ const lines = css.split('\\n');
4807
+ const removed = new Set();
4808
+ const drop = new Set();
4809
+ const blocks = [];
4810
+ for (let i = 0; i < lines.length; i++) {
4811
+ const t = lines[i].trim();
4812
+ if (t.endsWith('{')) { blocks.push([]); continue; }
4813
+ if (t === '}') {
4814
+ const decls = blocks.pop() || [];
4815
+ for (const d of decls) {
4816
+ if (!d.prop.startsWith('--tw-')) continue;
4817
+ if (decls.some((o) => !o.prop.startsWith('--') && o.value === d.value)) {
4818
+ drop.add(d.line);
4819
+ removed.add(d.prop);
4820
+ }
4821
+ }
4822
+ continue;
4823
+ }
4824
+ const colon = t.indexOf(':');
4825
+ if (blocks.length > 0 && colon > 0 && t.endsWith(';')) {
4826
+ blocks[blocks.length - 1].push({ line: i, prop: t.slice(0, colon).trim(), value: t.slice(colon + 1, -1).trim() });
4827
+ }
4828
+ }
4829
+ if (removed.size === 0) return { css, removed };
4830
+ const kept = [];
4831
+ for (let i = 0; i < lines.length; i++) {
4832
+ if (drop.has(i)) continue;
4833
+ const t = lines[i].trim();
4834
+ if (t.startsWith('@property ') && t.endsWith('{') && removed.has(t.slice(10, -1).trim())) {
4835
+ while (i < lines.length && lines[i].trim() !== '}') i++;
4836
+ continue;
4837
+ }
4838
+ kept.push(lines[i]);
4839
+ }
4840
+ return { css: kept.join('\\n'), removed };
4841
+ };
4549
4842
  const results = [];
4550
4843
  for (const cls of classes) {
4551
4844
  // A malformed/mid-typing arbitrary value (e.g. \`px-[calc(var(--a)+)]\`) can
@@ -4562,19 +4855,37 @@ const WORKER_SCRIPT$2 = makeWorkerScript(`async (ds, request, env) => {
4562
4855
  }
4563
4856
  const canonical = r[0] ?? cls;
4564
4857
  if (canonical === cls) { results.push({ canonical: cls, safe: true }); continue; }
4565
- const a = declsOf(ds, cls);
4566
- const b = declsOf(ds, canonical);
4858
+ const rawA = rawOf(ds, cls);
4859
+ const rawB = rawOf(ds, canonical);
4860
+ const a = rawA === null ? null : own(rawA);
4861
+ const b = rawB === null ? null : own(rawB);
4567
4862
  if (a !== null && b !== null && a === b) { results.push({ canonical, safe: true }); continue; }
4568
4863
  if (a === null || b === null) { results.push({ canonical, safe: false }); continue; }
4569
- if (declarationsOf(a) !== declarationsOf(b)) { results.push({ canonical, safe: false, reason: 'value' }); continue; }
4864
+ const ma = stripMirrors(rawA);
4865
+ const mb = stripMirrors(rawB);
4866
+ const sa = own(ma.css);
4867
+ const sb = own(mb.css);
4868
+ if (sa === sb) {
4869
+ // The same CSS once the mirrors are gone. It is 'variable' only when the
4870
+ // canonical form ADDS mirrors and drops none; any other way to get here
4871
+ // differs in something else.
4872
+ const added = [...mb.removed].filter((v) => !ma.removed.has(v)).sort();
4873
+ const dropped = [...ma.removed].some((v) => !mb.removed.has(v));
4874
+ results.push(added.length > 0 && !dropped
4875
+ ? { canonical, safe: false, reason: 'variable', variables: added }
4876
+ : { canonical, safe: false, reason: 'value' });
4877
+ continue;
4878
+ }
4879
+ if (declarationsOf(sa) !== declarationsOf(sb)) { results.push({ canonical, safe: false, reason: 'value' }); continue; }
4570
4880
  // Only the selector differs. Whether the PROJECT made it differ is what
4571
4881
  // stock Tailwind answers: the same two classes, compiled without the
4572
4882
  // project's CSS. Equal there means a project-defined variant.
4573
4883
  let stock = null;
4574
4884
  try { stock = await env.loadStock(); } catch (e) {}
4575
- const sa = stock && declsOf(stock, cls);
4576
- const sb = stock && declsOf(stock, canonical);
4577
- results.push({ canonical, safe: false, reason: sa && sb && sa === sb ? 'variant' : 'selector' });
4885
+ const xa = stock && rawOf(stock, cls);
4886
+ const xb = stock && rawOf(stock, canonical);
4887
+ const same = xa && xb && own(stripMirrors(xa).css) === own(stripMirrors(xb).css);
4888
+ results.push({ canonical, safe: false, reason: same ? 'variant' : 'selector' });
4578
4889
  }
4579
4890
  return results;
4580
4891
  }`, "", `(ds, warm) => {
@@ -4798,7 +5109,12 @@ function canonicalizeClassesSync(cssPath, classes, rem) {
4798
5109
  canonical: roundRemValue(raw.canonical),
4799
5110
  safe: raw.safe
4800
5111
  };
4801
- if (raw.reason) value.reason = raw.reason;
5112
+ if (raw.reason === "variable") {
5113
+ if (isVariableList(raw.variables)) {
5114
+ value.reason = raw.reason;
5115
+ value.variables = raw.variables;
5116
+ } else value.reason = "value";
5117
+ } else if (raw.reason) value.reason = raw.reason;
4802
5118
  canonCache.set(cachePrefix + cls, value);
4803
5119
  out[missingIdx[j]] = value;
4804
5120
  }
@@ -4902,10 +5218,19 @@ function resolveByGlobMapping(mappings, filePath, baseDir) {
4902
5218
  }
4903
5219
  /**
4904
5220
  * oxlint discovers nested configuration by walking up from each linted file
4905
- * looking for files with these names. We mirror that walk to find the config
4906
- * directory a relative `entryPoint` should be anchored to.
4907
- */
4908
- const OXLINT_CONFIG_NAMES = [".oxlintrc.json"];
5221
+ * looking for files with these names (oxlint 1.87: JSON, JSONC, and the JS
5222
+ * configs it loads through Node). We mirror that walk to find the config
5223
+ * directory a relative `entryPoint` should be anchored to — which is also
5224
+ * where an `oxlint.config.ts` passes it through `oxlint-tailwindcss/config`.
5225
+ * Not `vite.config.*`: under Vite+ a package's own Vite config needn't hold
5226
+ * any lint config, and nested configs aren't discovered there anyway.
5227
+ */
5228
+ const OXLINT_CONFIG_NAMES = [
5229
+ ".oxlintrc.json",
5230
+ ".oxlintrc.jsonc",
5231
+ "oxlint.config.ts",
5232
+ "oxlint.config.mts"
5233
+ ];
4909
5234
  /** Memoizes the nearest-config walk per starting directory (cleared in tests). */
4910
5235
  const nearestConfigDirCache = /* @__PURE__ */ new Map();
4911
5236
  /**
@@ -4941,8 +5266,10 @@ function nearestConfigDir(filePath) {
4941
5266
  * absolute path.
4942
5267
  *
4943
5268
  * Absolute paths are returned normalized and untouched. A **relative** path is
4944
- * anchored to the directory of the nearest enclosing `.oxlintrc.json` (the
4945
- * config oxlint applies to the file), with the CWD as a single fallback:
5269
+ * anchored to the directory of the nearest enclosing oxlint config
5270
+ * (`.oxlintrc.json`, `.oxlintrc.jsonc`, `oxlint.config.ts` or
5271
+ * `oxlint.config.mts` — the config oxlint applies to the file), with the CWD
5272
+ * as a single fallback:
4946
5273
  *
4947
5274
  * 1. nearest config dir — if its candidate file exists, use it;
4948
5275
  * 2. CWD — if its candidate file exists, use it;
@@ -5004,7 +5331,7 @@ function getLoadedDesignSystem(cssPath, settings, engineInfo) {
5004
5331
  try {
5005
5332
  mtime = (0, node_fs.statSync)(resolvedPath).mtimeMs;
5006
5333
  } catch (cause) {
5007
- throw new DesignSystemLoadError(`Could not stat CSS entry point: ${resolvedPath}`, "Check that the file exists and is readable. A relative `entryPoint` is resolved against the nearest `.oxlintrc.json` directory, falling back to the oxlint working directory.", { cause: cause instanceof Error ? cause : void 0 });
5334
+ throw new DesignSystemLoadError(`Could not stat CSS entry point: ${resolvedPath}`, "Check that the file exists and is readable. A relative `entryPoint` is resolved against the directory of the nearest oxlint config (`.oxlintrc.json`, `.oxlintrc.jsonc`, `oxlint.config.ts` or `oxlint.config.mts`), falling back to the oxlint working directory.", { cause: cause instanceof Error ? cause : void 0 });
5008
5335
  }
5009
5336
  const cached = dsCache.get(resolvedPath);
5010
5337
  if (cached && cached.mtime === mtime) return {
@@ -5327,21 +5654,12 @@ const noUnknownClasses = defineRule({
5327
5654
  }
5328
5655
  /** Replace one class in the location and report, with a quick-fix suggestion. */
5329
5656
  function reportWithSuggestion(loc, classes, cls, replacement, messageId, data, split) {
5330
- const fixedValue = rebuildClassString(split, classes.map((c) => c === cls ? replacement : c));
5331
- context.report({
5332
- node: loc.node,
5657
+ reportClassSuggestion(context, loc, split, classes, {
5658
+ cls,
5659
+ replacement
5660
+ }, {
5333
5661
  messageId,
5334
- data,
5335
- suggest: [{
5336
- messageId: "suggestReplace",
5337
- data: {
5338
- className: cls,
5339
- replacement
5340
- },
5341
- fix(fixer) {
5342
- return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
5343
- }
5344
- }]
5662
+ data
5345
5663
  });
5346
5664
  }
5347
5665
  function check(locations) {
@@ -5928,69 +6246,6 @@ const noConflictingClasses = defineRule({
5928
6246
  }
5929
6247
  });
5930
6248
  //#endregion
5931
- //#region src/utils/report.ts
5932
- /**
5933
- * Shared reporter for the "first-as-fix, rest-as-suggestion" pattern.
5934
- *
5935
- * Nine rules (enforce-canonical, enforce-logical, enforce-physical,
5936
- * enforce-consistent-variable-syntax, enforce-consistent-important-position,
5937
- * enforce-negative-arbitrary-values, no-deprecated-classes,
5938
- * no-unnecessary-arbitrary-value, prefer-theme-tokens) all emit
5939
- * replacements via the same shape:
5940
- *
5941
- * 1. Collect `{ cls, replacement }` entries from a class string.
5942
- * 2. Rebuild the full class string with replacements applied.
5943
- * 3. Emit ONE diagnostic with the autofix attached.
5944
- * 4. Emit one MORE diagnostic per remaining offender, each carrying
5945
- * the same autofix as a `suggest`.
5946
- *
5947
- * oxlint's fixer is single-shot per AST node, so multiple offenders in the
5948
- * same class string can only get one mechanical fix; the rest stay as
5949
- * suggestions the IDE can offer interactively.
5950
- */
5951
- /**
5952
- * Emit autofix + suggestion diagnostics for a list of class replacements.
5953
- *
5954
- * If `offending` is empty, no-op. The fixer's `replaceTextRange` is shared
5955
- * across all diagnostics — the first one is the primary fix, the rest carry
5956
- * the same fix as a suggestion (oxlint can only apply one autofix per node).
5957
- */
5958
- function reportClassReplacements(context, loc, split, classes, offending, options) {
5959
- if (offending.length === 0) return;
5960
- const replacements = new Map(offending.map(({ cls, replacement }) => [cls, replacement]));
5961
- const fixedValue = rebuildClassString(split, classes.map((c) => replacements.get(c) ?? c));
5962
- const replacementKey = options.replacementKey ?? "replacement";
5963
- const suggestMessageId = options.suggestMessageId ?? "suggestReplace";
5964
- const applyFix = (fixer) => fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
5965
- const report = context.report;
5966
- for (let i = 0; i < offending.length; i++) {
5967
- const { cls, replacement } = offending[i];
5968
- const primaryData = {
5969
- className: cls,
5970
- [replacementKey]: replacement
5971
- };
5972
- if (i === 0) report({
5973
- node: loc.node,
5974
- messageId: options.messageId,
5975
- data: primaryData,
5976
- fix: applyFix
5977
- });
5978
- else report({
5979
- node: loc.node,
5980
- messageId: options.messageId,
5981
- data: primaryData,
5982
- suggest: [{
5983
- messageId: suggestMessageId,
5984
- data: {
5985
- className: cls,
5986
- replacement
5987
- },
5988
- fix: applyFix
5989
- }]
5990
- });
5991
- }
5992
- }
5993
- //#endregion
5994
6249
  //#region src/utils/replacement.ts
5995
6250
  /**
5996
6251
  * Returns a predicate that answers "would this replacement produce CSS?".
@@ -6144,6 +6399,7 @@ const enforceCanonical = defineRule({
6144
6399
  ...SETTINGS_MESSAGE,
6145
6400
  nonCanonical: "\"{{className}}\" can be written as \"{{canonical}}\". Use the canonical form.",
6146
6401
  nonEquivalentVariant: "\"{{className}}\" is not the same CSS as its canonical form \"{{canonical}}\" in this project: \"{{variant}}:\" is defined differently from \"{{written}}:\" (a custom variant in your CSS), so the two match different elements. It is left as written; switch to \"{{variant}}:\" only if that is what you mean.",
6402
+ nonEquivalentVariable: "\"{{className}}\" is not the same CSS as its canonical form \"{{canonical}}\": \"{{canonical}}\" also sets {{variables}}, which other utilities read, so next to them the two can render differently. It is left as written; switch to \"{{canonical}}\" if that is what you mean.",
6147
6403
  suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\".",
6148
6404
  ...DS_UNAVAILABLE_MESSAGE
6149
6405
  }
@@ -6162,6 +6418,7 @@ const enforceCanonical = defineRule({
6162
6418
  const classes = split.classes;
6163
6419
  const canonicals = Array.from({ length: classes.length });
6164
6420
  const nonEquivalent = [];
6421
+ const addsVariables = [];
6165
6422
  const arbitraryIdx = [];
6166
6423
  const arbitrary = [];
6167
6424
  for (let i = 0; i < classes.length; i++) {
@@ -6181,12 +6438,17 @@ const enforceCanonical = defineRule({
6181
6438
  if (!dynamic) return;
6182
6439
  const reportNonEquivalent = getReportNonEquivalent();
6183
6440
  for (let k = 0; k < arbitrary.length; k++) {
6184
- const { canonical, safe, reason } = dynamic[k];
6441
+ const { canonical, safe, reason, variables } = dynamic[k];
6185
6442
  const idx = arbitraryIdx[k];
6186
6443
  if (!safe && reason === "variant" && reportNonEquivalent) nonEquivalent.push({
6187
6444
  cls: arbitrary[k],
6188
6445
  canonical
6189
6446
  });
6447
+ if (!safe && reason === "variable" && variables && reportNonEquivalent) addsVariables.push({
6448
+ cls: arbitrary[k],
6449
+ canonical: preserveImportantPosition(arbitrary[k], canonical),
6450
+ variables
6451
+ });
6190
6452
  if (!safe) {
6191
6453
  canonicals[idx] = arbitrary[k];
6192
6454
  continue;
@@ -6215,6 +6477,17 @@ const enforceCanonical = defineRule({
6215
6477
  }
6216
6478
  });
6217
6479
  }
6480
+ for (const { cls, canonical, variables } of addsVariables) reportClassSuggestion(context, loc, split, classes, {
6481
+ cls,
6482
+ replacement: canonical
6483
+ }, {
6484
+ messageId: "nonEquivalentVariable",
6485
+ data: {
6486
+ className: cls,
6487
+ canonical,
6488
+ variables: variables.join(", ")
6489
+ }
6490
+ });
6218
6491
  }
6219
6492
  }
6220
6493
  return createExtractorVisitors(context, check);
@@ -6355,12 +6628,39 @@ const enforceSortOrder = defineRule({
6355
6628
  }
6356
6629
  });
6357
6630
  //#endregion
6631
+ //#region src/utils/declared-values.ts
6632
+ /** A plain number or fraction: always the shared numeric/`--spacing` scale. */
6633
+ const NUMERIC_VALUE_RE = /^\d+(?:\.\d+)?(?:\/\d+(?:\.\d+)?)?$/;
6634
+ /** The value is a literal the user wrote, injected verbatim into every part. */
6635
+ function isWrittenValue(value) {
6636
+ return value.startsWith("[") || value.startsWith("(");
6637
+ }
6638
+ /**
6639
+ * Values the class declares on its own box, unconditionally. `null` when the
6640
+ * class produces nothing — which for a named token means it does not exist.
6641
+ */
6642
+ function declaredValues(cache, cls) {
6643
+ const values = /* @__PURE__ */ new Set();
6644
+ for (const decl of cache.getCssDeclarations(cls)) {
6645
+ if (decl.conditional) continue;
6646
+ values.add(decl.value);
6647
+ }
6648
+ return values.size > 0 ? values : null;
6649
+ }
6650
+ function sameValues(a, b) {
6651
+ if (a.size !== b.size) return false;
6652
+ for (const value of a) if (!b.has(value)) return false;
6653
+ return true;
6654
+ }
6655
+ //#endregion
6358
6656
  //#region src/rules/enforce-shorthand.ts
6359
6657
  /**
6360
6658
  * The `m`/`p` shape, shared by `margin`, `padding`, `scroll-margin` and
6361
- * `scroll-padding`: four sides, each axis, and the logical inline pair (`ms`+`me`
6362
- * IS `margin-inline`, so that one is property-identical rather than merely
6363
- * equivalent).
6659
+ * `scroll-padding`: four sides, each axis, and the logical pairs (`ms`+`me` IS
6660
+ * `margin-inline`, `mbs`+`mbe` IS `margin-block`, so those are
6661
+ * property-identical rather than merely equivalent). The logical ones are what
6662
+ * `enforce-logical` writes, so `mt-2 mb-2` ends as `my-2` whichever of the two
6663
+ * rules fixes it first.
6364
6664
  */
6365
6665
  function boxFamilies(p) {
6366
6666
  return [
@@ -6373,10 +6673,23 @@ function boxFamilies(p) {
6373
6673
  ],
6374
6674
  to: p
6375
6675
  },
6676
+ {
6677
+ parts: [
6678
+ `${p}s`,
6679
+ `${p}e`,
6680
+ `${p}bs`,
6681
+ `${p}be`
6682
+ ],
6683
+ to: p
6684
+ },
6376
6685
  {
6377
6686
  parts: [`${p}t`, `${p}b`],
6378
6687
  to: `${p}y`
6379
6688
  },
6689
+ {
6690
+ parts: [`${p}bs`, `${p}be`],
6691
+ to: `${p}y`
6692
+ },
6380
6693
  {
6381
6694
  parts: [`${p}l`, `${p}r`],
6382
6695
  to: `${p}x`
@@ -6464,10 +6777,23 @@ const SHORTHAND_FAMILIES = [
6464
6777
  ],
6465
6778
  to: "border"
6466
6779
  },
6780
+ {
6781
+ parts: [
6782
+ "border-s",
6783
+ "border-e",
6784
+ "border-bs",
6785
+ "border-be"
6786
+ ],
6787
+ to: "border"
6788
+ },
6467
6789
  {
6468
6790
  parts: ["border-t", "border-b"],
6469
6791
  to: "border-y"
6470
6792
  },
6793
+ {
6794
+ parts: ["border-bs", "border-be"],
6795
+ to: "border-y"
6796
+ },
6471
6797
  {
6472
6798
  parts: ["border-l", "border-r"],
6473
6799
  to: "border-x"
@@ -6489,10 +6815,23 @@ const SHORTHAND_FAMILIES = [
6489
6815
  ],
6490
6816
  to: "inset"
6491
6817
  },
6818
+ {
6819
+ parts: [
6820
+ "inset-s",
6821
+ "inset-e",
6822
+ "inset-bs",
6823
+ "inset-be"
6824
+ ],
6825
+ to: "inset"
6826
+ },
6492
6827
  {
6493
6828
  parts: ["top", "bottom"],
6494
6829
  to: "inset-y"
6495
6830
  },
6831
+ {
6832
+ parts: ["inset-bs", "inset-be"],
6833
+ to: "inset-y"
6834
+ },
6496
6835
  {
6497
6836
  parts: ["left", "right"],
6498
6837
  to: "inset-x"
@@ -6501,6 +6840,10 @@ const SHORTHAND_FAMILIES = [
6501
6840
  parts: ["start", "end"],
6502
6841
  to: "inset-x"
6503
6842
  },
6843
+ {
6844
+ parts: ["inset-s", "inset-e"],
6845
+ to: "inset-x"
6846
+ },
6504
6847
  {
6505
6848
  parts: ["inset-x", "inset-y"],
6506
6849
  to: "inset"
@@ -6541,8 +6884,6 @@ const VALUE_RE = (() => {
6541
6884
  const prefixes = [...new Set(SHORTHAND_FAMILIES.flatMap((f) => f.parts))].sort((a, b) => b.length - a.length);
6542
6885
  return new RegExp(`^(${prefixes.join("|")})-(.+)$`);
6543
6886
  })();
6544
- /** A plain number or fraction: always the shared numeric/`--spacing` scale. */
6545
- const NUMERIC_VALUE_RE = /^\d+(?:\.\d+)?(?:\/\d+(?:\.\d+)?)?$/;
6546
6887
  /**
6547
6888
  * Core keywords whose per-axis forms are known to agree, for when no design
6548
6889
  * system is available to check. Deliberately excludes `screen` (`w-screen` is
@@ -6563,27 +6904,6 @@ const AXIS_SAFE_KEYWORDS = /* @__PURE__ */ new Set([
6563
6904
  "svw",
6564
6905
  "svh"
6565
6906
  ]);
6566
- /** The value is a literal the user wrote, injected verbatim into every part. */
6567
- function isWrittenValue(value) {
6568
- return value.startsWith("[") || value.startsWith("(");
6569
- }
6570
- /**
6571
- * Values the class declares on its own box, unconditionally. `null` when the
6572
- * class produces nothing — which for a named token means it does not exist.
6573
- */
6574
- function declaredValues(cache, cls) {
6575
- const values = /* @__PURE__ */ new Set();
6576
- for (const decl of cache.getCssDeclarations(cls)) {
6577
- if (decl.conditional) continue;
6578
- values.add(decl.value);
6579
- }
6580
- return values.size > 0 ? values : null;
6581
- }
6582
- function sameValues(a, b) {
6583
- if (a.size !== b.size) return false;
6584
- for (const value of a) if (!b.has(value)) return false;
6585
- return true;
6586
- }
6587
6907
  /**
6588
6908
  * Would collapsing this family at this value keep the CSS identical?
6589
6909
  *
@@ -6718,10 +7038,14 @@ const LOGICAL_PHYSICAL_SCHEMA = {
6718
7038
  "both"
6719
7039
  ]
6720
7040
  },
7041
+ sizing: { type: "boolean" },
6721
7042
  entryPoint: { type: "string" }
6722
7043
  },
6723
7044
  additionalProperties: false
6724
7045
  };
7046
+ /** Viewport units of the other axis: a width in heights, a height in widths. */
7047
+ const HEIGHT_UNITS = /^[dls]vh$/;
7048
+ const WIDTH_UNITS = /^[dls]vw$/;
6725
7049
  const PHYSICAL_TO_LOGICAL_MAPPINGS = [
6726
7050
  {
6727
7051
  from: "ml",
@@ -6745,13 +7069,17 @@ const PHYSICAL_TO_LOGICAL_MAPPINGS = [
6745
7069
  },
6746
7070
  {
6747
7071
  from: "left",
6748
- to: "start",
6749
- axis: "inline"
7072
+ to: "inset-s",
7073
+ axis: "inline",
7074
+ since: true,
7075
+ fallback: "start"
6750
7076
  },
6751
7077
  {
6752
7078
  from: "right",
6753
- to: "end",
6754
- axis: "inline"
7079
+ to: "inset-e",
7080
+ axis: "inline",
7081
+ since: true,
7082
+ fallback: "end"
6755
7083
  },
6756
7084
  {
6757
7085
  from: "border-l",
@@ -6848,82 +7176,294 @@ const PHYSICAL_TO_LOGICAL_MAPPINGS = [
6848
7176
  to: "text-end",
6849
7177
  axis: "inline",
6850
7178
  exact: true
7179
+ },
7180
+ {
7181
+ from: "mt",
7182
+ to: "mbs",
7183
+ axis: "block",
7184
+ since: true
7185
+ },
7186
+ {
7187
+ from: "mb",
7188
+ to: "mbe",
7189
+ axis: "block",
7190
+ since: true
7191
+ },
7192
+ {
7193
+ from: "pt",
7194
+ to: "pbs",
7195
+ axis: "block",
7196
+ since: true
7197
+ },
7198
+ {
7199
+ from: "pb",
7200
+ to: "pbe",
7201
+ axis: "block",
7202
+ since: true
7203
+ },
7204
+ {
7205
+ from: "top",
7206
+ to: "inset-bs",
7207
+ axis: "block",
7208
+ since: true
7209
+ },
7210
+ {
7211
+ from: "bottom",
7212
+ to: "inset-be",
7213
+ axis: "block",
7214
+ since: true
7215
+ },
7216
+ {
7217
+ from: "border-t",
7218
+ to: "border-bs",
7219
+ axis: "block",
7220
+ since: true
7221
+ },
7222
+ {
7223
+ from: "border-b",
7224
+ to: "border-be",
7225
+ axis: "block",
7226
+ since: true
7227
+ },
7228
+ {
7229
+ from: "scroll-mt",
7230
+ to: "scroll-mbs",
7231
+ axis: "block",
7232
+ since: true
7233
+ },
7234
+ {
7235
+ from: "scroll-mb",
7236
+ to: "scroll-mbe",
7237
+ axis: "block",
7238
+ since: true
7239
+ },
7240
+ {
7241
+ from: "scroll-pt",
7242
+ to: "scroll-pbs",
7243
+ axis: "block",
7244
+ since: true
7245
+ },
7246
+ {
7247
+ from: "scroll-pb",
7248
+ to: "scroll-pbe",
7249
+ axis: "block",
7250
+ since: true
7251
+ },
7252
+ {
7253
+ from: "w",
7254
+ to: "inline",
7255
+ axis: "inline",
7256
+ since: true,
7257
+ sizing: true,
7258
+ skipValues: HEIGHT_UNITS
7259
+ },
7260
+ {
7261
+ from: "min-w",
7262
+ to: "min-inline",
7263
+ axis: "inline",
7264
+ since: true,
7265
+ sizing: true,
7266
+ skipValues: HEIGHT_UNITS
7267
+ },
7268
+ {
7269
+ from: "max-w",
7270
+ to: "max-inline",
7271
+ axis: "inline",
7272
+ since: true,
7273
+ sizing: true,
7274
+ skipValues: /^(?:[dls]vh|prose|screen-.+)$/
7275
+ },
7276
+ {
7277
+ from: "h",
7278
+ to: "block",
7279
+ axis: "block",
7280
+ since: true,
7281
+ sizing: true,
7282
+ skipValues: WIDTH_UNITS
7283
+ },
7284
+ {
7285
+ from: "min-h",
7286
+ to: "min-block",
7287
+ axis: "block",
7288
+ since: true,
7289
+ sizing: true,
7290
+ skipValues: WIDTH_UNITS
7291
+ },
7292
+ {
7293
+ from: "max-h",
7294
+ to: "max-block",
7295
+ axis: "block",
7296
+ since: true,
7297
+ sizing: true,
7298
+ skipValues: WIDTH_UNITS
7299
+ },
7300
+ {
7301
+ from: "size",
7302
+ to: ["inline", "block"],
7303
+ axis: "both",
7304
+ since: true,
7305
+ sizing: true,
7306
+ skipValues: /^[dls]v[hw]$/
6851
7307
  }
6852
7308
  ];
6853
7309
  /**
6854
- * Extra sources for enforce-physical ONLY.
6855
- *
6856
- * `enforce-logical` rewrites `left-2` to `start-2`, the spelling Tailwind's own
6857
- * docs use. `enforce-canonical`, asking the design system, then rewrites that to
6858
- * `inset-s-2` — same CSS, canonical name. So a codebase that ran both ends up with
6859
- * `inset-s-*`, and enforce-physical had no way back: its table only knew `start`.
6860
- *
6861
- * Kept out of the main table so inverting it doesn't change what enforce-logical
6862
- * suggests (both spellings map to the same physical class, but only one of them
6863
- * can be the recommendation).
6864
- */
6865
- const LOGICAL_INSET_ALIASES = [{
6866
- from: "inset-s",
6867
- to: "left",
6868
- axis: "inline"
6869
- }, {
6870
- from: "inset-e",
6871
- to: "right",
6872
- axis: "inline"
6873
- }];
6874
- /** Invert a directional table. enforce-physical consumes this. */
7310
+ * `inline` and `block` are display utilities too: `inline-flex` must never read
7311
+ * as an inline size, nor `block` as a block size.
7312
+ */
7313
+ const DISPLAY_CLASSES = /* @__PURE__ */ new Set([
7314
+ "inline",
7315
+ "block",
7316
+ "inline-block",
7317
+ "inline-flex",
7318
+ "inline-grid",
7319
+ "inline-table"
7320
+ ]);
7321
+ /**
7322
+ * Invert a directional table. enforce-physical consumes this. A two-axis entry
7323
+ * has no single inverse (`inline-4 block-4` convert one by one), and an entry
7324
+ * with a `fallback` inverts both spellings: `inset-s-2` and `start-2` are both
7325
+ * `left-2`.
7326
+ */
6875
7327
  function invertAxisMappings(mappings) {
6876
- return mappings.map((m) => ({
6877
- ...m,
6878
- from: m.to,
6879
- to: m.from
6880
- }));
7328
+ return mappings.flatMap((m) => {
7329
+ if (typeof m.to !== "string") return [];
7330
+ const back = {
7331
+ from: m.to,
7332
+ to: m.from,
7333
+ axis: m.axis
7334
+ };
7335
+ if (m.exact) back.exact = m.exact;
7336
+ if (m.sizing) back.sizing = m.sizing;
7337
+ return m.fallback ? [back, {
7338
+ ...back,
7339
+ from: m.fallback
7340
+ }] : [back];
7341
+ });
7342
+ }
7343
+ /** Does the project's Tailwind have this utility? See `AxisMapping.since`. */
7344
+ function hasUtility(cache, root) {
7345
+ return cache.isKnownClass(`${root}-0`);
7346
+ }
7347
+ /**
7348
+ * The same value under the new prefixes? Numbers, fractions and written values
7349
+ * read the same scale or nothing at all; a named token is settled by the CSS.
7350
+ */
7351
+ function sameSizing(cache, value, source, targets) {
7352
+ if (NUMERIC_VALUE_RE.test(value) || isWrittenValue(value)) return true;
7353
+ const expected = declaredValues(cache, source);
7354
+ if (!expected) return false;
7355
+ const actual = /* @__PURE__ */ new Set();
7356
+ for (const target of targets) {
7357
+ const values = declaredValues(cache, target);
7358
+ if (!values) return false;
7359
+ for (const v of values) actual.add(v);
7360
+ }
7361
+ return sameValues(expected, actual);
7362
+ }
7363
+ /**
7364
+ * One class through a directional table: what it should be written as, or null
7365
+ * when the table has nothing for it or the replacement can't be trusted. Pure,
7366
+ * so the Tailwind 4.1 case (no 4.2 utilities) is testable with a hand-built
7367
+ * design system.
7368
+ */
7369
+ function convertDirectional(cls, mappings, options, cache) {
7370
+ if (matchesAny(cls, options.allowlist)) return null;
7371
+ const { utility, variant } = splitUtilityAndVariant(cls);
7372
+ const { bare: bareUtility, position } = splitImportant(utility);
7373
+ const negative = bareUtility.startsWith("-");
7374
+ const core = negative ? bareUtility.slice(1) : bareUtility;
7375
+ const isUsable = makeReplacementGuard(cache);
7376
+ for (const mapping of mappings) {
7377
+ const { from, to, axis, exact, sizing } = mapping;
7378
+ if (options.direction !== "both" && options.direction !== axis) continue;
7379
+ if (sizing && !options.sizing) continue;
7380
+ if (!(core === from || !exact && core.startsWith(`${from}-`))) continue;
7381
+ if (sizing && (core === from || DISPLAY_CLASSES.has(core))) continue;
7382
+ const suffix = core.slice(from.length);
7383
+ const value = suffix.slice(1);
7384
+ if (mapping.skipValues?.test(value)) return null;
7385
+ const prefixes = typeof to === "string" ? [to] : [...to];
7386
+ const build = (prefix) => `${variant}${reattachImportant(`${negative ? "-" : ""}${prefix}${suffix}`, position)}`;
7387
+ const halves = prefixes.map(build);
7388
+ const replacement = halves.join(" ");
7389
+ if (!mapping.since) return isUsable(replacement) ? {
7390
+ replacement,
7391
+ suggestOnly: false,
7392
+ mapping
7393
+ } : null;
7394
+ if (!cache) return mapping.fallback ? {
7395
+ replacement: build(mapping.fallback),
7396
+ suggestOnly: false,
7397
+ mapping
7398
+ } : {
7399
+ replacement,
7400
+ suggestOnly: true,
7401
+ mapping
7402
+ };
7403
+ if (prefixes.every((prefix) => hasUtility(cache, prefix)) && halves.every(isUsable) && (!sizing || sameSizing(cache, value, `${from}${suffix}`, prefixes.map((p) => `${p}${suffix}`)))) return {
7404
+ replacement,
7405
+ suggestOnly: false,
7406
+ mapping
7407
+ };
7408
+ if (mapping.fallback && isUsable(build(mapping.fallback))) return {
7409
+ replacement: build(mapping.fallback),
7410
+ suggestOnly: false,
7411
+ mapping
7412
+ };
7413
+ return null;
7414
+ }
7415
+ return null;
6881
7416
  }
6882
7417
  /**
6883
7418
  * Build the `check` callback for a directional-rewrite rule. Both
6884
7419
  * enforce-logical and enforce-physical instantiate this with their own
6885
- * mapping table and messageId; the rule's `createOnce` wires it through
7420
+ * mapping table and messageIds; the rule's `createOnce` wires it through
6886
7421
  * `createExtractorVisitors`.
6887
7422
  *
6888
- * Owns: option compilation (allowlist + direction), per-class conversion
6889
- * (linear scan of the mapping table respecting `!`-prefix/suffix), and
6890
- * the `reportClassReplacements` dispatch.
7423
+ * Owns: option compilation (allowlist + direction + sizing), the per-class
7424
+ * conversion (`convertDirectional`), and the report: autofixes through
7425
+ * `reportClassReplacements`, suggestion-only conversions through
7426
+ * `reportClassSuggestion`, so a suggestion never rides along in the autofix.
6891
7427
  */
6892
7428
  function createDirectionalMapper(context, opts) {
6893
- const getState = createLazyOptions(context, (o) => ({
7429
+ const getOptions = createLazyOptions(context, (o) => ({
6894
7430
  allowlist: compileRegexList(o?.allowlist),
6895
- direction: o?.direction ?? "both"
7431
+ direction: o?.direction ?? "both",
7432
+ sizing: o?.sizing === true
6896
7433
  }));
6897
7434
  const getDS = createLazyLoader(context);
6898
- function convertClass(cls) {
6899
- const { allowlist, direction } = getState();
6900
- if (matchesAny(cls, allowlist)) return null;
6901
- const { utility, variant } = splitUtilityAndVariant(cls);
6902
- const { bare: bareUtility, position } = splitImportant(utility);
6903
- const negative = bareUtility.startsWith("-");
6904
- const core = negative ? bareUtility.slice(1) : bareUtility;
6905
- for (const { from, to, axis, exact } of opts.mappings) {
6906
- if (direction !== "both" && direction !== axis) continue;
6907
- if (!(core === from || !exact && core.startsWith(`${from}-`))) continue;
6908
- const suffix = core.slice(from.length);
6909
- return `${variant}${reattachImportant(`${negative ? "-" : ""}${to}${suffix}`, position)}`;
6910
- }
6911
- return null;
6912
- }
7435
+ const messageIdFor = ({ axis, sizing }) => opts.writingModeMessageId && (axis !== "inline" || sizing) ? opts.writingModeMessageId : opts.messageId;
6913
7436
  function check(locations) {
6914
7437
  const ds = softGetDS(getDS);
6915
- const isUsable = makeReplacementGuard(ds ? ds.cache : null);
7438
+ const cache = ds ? ds.cache : null;
7439
+ const options = getOptions();
6916
7440
  for (const loc of locations) {
6917
7441
  const split = splitClassesWithSeparators(loc.value);
6918
- const offending = split.classes.flatMap((cls) => {
6919
- const converted = convertClass(cls);
6920
- if (!converted || !isUsable(converted)) return [];
6921
- return [{
7442
+ const fixes = [];
7443
+ const suggestions = [];
7444
+ for (const cls of split.classes) {
7445
+ const conversion = convertDirectional(cls, opts.mappings, options, cache);
7446
+ if (!conversion) continue;
7447
+ const messageId = messageIdFor(conversion.mapping);
7448
+ const entry = {
6922
7449
  cls,
6923
- replacement: converted
6924
- }];
7450
+ replacement: conversion.replacement,
7451
+ messageId
7452
+ };
7453
+ if (conversion.suggestOnly) suggestions.push(entry);
7454
+ else fixes.push(entry);
7455
+ }
7456
+ reportClassReplacements(context, loc, split, split.classes, fixes, { messageId: opts.messageId });
7457
+ for (const { cls, replacement, messageId } of suggestions) reportClassSuggestion(context, loc, split, split.classes, {
7458
+ cls,
7459
+ replacement
7460
+ }, {
7461
+ messageId,
7462
+ data: {
7463
+ className: cls,
7464
+ replacement
7465
+ }
6925
7466
  });
6926
- reportClassReplacements(context, loc, split, split.classes, offending, { messageId: opts.messageId });
6927
7467
  }
6928
7468
  }
6929
7469
  return { check };
@@ -6942,24 +7482,28 @@ const enforceLogical = defineRule({
6942
7482
  hasSuggestions: true,
6943
7483
  defaultOptions: [{
6944
7484
  allowlist: [],
6945
- direction: "both"
7485
+ direction: "both",
7486
+ sizing: false
6946
7487
  }],
6947
7488
  messages: {
6948
7489
  ...SETTINGS_MESSAGE,
6949
7490
  useLogical: "\"{{className}}\" uses a physical property. Use \"{{replacement}}\" for LTR/RTL support.",
7491
+ useLogicalWritingMode: "\"{{className}}\" uses a physical property. Use \"{{replacement}}\" so it follows the writing mode.",
6950
7492
  suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
6951
7493
  }
6952
7494
  },
6953
7495
  createOnce(context) {
6954
7496
  const { check } = createDirectionalMapper(context, {
6955
7497
  mappings: PHYSICAL_TO_LOGICAL_MAPPINGS,
6956
- messageId: "useLogical"
7498
+ messageId: "useLogical",
7499
+ writingModeMessageId: "useLogicalWritingMode"
6957
7500
  });
6958
7501
  return createExtractorVisitors(context, check);
6959
7502
  }
6960
7503
  });
6961
7504
  //#endregion
6962
7505
  //#region src/rules/enforce-physical.ts
7506
+ const PHYSICAL_MAPPINGS = invertAxisMappings(PHYSICAL_TO_LOGICAL_MAPPINGS);
6963
7507
  const enforcePhysical = defineRule({
6964
7508
  meta: {
6965
7509
  type: "suggestion",
@@ -6974,7 +7518,8 @@ const enforcePhysical = defineRule({
6974
7518
  hasSuggestions: true,
6975
7519
  defaultOptions: [{
6976
7520
  allowlist: [],
6977
- direction: "both"
7521
+ direction: "both",
7522
+ sizing: false
6978
7523
  }],
6979
7524
  messages: {
6980
7525
  ...SETTINGS_MESSAGE,
@@ -6984,7 +7529,7 @@ const enforcePhysical = defineRule({
6984
7529
  },
6985
7530
  createOnce(context) {
6986
7531
  const { check } = createDirectionalMapper(context, {
6987
- mappings: [...invertAxisMappings(PHYSICAL_TO_LOGICAL_MAPPINGS), ...LOGICAL_INSET_ALIASES],
7532
+ mappings: PHYSICAL_MAPPINGS,
6988
7533
  messageId: "usePhysical"
6989
7534
  });
6990
7535
  return createExtractorVisitors(context, check);
@@ -8372,6 +8917,12 @@ const consistentVariantOrder = defineRule({
8372
8917
  //#region src/rules/enforce-consistent-line-wrapping.ts
8373
8918
  const DEFAULT_PRINT_WIDTH = 80;
8374
8919
  const DEFAULT_GROUP = "newLine";
8920
+ const DEFAULT_WRAP_STRINGS = "never";
8921
+ /** A JSX attribute's own string: `className="…"`, not `className={"…"}` (#216). */
8922
+ function isJsxAttributeString(loc) {
8923
+ const node = loc.node;
8924
+ return node.type === "Literal" && node.parent?.type === "JSXAttribute";
8925
+ }
8375
8926
  /** One indentation level added below the statement's base indent for wrapped lines. */
8376
8927
  const INDENT_UNIT = " ";
8377
8928
  /** Group `classes` into chunks of at most `n`, each chunk space-joined. */
@@ -8473,13 +9024,18 @@ const enforceConsistentLineWrapping = defineRule({
8473
9024
  "emptyLine",
8474
9025
  "never"
8475
9026
  ]
9027
+ },
9028
+ wrapStrings: {
9029
+ type: "string",
9030
+ enum: ["never", "jsx"]
8476
9031
  }
8477
9032
  },
8478
9033
  additionalProperties: false
8479
9034
  }],
8480
9035
  defaultOptions: [{
8481
9036
  printWidth: DEFAULT_PRINT_WIDTH,
8482
- group: DEFAULT_GROUP
9037
+ group: DEFAULT_GROUP,
9038
+ wrapStrings: DEFAULT_WRAP_STRINGS
8483
9039
  }],
8484
9040
  messages: {
8485
9041
  ...SETTINGS_MESSAGE,
@@ -8493,6 +9049,7 @@ const enforceConsistentLineWrapping = defineRule({
8493
9049
  const getClassesPerLine = createLazyOptions(context, (o) => o?.classesPerLine);
8494
9050
  const getWrapLines = createLazyOptions(context, (o) => o?.wrapLines);
8495
9051
  const getGroup = createLazyOptions(context, (o) => o?.group ?? DEFAULT_GROUP);
9052
+ const getWrapStrings = createLazyOptions(context, (o) => o?.wrapStrings ?? DEFAULT_WRAP_STRINGS);
8496
9053
  const getDS = createLazyLoader(context);
8497
9054
  /**
8498
9055
  * The statement's real base indentation — the leading whitespace of the
@@ -8512,6 +9069,19 @@ const enforceConsistentLineWrapping = defineRule({
8512
9069
  return "";
8513
9070
  }
8514
9071
  /**
9072
+ * The line ending a JSX string's fix writes. A JSX attribute keeps the
9073
+ * file's `\r\n` in its value (a template's is LF already), so a CRLF file
9074
+ * gets CRLF breaks: from the value when it has any, else from the line the
9075
+ * string ends on.
9076
+ */
9077
+ function lineEndingOf(loc) {
9078
+ if (loc.value.includes("\r\n")) return "\r\n";
9079
+ const text = safeSourceCode(context)?.text;
9080
+ if (typeof text !== "string") return "\n";
9081
+ const nl = text.indexOf("\n", loc.range[1]);
9082
+ return nl > 0 && text[nl - 1] === "\r" ? "\r\n" : "\n";
9083
+ }
9084
+ /**
8515
9085
  * Re-wrap a template literal's classes into the block convention,
8516
9086
  * non-destructively:
8517
9087
  * - single-line → convert to a `\n` + indent block (unless the quasi is
@@ -8596,7 +9166,16 @@ const enforceConsistentLineWrapping = defineRule({
8596
9166
  const wrapLines = getWrapLines();
8597
9167
  const group = getGroup();
8598
9168
  const prefix = wrapLines === "all" && group !== "never" && classesPerLine === void 0 ? softGetDS(getDS)?.cache.prefix ?? "" : "";
8599
- for (const loc of locations) {
9169
+ const wrapStrings = getWrapStrings();
9170
+ for (const written of locations) {
9171
+ const wrapsString = wrapStrings === "jsx" && isJsxAttributeString(written);
9172
+ const fixable = written.node.type === "TemplateElement" || wrapsString;
9173
+ const eol = wrapsString ? lineEndingOf(written) : "\n";
9174
+ const loc = eol === "\n" ? written : {
9175
+ ...written,
9176
+ value: written.value.replace(/\r\n/g, "\n")
9177
+ };
9178
+ const toSource = (value) => eol === "\n" ? value : value.replace(/\n/g, eol);
8600
9179
  let maxLine = 0;
8601
9180
  for (const line of loc.value.split("\n")) {
8602
9181
  if (line.length <= maxLine) continue;
@@ -8609,14 +9188,14 @@ const enforceConsistentLineWrapping = defineRule({
8609
9188
  };
8610
9189
  const isMultiline = loc.value.includes("\n");
8611
9190
  const glued = loc.preserveLeadingSpace === true && !/^\s/.test(loc.value) || loc.preserveTrailingSpace === true && !/\s$/.test(loc.value);
8612
- if (wrapLines !== void 0 && classesPerLine === void 0 && loc.node.type === "TemplateElement" && !glued && (maxLine > printWidth || wrapLines === "all" && isMultiline)) {
9191
+ if (wrapLines !== void 0 && classesPerLine === void 0 && fixable && !glued && (maxLine > printWidth || wrapLines === "all" && isMultiline)) {
8613
9192
  const fixedValue = wrapLines === "all" ? rewrapTemplateToWidth(loc, printWidth, group, prefix) : rewrapOverBudgetLinesToWidth(loc, printWidth);
8614
9193
  if (fixedValue !== loc.value) context.report({
8615
9194
  node: loc.node,
8616
9195
  messageId: maxLine > printWidth ? "tooLong" : "inconsistentWrapping",
8617
9196
  data,
8618
9197
  fix(fixer) {
8619
- return fixer.replaceTextRange(loc.range, fixedValue);
9198
+ return fixer.replaceTextRange(loc.range, toSource(fixedValue));
8620
9199
  }
8621
9200
  });
8622
9201
  } else if (maxLine > printWidth) context.report({
@@ -8636,14 +9215,14 @@ const enforceConsistentLineWrapping = defineRule({
8636
9215
  count: String(maxPerLine),
8637
9216
  max: String(classesPerLine)
8638
9217
  };
8639
- if (loc.node.type === "TemplateElement" && !glued) {
9218
+ if (fixable && !glued) {
8640
9219
  const fixedValue = rewrapTemplate(loc, lines, classesPerLine);
8641
9220
  context.report({
8642
9221
  node: loc.node,
8643
9222
  messageId: "tooManyPerLine",
8644
9223
  data,
8645
9224
  fix(fixer) {
8646
- return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
9225
+ return fixer.replaceTextRange(loc.range, toSource(preserveSpaces(loc, fixedValue)));
8647
9226
  }
8648
9227
  });
8649
9228
  } else context.report({
@@ -8878,24 +9457,15 @@ const preferScaleToken = defineRule({
8878
9457
  const equivalent = equivalentOf(cache, bare);
8879
9458
  if (!equivalent) continue;
8880
9459
  const replacement = variant + reattachImportant(equivalent, position);
8881
- const fixedValue = rebuildClassString(split, split.classes.map((c) => c === cls ? replacement : c));
8882
- context.report({
8883
- node: loc.node,
9460
+ reportClassSuggestion(context, loc, split, split.classes, {
9461
+ cls,
9462
+ replacement
9463
+ }, {
8884
9464
  messageId: "preferToken",
8885
9465
  data: {
8886
9466
  className: cls,
8887
9467
  replacement
8888
- },
8889
- suggest: [{
8890
- messageId: "suggestReplace",
8891
- data: {
8892
- className: cls,
8893
- replacement
8894
- },
8895
- fix(fixer) {
8896
- return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
8897
- }
8898
- }]
9468
+ }
8899
9469
  });
8900
9470
  }
8901
9471
  }
@@ -9980,7 +10550,7 @@ function componentSignatures(files, cache, entryPoint) {
9980
10550
  const signature = signatureOf(style.classes, cache, entryPoint);
9981
10551
  const keys = [...signature.keys()];
9982
10552
  if (signature.size < MIN_SHARED || !keys.some(isColorKey) || !keys.some(isSurfaceKey)) continue;
9983
- const id = JSON.stringify([...signature].sort());
10553
+ const id = JSON.stringify([...signature].sort(([a], [b]) => a < b ? -1 : 1));
9984
10554
  if (seen.has(id)) continue;
9985
10555
  seen.add(id);
9986
10556
  const file = (0, node_path.relative)(process.cwd(), path).split("\\").join("/");