oxlint-tailwindcss 1.14.0 → 1.15.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/README.md +4 -0
- package/dist/config.cjs +84 -0
- package/dist/config.d.cts +114 -0
- package/dist/config.d.mts +114 -0
- package/dist/config.mjs +79 -0
- package/dist/index.cjs +825 -222
- package/dist/index.d.cts +16 -16
- package/dist/index.d.mts +16 -16
- package/dist/index.mjs +825 -222
- package/package.json +11 -3
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.
|
|
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,140 @@ 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
|
-
|
|
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
|
|
4519
|
-
|
|
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
|
-
|
|
4529
|
-
r.
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
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
|
-
const
|
|
4537
|
-
|
|
4784
|
+
const escapeClass = (s) => {
|
|
4785
|
+
if (s === '-') return '\\\\-';
|
|
4786
|
+
let out = '';
|
|
4787
|
+
for (let i = 0; i < s.length; i++) {
|
|
4788
|
+
const c = s.charCodeAt(i);
|
|
4789
|
+
if (c === 0) out += '\\uFFFD';
|
|
4790
|
+
else if ((c >= 1 && c <= 31) || c === 127 || (c >= 48 && c <= 57 && (i === 0 || (i === 1 && s[0] === '-')))) {
|
|
4791
|
+
out += '\\\\' + c.toString(16) + ' ';
|
|
4792
|
+
} else if (c >= 128 || c === 45 || c === 95 || (c >= 48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122)) {
|
|
4793
|
+
out += s[i];
|
|
4794
|
+
} else {
|
|
4795
|
+
out += '\\\\' + s[i];
|
|
4796
|
+
}
|
|
4797
|
+
}
|
|
4798
|
+
return out;
|
|
4799
|
+
};
|
|
4800
|
+
const NAME_CHAR = /[\\w\\\\-]|[^\\x00-\\x7f]/;
|
|
4801
|
+
const rawOf = (d, cls) => {
|
|
4538
4802
|
let out;
|
|
4539
4803
|
try { out = d.candidatesToCss([cls]); } catch (e) { return null; }
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4804
|
+
return out && out[0] ? out[0] : null;
|
|
4805
|
+
};
|
|
4806
|
+
const own = (css, cls) => {
|
|
4807
|
+
const token = '.' + escapeClass(cls);
|
|
4808
|
+
let out = '';
|
|
4809
|
+
let i = 0;
|
|
4810
|
+
while (i < css.length) {
|
|
4811
|
+
const ch = css[i];
|
|
4812
|
+
if (ch === '"' || ch === "'") {
|
|
4813
|
+
let j = i + 1;
|
|
4814
|
+
while (j < css.length && css[j] !== ch) j += css[j] === '\\\\' ? 2 : 1;
|
|
4815
|
+
out += css.slice(i, j + 1);
|
|
4816
|
+
i = j + 1;
|
|
4817
|
+
} else if (css.startsWith(token, i) && css[i - 1] !== '\\\\' && !NAME_CHAR.test(css[i + token.length] || ' ')) {
|
|
4818
|
+
out += '.__c';
|
|
4819
|
+
i += token.length;
|
|
4820
|
+
} else {
|
|
4821
|
+
out += ch;
|
|
4822
|
+
i++;
|
|
4823
|
+
}
|
|
4824
|
+
}
|
|
4825
|
+
return out.replace(/\\s+/g, ' ').trim();
|
|
4545
4826
|
};
|
|
4546
4827
|
// Declarations only, selectors and at-rule preludes dropped: equal for two
|
|
4547
4828
|
// rules that set the same things on different selectors.
|
|
4548
4829
|
const declarationsOf = (css) => css.replace(/[^{};]+\\{/g, '').replace(/\\}/g, '').replace(/\\s+/g, ' ').trim();
|
|
4830
|
+
// A mirror (#217) is a --tw-* declaration that repeats, verbatim, the value of
|
|
4831
|
+
// a sibling real property in the same block: "--tw-font-weight: var(--x)" next
|
|
4832
|
+
// to "font-weight: var(--x)". Tailwind drops exactly these (and their
|
|
4833
|
+
// @property rules) when it signs a class to canonicalize it, which is why it
|
|
4834
|
+
// proposes "[font-weight:var(--x)]" -> "font-(--x)". Other utilities read
|
|
4835
|
+
// those variables (a text-* size reads --tw-font-weight), so the two forms are
|
|
4836
|
+
// not the same CSS. candidatesToCss prints one declaration per line, so this
|
|
4837
|
+
// walks lines: a value holding a ";" (content: ';') stays whole.
|
|
4838
|
+
const stripMirrors = (css) => {
|
|
4839
|
+
const lines = css.split('\\n');
|
|
4840
|
+
const removed = new Set();
|
|
4841
|
+
const drop = new Set();
|
|
4842
|
+
const blocks = [];
|
|
4843
|
+
for (let i = 0; i < lines.length; i++) {
|
|
4844
|
+
const t = lines[i].trim();
|
|
4845
|
+
if (t.endsWith('{')) { blocks.push([]); continue; }
|
|
4846
|
+
if (t === '}') {
|
|
4847
|
+
const decls = blocks.pop() || [];
|
|
4848
|
+
for (const d of decls) {
|
|
4849
|
+
if (!d.prop.startsWith('--tw-')) continue;
|
|
4850
|
+
if (decls.some((o) => !o.prop.startsWith('--') && o.value === d.value)) {
|
|
4851
|
+
drop.add(d.line);
|
|
4852
|
+
removed.add(d.prop);
|
|
4853
|
+
}
|
|
4854
|
+
}
|
|
4855
|
+
continue;
|
|
4856
|
+
}
|
|
4857
|
+
const colon = t.indexOf(':');
|
|
4858
|
+
if (blocks.length > 0 && colon > 0 && t.endsWith(';')) {
|
|
4859
|
+
blocks[blocks.length - 1].push({ line: i, prop: t.slice(0, colon).trim(), value: t.slice(colon + 1, -1).trim() });
|
|
4860
|
+
}
|
|
4861
|
+
}
|
|
4862
|
+
if (removed.size === 0) return { css, removed };
|
|
4863
|
+
const kept = [];
|
|
4864
|
+
for (let i = 0; i < lines.length; i++) {
|
|
4865
|
+
if (drop.has(i)) continue;
|
|
4866
|
+
const t = lines[i].trim();
|
|
4867
|
+
if (t.startsWith('@property ') && t.endsWith('{') && removed.has(t.slice(10, -1).trim())) {
|
|
4868
|
+
while (i < lines.length && lines[i].trim() !== '}') i++;
|
|
4869
|
+
continue;
|
|
4870
|
+
}
|
|
4871
|
+
kept.push(lines[i]);
|
|
4872
|
+
}
|
|
4873
|
+
return { css: kept.join('\\n'), removed };
|
|
4874
|
+
};
|
|
4549
4875
|
const results = [];
|
|
4550
4876
|
for (const cls of classes) {
|
|
4551
4877
|
// A malformed/mid-typing arbitrary value (e.g. \`px-[calc(var(--a)+)]\`) can
|
|
@@ -4562,19 +4888,37 @@ const WORKER_SCRIPT$2 = makeWorkerScript(`async (ds, request, env) => {
|
|
|
4562
4888
|
}
|
|
4563
4889
|
const canonical = r[0] ?? cls;
|
|
4564
4890
|
if (canonical === cls) { results.push({ canonical: cls, safe: true }); continue; }
|
|
4565
|
-
const
|
|
4566
|
-
const
|
|
4891
|
+
const rawA = rawOf(ds, cls);
|
|
4892
|
+
const rawB = rawOf(ds, canonical);
|
|
4893
|
+
const a = rawA === null ? null : own(rawA, cls);
|
|
4894
|
+
const b = rawB === null ? null : own(rawB, canonical);
|
|
4567
4895
|
if (a !== null && b !== null && a === b) { results.push({ canonical, safe: true }); continue; }
|
|
4568
4896
|
if (a === null || b === null) { results.push({ canonical, safe: false }); continue; }
|
|
4569
|
-
|
|
4897
|
+
const ma = stripMirrors(rawA);
|
|
4898
|
+
const mb = stripMirrors(rawB);
|
|
4899
|
+
const sa = own(ma.css, cls);
|
|
4900
|
+
const sb = own(mb.css, canonical);
|
|
4901
|
+
if (sa === sb) {
|
|
4902
|
+
// The same CSS once the mirrors are gone. It is 'variable' only when the
|
|
4903
|
+
// canonical form ADDS mirrors and drops none; any other way to get here
|
|
4904
|
+
// differs in something else.
|
|
4905
|
+
const added = [...mb.removed].filter((v) => !ma.removed.has(v)).sort();
|
|
4906
|
+
const dropped = [...ma.removed].some((v) => !mb.removed.has(v));
|
|
4907
|
+
results.push(added.length > 0 && !dropped
|
|
4908
|
+
? { canonical, safe: false, reason: 'variable', variables: added }
|
|
4909
|
+
: { canonical, safe: false, reason: 'value' });
|
|
4910
|
+
continue;
|
|
4911
|
+
}
|
|
4912
|
+
if (declarationsOf(sa) !== declarationsOf(sb)) { results.push({ canonical, safe: false, reason: 'value' }); continue; }
|
|
4570
4913
|
// Only the selector differs. Whether the PROJECT made it differ is what
|
|
4571
4914
|
// stock Tailwind answers: the same two classes, compiled without the
|
|
4572
4915
|
// project's CSS. Equal there means a project-defined variant.
|
|
4573
4916
|
let stock = null;
|
|
4574
4917
|
try { stock = await env.loadStock(); } catch (e) {}
|
|
4575
|
-
const
|
|
4576
|
-
const
|
|
4577
|
-
|
|
4918
|
+
const xa = stock && rawOf(stock, cls);
|
|
4919
|
+
const xb = stock && rawOf(stock, canonical);
|
|
4920
|
+
const same = xa && xb && own(stripMirrors(xa).css, cls) === own(stripMirrors(xb).css, canonical);
|
|
4921
|
+
results.push({ canonical, safe: false, reason: same ? 'variant' : 'selector' });
|
|
4578
4922
|
}
|
|
4579
4923
|
return results;
|
|
4580
4924
|
}`, "", `(ds, warm) => {
|
|
@@ -4798,7 +5142,12 @@ function canonicalizeClassesSync(cssPath, classes, rem) {
|
|
|
4798
5142
|
canonical: roundRemValue(raw.canonical),
|
|
4799
5143
|
safe: raw.safe
|
|
4800
5144
|
};
|
|
4801
|
-
if (raw.reason
|
|
5145
|
+
if (raw.reason === "variable") {
|
|
5146
|
+
if (isVariableList(raw.variables)) {
|
|
5147
|
+
value.reason = raw.reason;
|
|
5148
|
+
value.variables = raw.variables;
|
|
5149
|
+
} else value.reason = "value";
|
|
5150
|
+
} else if (raw.reason) value.reason = raw.reason;
|
|
4802
5151
|
canonCache.set(cachePrefix + cls, value);
|
|
4803
5152
|
out[missingIdx[j]] = value;
|
|
4804
5153
|
}
|
|
@@ -4902,10 +5251,19 @@ function resolveByGlobMapping(mappings, filePath, baseDir) {
|
|
|
4902
5251
|
}
|
|
4903
5252
|
/**
|
|
4904
5253
|
* oxlint discovers nested configuration by walking up from each linted file
|
|
4905
|
-
* looking for files with these names
|
|
4906
|
-
*
|
|
4907
|
-
|
|
4908
|
-
|
|
5254
|
+
* looking for files with these names (oxlint 1.87: JSON, JSONC, and the JS
|
|
5255
|
+
* configs it loads through Node). We mirror that walk to find the config
|
|
5256
|
+
* directory a relative `entryPoint` should be anchored to — which is also
|
|
5257
|
+
* where an `oxlint.config.ts` passes it through `oxlint-tailwindcss/config`.
|
|
5258
|
+
* Not `vite.config.*`: under Vite+ a package's own Vite config needn't hold
|
|
5259
|
+
* any lint config, and nested configs aren't discovered there anyway.
|
|
5260
|
+
*/
|
|
5261
|
+
const OXLINT_CONFIG_NAMES = [
|
|
5262
|
+
".oxlintrc.json",
|
|
5263
|
+
".oxlintrc.jsonc",
|
|
5264
|
+
"oxlint.config.ts",
|
|
5265
|
+
"oxlint.config.mts"
|
|
5266
|
+
];
|
|
4909
5267
|
/** Memoizes the nearest-config walk per starting directory (cleared in tests). */
|
|
4910
5268
|
const nearestConfigDirCache = /* @__PURE__ */ new Map();
|
|
4911
5269
|
/**
|
|
@@ -4941,8 +5299,10 @@ function nearestConfigDir(filePath) {
|
|
|
4941
5299
|
* absolute path.
|
|
4942
5300
|
*
|
|
4943
5301
|
* Absolute paths are returned normalized and untouched. A **relative** path is
|
|
4944
|
-
* anchored to the directory of the nearest enclosing
|
|
4945
|
-
*
|
|
5302
|
+
* anchored to the directory of the nearest enclosing oxlint config
|
|
5303
|
+
* (`.oxlintrc.json`, `.oxlintrc.jsonc`, `oxlint.config.ts` or
|
|
5304
|
+
* `oxlint.config.mts` — the config oxlint applies to the file), with the CWD
|
|
5305
|
+
* as a single fallback:
|
|
4946
5306
|
*
|
|
4947
5307
|
* 1. nearest config dir — if its candidate file exists, use it;
|
|
4948
5308
|
* 2. CWD — if its candidate file exists, use it;
|
|
@@ -5004,7 +5364,7 @@ function getLoadedDesignSystem(cssPath, settings, engineInfo) {
|
|
|
5004
5364
|
try {
|
|
5005
5365
|
mtime = (0, node_fs.statSync)(resolvedPath).mtimeMs;
|
|
5006
5366
|
} 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`
|
|
5367
|
+
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
5368
|
}
|
|
5009
5369
|
const cached = dsCache.get(resolvedPath);
|
|
5010
5370
|
if (cached && cached.mtime === mtime) return {
|
|
@@ -5327,21 +5687,12 @@ const noUnknownClasses = defineRule({
|
|
|
5327
5687
|
}
|
|
5328
5688
|
/** Replace one class in the location and report, with a quick-fix suggestion. */
|
|
5329
5689
|
function reportWithSuggestion(loc, classes, cls, replacement, messageId, data, split) {
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5690
|
+
reportClassSuggestion(context, loc, split, classes, {
|
|
5691
|
+
cls,
|
|
5692
|
+
replacement
|
|
5693
|
+
}, {
|
|
5333
5694
|
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
|
-
}]
|
|
5695
|
+
data
|
|
5345
5696
|
});
|
|
5346
5697
|
}
|
|
5347
5698
|
function check(locations) {
|
|
@@ -5928,69 +6279,6 @@ const noConflictingClasses = defineRule({
|
|
|
5928
6279
|
}
|
|
5929
6280
|
});
|
|
5930
6281
|
//#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
6282
|
//#region src/utils/replacement.ts
|
|
5995
6283
|
/**
|
|
5996
6284
|
* Returns a predicate that answers "would this replacement produce CSS?".
|
|
@@ -6144,6 +6432,7 @@ const enforceCanonical = defineRule({
|
|
|
6144
6432
|
...SETTINGS_MESSAGE,
|
|
6145
6433
|
nonCanonical: "\"{{className}}\" can be written as \"{{canonical}}\". Use the canonical form.",
|
|
6146
6434
|
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.",
|
|
6435
|
+
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
6436
|
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\".",
|
|
6148
6437
|
...DS_UNAVAILABLE_MESSAGE
|
|
6149
6438
|
}
|
|
@@ -6162,6 +6451,7 @@ const enforceCanonical = defineRule({
|
|
|
6162
6451
|
const classes = split.classes;
|
|
6163
6452
|
const canonicals = Array.from({ length: classes.length });
|
|
6164
6453
|
const nonEquivalent = [];
|
|
6454
|
+
const addsVariables = [];
|
|
6165
6455
|
const arbitraryIdx = [];
|
|
6166
6456
|
const arbitrary = [];
|
|
6167
6457
|
for (let i = 0; i < classes.length; i++) {
|
|
@@ -6181,12 +6471,17 @@ const enforceCanonical = defineRule({
|
|
|
6181
6471
|
if (!dynamic) return;
|
|
6182
6472
|
const reportNonEquivalent = getReportNonEquivalent();
|
|
6183
6473
|
for (let k = 0; k < arbitrary.length; k++) {
|
|
6184
|
-
const { canonical, safe, reason } = dynamic[k];
|
|
6474
|
+
const { canonical, safe, reason, variables } = dynamic[k];
|
|
6185
6475
|
const idx = arbitraryIdx[k];
|
|
6186
6476
|
if (!safe && reason === "variant" && reportNonEquivalent) nonEquivalent.push({
|
|
6187
6477
|
cls: arbitrary[k],
|
|
6188
6478
|
canonical
|
|
6189
6479
|
});
|
|
6480
|
+
if (!safe && reason === "variable" && variables && reportNonEquivalent) addsVariables.push({
|
|
6481
|
+
cls: arbitrary[k],
|
|
6482
|
+
canonical: preserveImportantPosition(arbitrary[k], canonical),
|
|
6483
|
+
variables
|
|
6484
|
+
});
|
|
6190
6485
|
if (!safe) {
|
|
6191
6486
|
canonicals[idx] = arbitrary[k];
|
|
6192
6487
|
continue;
|
|
@@ -6215,6 +6510,17 @@ const enforceCanonical = defineRule({
|
|
|
6215
6510
|
}
|
|
6216
6511
|
});
|
|
6217
6512
|
}
|
|
6513
|
+
for (const { cls, canonical, variables } of addsVariables) reportClassSuggestion(context, loc, split, classes, {
|
|
6514
|
+
cls,
|
|
6515
|
+
replacement: canonical
|
|
6516
|
+
}, {
|
|
6517
|
+
messageId: "nonEquivalentVariable",
|
|
6518
|
+
data: {
|
|
6519
|
+
className: cls,
|
|
6520
|
+
canonical,
|
|
6521
|
+
variables: variables.join(", ")
|
|
6522
|
+
}
|
|
6523
|
+
});
|
|
6218
6524
|
}
|
|
6219
6525
|
}
|
|
6220
6526
|
return createExtractorVisitors(context, check);
|
|
@@ -6355,12 +6661,39 @@ const enforceSortOrder = defineRule({
|
|
|
6355
6661
|
}
|
|
6356
6662
|
});
|
|
6357
6663
|
//#endregion
|
|
6664
|
+
//#region src/utils/declared-values.ts
|
|
6665
|
+
/** A plain number or fraction: always the shared numeric/`--spacing` scale. */
|
|
6666
|
+
const NUMERIC_VALUE_RE = /^\d+(?:\.\d+)?(?:\/\d+(?:\.\d+)?)?$/;
|
|
6667
|
+
/** The value is a literal the user wrote, injected verbatim into every part. */
|
|
6668
|
+
function isWrittenValue(value) {
|
|
6669
|
+
return value.startsWith("[") || value.startsWith("(");
|
|
6670
|
+
}
|
|
6671
|
+
/**
|
|
6672
|
+
* Values the class declares on its own box, unconditionally. `null` when the
|
|
6673
|
+
* class produces nothing — which for a named token means it does not exist.
|
|
6674
|
+
*/
|
|
6675
|
+
function declaredValues(cache, cls) {
|
|
6676
|
+
const values = /* @__PURE__ */ new Set();
|
|
6677
|
+
for (const decl of cache.getCssDeclarations(cls)) {
|
|
6678
|
+
if (decl.conditional) continue;
|
|
6679
|
+
values.add(decl.value);
|
|
6680
|
+
}
|
|
6681
|
+
return values.size > 0 ? values : null;
|
|
6682
|
+
}
|
|
6683
|
+
function sameValues(a, b) {
|
|
6684
|
+
if (a.size !== b.size) return false;
|
|
6685
|
+
for (const value of a) if (!b.has(value)) return false;
|
|
6686
|
+
return true;
|
|
6687
|
+
}
|
|
6688
|
+
//#endregion
|
|
6358
6689
|
//#region src/rules/enforce-shorthand.ts
|
|
6359
6690
|
/**
|
|
6360
6691
|
* The `m`/`p` shape, shared by `margin`, `padding`, `scroll-margin` and
|
|
6361
|
-
* `scroll-padding`: four sides, each axis, and the logical
|
|
6362
|
-
*
|
|
6363
|
-
* equivalent).
|
|
6692
|
+
* `scroll-padding`: four sides, each axis, and the logical pairs (`ms`+`me` IS
|
|
6693
|
+
* `margin-inline`, `mbs`+`mbe` IS `margin-block`, so those are
|
|
6694
|
+
* property-identical rather than merely equivalent). The logical ones are what
|
|
6695
|
+
* `enforce-logical` writes, so `mt-2 mb-2` ends as `my-2` whichever of the two
|
|
6696
|
+
* rules fixes it first.
|
|
6364
6697
|
*/
|
|
6365
6698
|
function boxFamilies(p) {
|
|
6366
6699
|
return [
|
|
@@ -6373,10 +6706,23 @@ function boxFamilies(p) {
|
|
|
6373
6706
|
],
|
|
6374
6707
|
to: p
|
|
6375
6708
|
},
|
|
6709
|
+
{
|
|
6710
|
+
parts: [
|
|
6711
|
+
`${p}s`,
|
|
6712
|
+
`${p}e`,
|
|
6713
|
+
`${p}bs`,
|
|
6714
|
+
`${p}be`
|
|
6715
|
+
],
|
|
6716
|
+
to: p
|
|
6717
|
+
},
|
|
6376
6718
|
{
|
|
6377
6719
|
parts: [`${p}t`, `${p}b`],
|
|
6378
6720
|
to: `${p}y`
|
|
6379
6721
|
},
|
|
6722
|
+
{
|
|
6723
|
+
parts: [`${p}bs`, `${p}be`],
|
|
6724
|
+
to: `${p}y`
|
|
6725
|
+
},
|
|
6380
6726
|
{
|
|
6381
6727
|
parts: [`${p}l`, `${p}r`],
|
|
6382
6728
|
to: `${p}x`
|
|
@@ -6464,10 +6810,23 @@ const SHORTHAND_FAMILIES = [
|
|
|
6464
6810
|
],
|
|
6465
6811
|
to: "border"
|
|
6466
6812
|
},
|
|
6813
|
+
{
|
|
6814
|
+
parts: [
|
|
6815
|
+
"border-s",
|
|
6816
|
+
"border-e",
|
|
6817
|
+
"border-bs",
|
|
6818
|
+
"border-be"
|
|
6819
|
+
],
|
|
6820
|
+
to: "border"
|
|
6821
|
+
},
|
|
6467
6822
|
{
|
|
6468
6823
|
parts: ["border-t", "border-b"],
|
|
6469
6824
|
to: "border-y"
|
|
6470
6825
|
},
|
|
6826
|
+
{
|
|
6827
|
+
parts: ["border-bs", "border-be"],
|
|
6828
|
+
to: "border-y"
|
|
6829
|
+
},
|
|
6471
6830
|
{
|
|
6472
6831
|
parts: ["border-l", "border-r"],
|
|
6473
6832
|
to: "border-x"
|
|
@@ -6489,10 +6848,23 @@ const SHORTHAND_FAMILIES = [
|
|
|
6489
6848
|
],
|
|
6490
6849
|
to: "inset"
|
|
6491
6850
|
},
|
|
6851
|
+
{
|
|
6852
|
+
parts: [
|
|
6853
|
+
"inset-s",
|
|
6854
|
+
"inset-e",
|
|
6855
|
+
"inset-bs",
|
|
6856
|
+
"inset-be"
|
|
6857
|
+
],
|
|
6858
|
+
to: "inset"
|
|
6859
|
+
},
|
|
6492
6860
|
{
|
|
6493
6861
|
parts: ["top", "bottom"],
|
|
6494
6862
|
to: "inset-y"
|
|
6495
6863
|
},
|
|
6864
|
+
{
|
|
6865
|
+
parts: ["inset-bs", "inset-be"],
|
|
6866
|
+
to: "inset-y"
|
|
6867
|
+
},
|
|
6496
6868
|
{
|
|
6497
6869
|
parts: ["left", "right"],
|
|
6498
6870
|
to: "inset-x"
|
|
@@ -6501,6 +6873,10 @@ const SHORTHAND_FAMILIES = [
|
|
|
6501
6873
|
parts: ["start", "end"],
|
|
6502
6874
|
to: "inset-x"
|
|
6503
6875
|
},
|
|
6876
|
+
{
|
|
6877
|
+
parts: ["inset-s", "inset-e"],
|
|
6878
|
+
to: "inset-x"
|
|
6879
|
+
},
|
|
6504
6880
|
{
|
|
6505
6881
|
parts: ["inset-x", "inset-y"],
|
|
6506
6882
|
to: "inset"
|
|
@@ -6541,8 +6917,6 @@ const VALUE_RE = (() => {
|
|
|
6541
6917
|
const prefixes = [...new Set(SHORTHAND_FAMILIES.flatMap((f) => f.parts))].sort((a, b) => b.length - a.length);
|
|
6542
6918
|
return new RegExp(`^(${prefixes.join("|")})-(.+)$`);
|
|
6543
6919
|
})();
|
|
6544
|
-
/** A plain number or fraction: always the shared numeric/`--spacing` scale. */
|
|
6545
|
-
const NUMERIC_VALUE_RE = /^\d+(?:\.\d+)?(?:\/\d+(?:\.\d+)?)?$/;
|
|
6546
6920
|
/**
|
|
6547
6921
|
* Core keywords whose per-axis forms are known to agree, for when no design
|
|
6548
6922
|
* system is available to check. Deliberately excludes `screen` (`w-screen` is
|
|
@@ -6563,27 +6937,6 @@ const AXIS_SAFE_KEYWORDS = /* @__PURE__ */ new Set([
|
|
|
6563
6937
|
"svw",
|
|
6564
6938
|
"svh"
|
|
6565
6939
|
]);
|
|
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
6940
|
/**
|
|
6588
6941
|
* Would collapsing this family at this value keep the CSS identical?
|
|
6589
6942
|
*
|
|
@@ -6718,10 +7071,14 @@ const LOGICAL_PHYSICAL_SCHEMA = {
|
|
|
6718
7071
|
"both"
|
|
6719
7072
|
]
|
|
6720
7073
|
},
|
|
7074
|
+
sizing: { type: "boolean" },
|
|
6721
7075
|
entryPoint: { type: "string" }
|
|
6722
7076
|
},
|
|
6723
7077
|
additionalProperties: false
|
|
6724
7078
|
};
|
|
7079
|
+
/** Viewport units of the other axis: a width in heights, a height in widths. */
|
|
7080
|
+
const HEIGHT_UNITS = /^[dls]vh$/;
|
|
7081
|
+
const WIDTH_UNITS = /^[dls]vw$/;
|
|
6725
7082
|
const PHYSICAL_TO_LOGICAL_MAPPINGS = [
|
|
6726
7083
|
{
|
|
6727
7084
|
from: "ml",
|
|
@@ -6745,13 +7102,17 @@ const PHYSICAL_TO_LOGICAL_MAPPINGS = [
|
|
|
6745
7102
|
},
|
|
6746
7103
|
{
|
|
6747
7104
|
from: "left",
|
|
6748
|
-
to: "
|
|
6749
|
-
axis: "inline"
|
|
7105
|
+
to: "inset-s",
|
|
7106
|
+
axis: "inline",
|
|
7107
|
+
since: true,
|
|
7108
|
+
fallback: "start"
|
|
6750
7109
|
},
|
|
6751
7110
|
{
|
|
6752
7111
|
from: "right",
|
|
6753
|
-
to: "
|
|
6754
|
-
axis: "inline"
|
|
7112
|
+
to: "inset-e",
|
|
7113
|
+
axis: "inline",
|
|
7114
|
+
since: true,
|
|
7115
|
+
fallback: "end"
|
|
6755
7116
|
},
|
|
6756
7117
|
{
|
|
6757
7118
|
from: "border-l",
|
|
@@ -6848,82 +7209,294 @@ const PHYSICAL_TO_LOGICAL_MAPPINGS = [
|
|
|
6848
7209
|
to: "text-end",
|
|
6849
7210
|
axis: "inline",
|
|
6850
7211
|
exact: true
|
|
7212
|
+
},
|
|
7213
|
+
{
|
|
7214
|
+
from: "mt",
|
|
7215
|
+
to: "mbs",
|
|
7216
|
+
axis: "block",
|
|
7217
|
+
since: true
|
|
7218
|
+
},
|
|
7219
|
+
{
|
|
7220
|
+
from: "mb",
|
|
7221
|
+
to: "mbe",
|
|
7222
|
+
axis: "block",
|
|
7223
|
+
since: true
|
|
7224
|
+
},
|
|
7225
|
+
{
|
|
7226
|
+
from: "pt",
|
|
7227
|
+
to: "pbs",
|
|
7228
|
+
axis: "block",
|
|
7229
|
+
since: true
|
|
7230
|
+
},
|
|
7231
|
+
{
|
|
7232
|
+
from: "pb",
|
|
7233
|
+
to: "pbe",
|
|
7234
|
+
axis: "block",
|
|
7235
|
+
since: true
|
|
7236
|
+
},
|
|
7237
|
+
{
|
|
7238
|
+
from: "top",
|
|
7239
|
+
to: "inset-bs",
|
|
7240
|
+
axis: "block",
|
|
7241
|
+
since: true
|
|
7242
|
+
},
|
|
7243
|
+
{
|
|
7244
|
+
from: "bottom",
|
|
7245
|
+
to: "inset-be",
|
|
7246
|
+
axis: "block",
|
|
7247
|
+
since: true
|
|
7248
|
+
},
|
|
7249
|
+
{
|
|
7250
|
+
from: "border-t",
|
|
7251
|
+
to: "border-bs",
|
|
7252
|
+
axis: "block",
|
|
7253
|
+
since: true
|
|
7254
|
+
},
|
|
7255
|
+
{
|
|
7256
|
+
from: "border-b",
|
|
7257
|
+
to: "border-be",
|
|
7258
|
+
axis: "block",
|
|
7259
|
+
since: true
|
|
7260
|
+
},
|
|
7261
|
+
{
|
|
7262
|
+
from: "scroll-mt",
|
|
7263
|
+
to: "scroll-mbs",
|
|
7264
|
+
axis: "block",
|
|
7265
|
+
since: true
|
|
7266
|
+
},
|
|
7267
|
+
{
|
|
7268
|
+
from: "scroll-mb",
|
|
7269
|
+
to: "scroll-mbe",
|
|
7270
|
+
axis: "block",
|
|
7271
|
+
since: true
|
|
7272
|
+
},
|
|
7273
|
+
{
|
|
7274
|
+
from: "scroll-pt",
|
|
7275
|
+
to: "scroll-pbs",
|
|
7276
|
+
axis: "block",
|
|
7277
|
+
since: true
|
|
7278
|
+
},
|
|
7279
|
+
{
|
|
7280
|
+
from: "scroll-pb",
|
|
7281
|
+
to: "scroll-pbe",
|
|
7282
|
+
axis: "block",
|
|
7283
|
+
since: true
|
|
7284
|
+
},
|
|
7285
|
+
{
|
|
7286
|
+
from: "w",
|
|
7287
|
+
to: "inline",
|
|
7288
|
+
axis: "inline",
|
|
7289
|
+
since: true,
|
|
7290
|
+
sizing: true,
|
|
7291
|
+
skipValues: HEIGHT_UNITS
|
|
7292
|
+
},
|
|
7293
|
+
{
|
|
7294
|
+
from: "min-w",
|
|
7295
|
+
to: "min-inline",
|
|
7296
|
+
axis: "inline",
|
|
7297
|
+
since: true,
|
|
7298
|
+
sizing: true,
|
|
7299
|
+
skipValues: HEIGHT_UNITS
|
|
7300
|
+
},
|
|
7301
|
+
{
|
|
7302
|
+
from: "max-w",
|
|
7303
|
+
to: "max-inline",
|
|
7304
|
+
axis: "inline",
|
|
7305
|
+
since: true,
|
|
7306
|
+
sizing: true,
|
|
7307
|
+
skipValues: /^(?:[dls]vh|prose|screen-.+)$/
|
|
7308
|
+
},
|
|
7309
|
+
{
|
|
7310
|
+
from: "h",
|
|
7311
|
+
to: "block",
|
|
7312
|
+
axis: "block",
|
|
7313
|
+
since: true,
|
|
7314
|
+
sizing: true,
|
|
7315
|
+
skipValues: WIDTH_UNITS
|
|
7316
|
+
},
|
|
7317
|
+
{
|
|
7318
|
+
from: "min-h",
|
|
7319
|
+
to: "min-block",
|
|
7320
|
+
axis: "block",
|
|
7321
|
+
since: true,
|
|
7322
|
+
sizing: true,
|
|
7323
|
+
skipValues: WIDTH_UNITS
|
|
7324
|
+
},
|
|
7325
|
+
{
|
|
7326
|
+
from: "max-h",
|
|
7327
|
+
to: "max-block",
|
|
7328
|
+
axis: "block",
|
|
7329
|
+
since: true,
|
|
7330
|
+
sizing: true,
|
|
7331
|
+
skipValues: WIDTH_UNITS
|
|
7332
|
+
},
|
|
7333
|
+
{
|
|
7334
|
+
from: "size",
|
|
7335
|
+
to: ["inline", "block"],
|
|
7336
|
+
axis: "both",
|
|
7337
|
+
since: true,
|
|
7338
|
+
sizing: true,
|
|
7339
|
+
skipValues: /^[dls]v[hw]$/
|
|
6851
7340
|
}
|
|
6852
7341
|
];
|
|
6853
7342
|
/**
|
|
6854
|
-
*
|
|
6855
|
-
*
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6861
|
-
|
|
6862
|
-
|
|
6863
|
-
|
|
6864
|
-
|
|
6865
|
-
|
|
6866
|
-
|
|
6867
|
-
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
|
|
6871
|
-
to: "right",
|
|
6872
|
-
axis: "inline"
|
|
6873
|
-
}];
|
|
6874
|
-
/** Invert a directional table. enforce-physical consumes this. */
|
|
7343
|
+
* `inline` and `block` are display utilities too: `inline-flex` must never read
|
|
7344
|
+
* as an inline size, nor `block` as a block size.
|
|
7345
|
+
*/
|
|
7346
|
+
const DISPLAY_CLASSES = /* @__PURE__ */ new Set([
|
|
7347
|
+
"inline",
|
|
7348
|
+
"block",
|
|
7349
|
+
"inline-block",
|
|
7350
|
+
"inline-flex",
|
|
7351
|
+
"inline-grid",
|
|
7352
|
+
"inline-table"
|
|
7353
|
+
]);
|
|
7354
|
+
/**
|
|
7355
|
+
* Invert a directional table. enforce-physical consumes this. A two-axis entry
|
|
7356
|
+
* has no single inverse (`inline-4 block-4` convert one by one), and an entry
|
|
7357
|
+
* with a `fallback` inverts both spellings: `inset-s-2` and `start-2` are both
|
|
7358
|
+
* `left-2`.
|
|
7359
|
+
*/
|
|
6875
7360
|
function invertAxisMappings(mappings) {
|
|
6876
|
-
return mappings.
|
|
6877
|
-
|
|
6878
|
-
|
|
6879
|
-
|
|
6880
|
-
|
|
7361
|
+
return mappings.flatMap((m) => {
|
|
7362
|
+
if (typeof m.to !== "string") return [];
|
|
7363
|
+
const back = {
|
|
7364
|
+
from: m.to,
|
|
7365
|
+
to: m.from,
|
|
7366
|
+
axis: m.axis
|
|
7367
|
+
};
|
|
7368
|
+
if (m.exact) back.exact = m.exact;
|
|
7369
|
+
if (m.sizing) back.sizing = m.sizing;
|
|
7370
|
+
return m.fallback ? [back, {
|
|
7371
|
+
...back,
|
|
7372
|
+
from: m.fallback
|
|
7373
|
+
}] : [back];
|
|
7374
|
+
});
|
|
7375
|
+
}
|
|
7376
|
+
/** Does the project's Tailwind have this utility? See `AxisMapping.since`. */
|
|
7377
|
+
function hasUtility(cache, root) {
|
|
7378
|
+
return cache.isKnownClass(`${root}-0`);
|
|
7379
|
+
}
|
|
7380
|
+
/**
|
|
7381
|
+
* The same value under the new prefixes? Numbers, fractions and written values
|
|
7382
|
+
* read the same scale or nothing at all; a named token is settled by the CSS.
|
|
7383
|
+
*/
|
|
7384
|
+
function sameSizing(cache, value, source, targets) {
|
|
7385
|
+
if (NUMERIC_VALUE_RE.test(value) || isWrittenValue(value)) return true;
|
|
7386
|
+
const expected = declaredValues(cache, source);
|
|
7387
|
+
if (!expected) return false;
|
|
7388
|
+
const actual = /* @__PURE__ */ new Set();
|
|
7389
|
+
for (const target of targets) {
|
|
7390
|
+
const values = declaredValues(cache, target);
|
|
7391
|
+
if (!values) return false;
|
|
7392
|
+
for (const v of values) actual.add(v);
|
|
7393
|
+
}
|
|
7394
|
+
return sameValues(expected, actual);
|
|
7395
|
+
}
|
|
7396
|
+
/**
|
|
7397
|
+
* One class through a directional table: what it should be written as, or null
|
|
7398
|
+
* when the table has nothing for it or the replacement can't be trusted. Pure,
|
|
7399
|
+
* so the Tailwind 4.1 case (no 4.2 utilities) is testable with a hand-built
|
|
7400
|
+
* design system.
|
|
7401
|
+
*/
|
|
7402
|
+
function convertDirectional(cls, mappings, options, cache) {
|
|
7403
|
+
if (matchesAny(cls, options.allowlist)) return null;
|
|
7404
|
+
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
7405
|
+
const { bare: bareUtility, position } = splitImportant(utility);
|
|
7406
|
+
const negative = bareUtility.startsWith("-");
|
|
7407
|
+
const core = negative ? bareUtility.slice(1) : bareUtility;
|
|
7408
|
+
const isUsable = makeReplacementGuard(cache);
|
|
7409
|
+
for (const mapping of mappings) {
|
|
7410
|
+
const { from, to, axis, exact, sizing } = mapping;
|
|
7411
|
+
if (options.direction !== "both" && options.direction !== axis) continue;
|
|
7412
|
+
if (sizing && !options.sizing) continue;
|
|
7413
|
+
if (!(core === from || !exact && core.startsWith(`${from}-`))) continue;
|
|
7414
|
+
if (sizing && (core === from || DISPLAY_CLASSES.has(core))) continue;
|
|
7415
|
+
const suffix = core.slice(from.length);
|
|
7416
|
+
const value = suffix.slice(1);
|
|
7417
|
+
if (mapping.skipValues?.test(value)) return null;
|
|
7418
|
+
const prefixes = typeof to === "string" ? [to] : [...to];
|
|
7419
|
+
const build = (prefix) => `${variant}${reattachImportant(`${negative ? "-" : ""}${prefix}${suffix}`, position)}`;
|
|
7420
|
+
const halves = prefixes.map(build);
|
|
7421
|
+
const replacement = halves.join(" ");
|
|
7422
|
+
if (!mapping.since) return isUsable(replacement) ? {
|
|
7423
|
+
replacement,
|
|
7424
|
+
suggestOnly: false,
|
|
7425
|
+
mapping
|
|
7426
|
+
} : null;
|
|
7427
|
+
if (!cache) return mapping.fallback ? {
|
|
7428
|
+
replacement: build(mapping.fallback),
|
|
7429
|
+
suggestOnly: false,
|
|
7430
|
+
mapping
|
|
7431
|
+
} : {
|
|
7432
|
+
replacement,
|
|
7433
|
+
suggestOnly: true,
|
|
7434
|
+
mapping
|
|
7435
|
+
};
|
|
7436
|
+
if (prefixes.every((prefix) => hasUtility(cache, prefix)) && halves.every(isUsable) && (!sizing || sameSizing(cache, value, `${from}${suffix}`, prefixes.map((p) => `${p}${suffix}`)))) return {
|
|
7437
|
+
replacement,
|
|
7438
|
+
suggestOnly: false,
|
|
7439
|
+
mapping
|
|
7440
|
+
};
|
|
7441
|
+
if (mapping.fallback && isUsable(build(mapping.fallback))) return {
|
|
7442
|
+
replacement: build(mapping.fallback),
|
|
7443
|
+
suggestOnly: false,
|
|
7444
|
+
mapping
|
|
7445
|
+
};
|
|
7446
|
+
return null;
|
|
7447
|
+
}
|
|
7448
|
+
return null;
|
|
6881
7449
|
}
|
|
6882
7450
|
/**
|
|
6883
7451
|
* Build the `check` callback for a directional-rewrite rule. Both
|
|
6884
7452
|
* enforce-logical and enforce-physical instantiate this with their own
|
|
6885
|
-
* mapping table and
|
|
7453
|
+
* mapping table and messageIds; the rule's `createOnce` wires it through
|
|
6886
7454
|
* `createExtractorVisitors`.
|
|
6887
7455
|
*
|
|
6888
|
-
* Owns: option compilation (allowlist + direction), per-class
|
|
6889
|
-
* (
|
|
6890
|
-
*
|
|
7456
|
+
* Owns: option compilation (allowlist + direction + sizing), the per-class
|
|
7457
|
+
* conversion (`convertDirectional`), and the report: autofixes through
|
|
7458
|
+
* `reportClassReplacements`, suggestion-only conversions through
|
|
7459
|
+
* `reportClassSuggestion`, so a suggestion never rides along in the autofix.
|
|
6891
7460
|
*/
|
|
6892
7461
|
function createDirectionalMapper(context, opts) {
|
|
6893
|
-
const
|
|
7462
|
+
const getOptions = createLazyOptions(context, (o) => ({
|
|
6894
7463
|
allowlist: compileRegexList(o?.allowlist),
|
|
6895
|
-
direction: o?.direction ?? "both"
|
|
7464
|
+
direction: o?.direction ?? "both",
|
|
7465
|
+
sizing: o?.sizing === true
|
|
6896
7466
|
}));
|
|
6897
7467
|
const getDS = createLazyLoader(context);
|
|
6898
|
-
|
|
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
|
-
}
|
|
7468
|
+
const messageIdFor = ({ axis, sizing }) => opts.writingModeMessageId && (axis !== "inline" || sizing) ? opts.writingModeMessageId : opts.messageId;
|
|
6913
7469
|
function check(locations) {
|
|
6914
7470
|
const ds = softGetDS(getDS);
|
|
6915
|
-
const
|
|
7471
|
+
const cache = ds ? ds.cache : null;
|
|
7472
|
+
const options = getOptions();
|
|
6916
7473
|
for (const loc of locations) {
|
|
6917
7474
|
const split = splitClassesWithSeparators(loc.value);
|
|
6918
|
-
const
|
|
6919
|
-
|
|
6920
|
-
|
|
6921
|
-
|
|
7475
|
+
const fixes = [];
|
|
7476
|
+
const suggestions = [];
|
|
7477
|
+
for (const cls of split.classes) {
|
|
7478
|
+
const conversion = convertDirectional(cls, opts.mappings, options, cache);
|
|
7479
|
+
if (!conversion) continue;
|
|
7480
|
+
const messageId = messageIdFor(conversion.mapping);
|
|
7481
|
+
const entry = {
|
|
6922
7482
|
cls,
|
|
6923
|
-
replacement:
|
|
6924
|
-
|
|
7483
|
+
replacement: conversion.replacement,
|
|
7484
|
+
messageId
|
|
7485
|
+
};
|
|
7486
|
+
if (conversion.suggestOnly) suggestions.push(entry);
|
|
7487
|
+
else fixes.push(entry);
|
|
7488
|
+
}
|
|
7489
|
+
reportClassReplacements(context, loc, split, split.classes, fixes, { messageId: opts.messageId });
|
|
7490
|
+
for (const { cls, replacement, messageId } of suggestions) reportClassSuggestion(context, loc, split, split.classes, {
|
|
7491
|
+
cls,
|
|
7492
|
+
replacement
|
|
7493
|
+
}, {
|
|
7494
|
+
messageId,
|
|
7495
|
+
data: {
|
|
7496
|
+
className: cls,
|
|
7497
|
+
replacement
|
|
7498
|
+
}
|
|
6925
7499
|
});
|
|
6926
|
-
reportClassReplacements(context, loc, split, split.classes, offending, { messageId: opts.messageId });
|
|
6927
7500
|
}
|
|
6928
7501
|
}
|
|
6929
7502
|
return { check };
|
|
@@ -6942,24 +7515,28 @@ const enforceLogical = defineRule({
|
|
|
6942
7515
|
hasSuggestions: true,
|
|
6943
7516
|
defaultOptions: [{
|
|
6944
7517
|
allowlist: [],
|
|
6945
|
-
direction: "both"
|
|
7518
|
+
direction: "both",
|
|
7519
|
+
sizing: false
|
|
6946
7520
|
}],
|
|
6947
7521
|
messages: {
|
|
6948
7522
|
...SETTINGS_MESSAGE,
|
|
6949
7523
|
useLogical: "\"{{className}}\" uses a physical property. Use \"{{replacement}}\" for LTR/RTL support.",
|
|
7524
|
+
useLogicalWritingMode: "\"{{className}}\" uses a physical property. Use \"{{replacement}}\" so it follows the writing mode.",
|
|
6950
7525
|
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\"."
|
|
6951
7526
|
}
|
|
6952
7527
|
},
|
|
6953
7528
|
createOnce(context) {
|
|
6954
7529
|
const { check } = createDirectionalMapper(context, {
|
|
6955
7530
|
mappings: PHYSICAL_TO_LOGICAL_MAPPINGS,
|
|
6956
|
-
messageId: "useLogical"
|
|
7531
|
+
messageId: "useLogical",
|
|
7532
|
+
writingModeMessageId: "useLogicalWritingMode"
|
|
6957
7533
|
});
|
|
6958
7534
|
return createExtractorVisitors(context, check);
|
|
6959
7535
|
}
|
|
6960
7536
|
});
|
|
6961
7537
|
//#endregion
|
|
6962
7538
|
//#region src/rules/enforce-physical.ts
|
|
7539
|
+
const PHYSICAL_MAPPINGS = invertAxisMappings(PHYSICAL_TO_LOGICAL_MAPPINGS);
|
|
6963
7540
|
const enforcePhysical = defineRule({
|
|
6964
7541
|
meta: {
|
|
6965
7542
|
type: "suggestion",
|
|
@@ -6974,7 +7551,8 @@ const enforcePhysical = defineRule({
|
|
|
6974
7551
|
hasSuggestions: true,
|
|
6975
7552
|
defaultOptions: [{
|
|
6976
7553
|
allowlist: [],
|
|
6977
|
-
direction: "both"
|
|
7554
|
+
direction: "both",
|
|
7555
|
+
sizing: false
|
|
6978
7556
|
}],
|
|
6979
7557
|
messages: {
|
|
6980
7558
|
...SETTINGS_MESSAGE,
|
|
@@ -6984,7 +7562,7 @@ const enforcePhysical = defineRule({
|
|
|
6984
7562
|
},
|
|
6985
7563
|
createOnce(context) {
|
|
6986
7564
|
const { check } = createDirectionalMapper(context, {
|
|
6987
|
-
mappings:
|
|
7565
|
+
mappings: PHYSICAL_MAPPINGS,
|
|
6988
7566
|
messageId: "usePhysical"
|
|
6989
7567
|
});
|
|
6990
7568
|
return createExtractorVisitors(context, check);
|
|
@@ -8372,6 +8950,12 @@ const consistentVariantOrder = defineRule({
|
|
|
8372
8950
|
//#region src/rules/enforce-consistent-line-wrapping.ts
|
|
8373
8951
|
const DEFAULT_PRINT_WIDTH = 80;
|
|
8374
8952
|
const DEFAULT_GROUP = "newLine";
|
|
8953
|
+
const DEFAULT_WRAP_STRINGS = "never";
|
|
8954
|
+
/** A JSX attribute's own string: `className="…"`, not `className={"…"}` (#216). */
|
|
8955
|
+
function isJsxAttributeString(loc) {
|
|
8956
|
+
const node = loc.node;
|
|
8957
|
+
return node.type === "Literal" && node.parent?.type === "JSXAttribute";
|
|
8958
|
+
}
|
|
8375
8959
|
/** One indentation level added below the statement's base indent for wrapped lines. */
|
|
8376
8960
|
const INDENT_UNIT = " ";
|
|
8377
8961
|
/** Group `classes` into chunks of at most `n`, each chunk space-joined. */
|
|
@@ -8473,13 +9057,18 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
8473
9057
|
"emptyLine",
|
|
8474
9058
|
"never"
|
|
8475
9059
|
]
|
|
9060
|
+
},
|
|
9061
|
+
wrapStrings: {
|
|
9062
|
+
type: "string",
|
|
9063
|
+
enum: ["never", "jsx"]
|
|
8476
9064
|
}
|
|
8477
9065
|
},
|
|
8478
9066
|
additionalProperties: false
|
|
8479
9067
|
}],
|
|
8480
9068
|
defaultOptions: [{
|
|
8481
9069
|
printWidth: DEFAULT_PRINT_WIDTH,
|
|
8482
|
-
group: DEFAULT_GROUP
|
|
9070
|
+
group: DEFAULT_GROUP,
|
|
9071
|
+
wrapStrings: DEFAULT_WRAP_STRINGS
|
|
8483
9072
|
}],
|
|
8484
9073
|
messages: {
|
|
8485
9074
|
...SETTINGS_MESSAGE,
|
|
@@ -8493,6 +9082,7 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
8493
9082
|
const getClassesPerLine = createLazyOptions(context, (o) => o?.classesPerLine);
|
|
8494
9083
|
const getWrapLines = createLazyOptions(context, (o) => o?.wrapLines);
|
|
8495
9084
|
const getGroup = createLazyOptions(context, (o) => o?.group ?? DEFAULT_GROUP);
|
|
9085
|
+
const getWrapStrings = createLazyOptions(context, (o) => o?.wrapStrings ?? DEFAULT_WRAP_STRINGS);
|
|
8496
9086
|
const getDS = createLazyLoader(context);
|
|
8497
9087
|
/**
|
|
8498
9088
|
* The statement's real base indentation — the leading whitespace of the
|
|
@@ -8512,6 +9102,19 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
8512
9102
|
return "";
|
|
8513
9103
|
}
|
|
8514
9104
|
/**
|
|
9105
|
+
* The line ending a JSX string's fix writes. A JSX attribute keeps the
|
|
9106
|
+
* file's `\r\n` in its value (a template's is LF already), so a CRLF file
|
|
9107
|
+
* gets CRLF breaks: from the value when it has any, else from the line the
|
|
9108
|
+
* string ends on.
|
|
9109
|
+
*/
|
|
9110
|
+
function lineEndingOf(loc) {
|
|
9111
|
+
if (loc.value.includes("\r\n")) return "\r\n";
|
|
9112
|
+
const text = safeSourceCode(context)?.text;
|
|
9113
|
+
if (typeof text !== "string") return "\n";
|
|
9114
|
+
const nl = text.indexOf("\n", loc.range[1]);
|
|
9115
|
+
return nl > 0 && text[nl - 1] === "\r" ? "\r\n" : "\n";
|
|
9116
|
+
}
|
|
9117
|
+
/**
|
|
8515
9118
|
* Re-wrap a template literal's classes into the block convention,
|
|
8516
9119
|
* non-destructively:
|
|
8517
9120
|
* - single-line → convert to a `\n` + indent block (unless the quasi is
|
|
@@ -8596,7 +9199,16 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
8596
9199
|
const wrapLines = getWrapLines();
|
|
8597
9200
|
const group = getGroup();
|
|
8598
9201
|
const prefix = wrapLines === "all" && group !== "never" && classesPerLine === void 0 ? softGetDS(getDS)?.cache.prefix ?? "" : "";
|
|
8599
|
-
|
|
9202
|
+
const wrapStrings = getWrapStrings();
|
|
9203
|
+
for (const written of locations) {
|
|
9204
|
+
const wrapsString = wrapStrings === "jsx" && isJsxAttributeString(written);
|
|
9205
|
+
const fixable = written.node.type === "TemplateElement" || wrapsString;
|
|
9206
|
+
const eol = wrapsString ? lineEndingOf(written) : "\n";
|
|
9207
|
+
const loc = eol === "\n" ? written : {
|
|
9208
|
+
...written,
|
|
9209
|
+
value: written.value.replace(/\r\n/g, "\n")
|
|
9210
|
+
};
|
|
9211
|
+
const toSource = (value) => eol === "\n" ? value : value.replace(/\n/g, eol);
|
|
8600
9212
|
let maxLine = 0;
|
|
8601
9213
|
for (const line of loc.value.split("\n")) {
|
|
8602
9214
|
if (line.length <= maxLine) continue;
|
|
@@ -8609,14 +9221,14 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
8609
9221
|
};
|
|
8610
9222
|
const isMultiline = loc.value.includes("\n");
|
|
8611
9223
|
const glued = loc.preserveLeadingSpace === true && !/^\s/.test(loc.value) || loc.preserveTrailingSpace === true && !/\s$/.test(loc.value);
|
|
8612
|
-
if (wrapLines !== void 0 && classesPerLine === void 0 &&
|
|
9224
|
+
if (wrapLines !== void 0 && classesPerLine === void 0 && fixable && !glued && (maxLine > printWidth || wrapLines === "all" && isMultiline)) {
|
|
8613
9225
|
const fixedValue = wrapLines === "all" ? rewrapTemplateToWidth(loc, printWidth, group, prefix) : rewrapOverBudgetLinesToWidth(loc, printWidth);
|
|
8614
9226
|
if (fixedValue !== loc.value) context.report({
|
|
8615
9227
|
node: loc.node,
|
|
8616
9228
|
messageId: maxLine > printWidth ? "tooLong" : "inconsistentWrapping",
|
|
8617
9229
|
data,
|
|
8618
9230
|
fix(fixer) {
|
|
8619
|
-
return fixer.replaceTextRange(loc.range, fixedValue);
|
|
9231
|
+
return fixer.replaceTextRange(loc.range, toSource(fixedValue));
|
|
8620
9232
|
}
|
|
8621
9233
|
});
|
|
8622
9234
|
} else if (maxLine > printWidth) context.report({
|
|
@@ -8636,14 +9248,14 @@ const enforceConsistentLineWrapping = defineRule({
|
|
|
8636
9248
|
count: String(maxPerLine),
|
|
8637
9249
|
max: String(classesPerLine)
|
|
8638
9250
|
};
|
|
8639
|
-
if (
|
|
9251
|
+
if (fixable && !glued) {
|
|
8640
9252
|
const fixedValue = rewrapTemplate(loc, lines, classesPerLine);
|
|
8641
9253
|
context.report({
|
|
8642
9254
|
node: loc.node,
|
|
8643
9255
|
messageId: "tooManyPerLine",
|
|
8644
9256
|
data,
|
|
8645
9257
|
fix(fixer) {
|
|
8646
|
-
return fixer.replaceTextRange(loc.range, preserveSpaces(loc, fixedValue));
|
|
9258
|
+
return fixer.replaceTextRange(loc.range, toSource(preserveSpaces(loc, fixedValue)));
|
|
8647
9259
|
}
|
|
8648
9260
|
});
|
|
8649
9261
|
} else context.report({
|
|
@@ -8878,24 +9490,15 @@ const preferScaleToken = defineRule({
|
|
|
8878
9490
|
const equivalent = equivalentOf(cache, bare);
|
|
8879
9491
|
if (!equivalent) continue;
|
|
8880
9492
|
const replacement = variant + reattachImportant(equivalent, position);
|
|
8881
|
-
|
|
8882
|
-
|
|
8883
|
-
|
|
9493
|
+
reportClassSuggestion(context, loc, split, split.classes, {
|
|
9494
|
+
cls,
|
|
9495
|
+
replacement
|
|
9496
|
+
}, {
|
|
8884
9497
|
messageId: "preferToken",
|
|
8885
9498
|
data: {
|
|
8886
9499
|
className: cls,
|
|
8887
9500
|
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
|
-
}]
|
|
9501
|
+
}
|
|
8899
9502
|
});
|
|
8900
9503
|
}
|
|
8901
9504
|
}
|
|
@@ -9980,7 +10583,7 @@ function componentSignatures(files, cache, entryPoint) {
|
|
|
9980
10583
|
const signature = signatureOf(style.classes, cache, entryPoint);
|
|
9981
10584
|
const keys = [...signature.keys()];
|
|
9982
10585
|
if (signature.size < MIN_SHARED || !keys.some(isColorKey) || !keys.some(isSurfaceKey)) continue;
|
|
9983
|
-
const id = JSON.stringify([...signature].sort());
|
|
10586
|
+
const id = JSON.stringify([...signature].sort(([a], [b]) => a < b ? -1 : 1));
|
|
9984
10587
|
if (seen.has(id)) continue;
|
|
9985
10588
|
seen.add(id);
|
|
9986
10589
|
const file = (0, node_path.relative)(process.cwd(), path).split("\\").join("/");
|