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