oxlint-tailwindcss 1.3.2 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +138 -75
- package/dist/index.d.cts +4021 -1
- package/dist/index.d.mts +4021 -1
- package/dist/index.mjs +69 -5
- package/package.json +7 -10
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,73 @@
|
|
|
1
|
-
let _oxlint_plugins = require("@oxlint/plugins");
|
|
2
1
|
let node_worker_threads = require("node:worker_threads");
|
|
3
2
|
let node_crypto = require("node:crypto");
|
|
4
3
|
let node_fs = require("node:fs");
|
|
5
4
|
let node_path = require("node:path");
|
|
6
5
|
let node_os = require("node:os");
|
|
6
|
+
//#region ../../node_modules/.pnpm/@oxlint+plugins@1.72.0/node_modules/@oxlint/plugins/index.js
|
|
7
|
+
/**
|
|
8
|
+
* Define a plugin.
|
|
9
|
+
*
|
|
10
|
+
* No-op function, just to provide type safety. Input is passed through unchanged.
|
|
11
|
+
*
|
|
12
|
+
* @param plugin - Plugin to define
|
|
13
|
+
* @returns Same plugin as passed in
|
|
14
|
+
*/
|
|
15
|
+
function definePlugin(plugin) {
|
|
16
|
+
return plugin;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Define a rule.
|
|
20
|
+
*
|
|
21
|
+
* No-op function, just to provide type safety. Input is passed through unchanged.
|
|
22
|
+
*
|
|
23
|
+
* @param rule - Rule to define
|
|
24
|
+
* @returns Same rule as passed in
|
|
25
|
+
*/
|
|
26
|
+
function defineRule(rule) {
|
|
27
|
+
return rule;
|
|
28
|
+
}
|
|
29
|
+
Object.freeze({
|
|
30
|
+
get filename() {
|
|
31
|
+
throw Error("Cannot access `context.filename` in `createOnce`");
|
|
32
|
+
},
|
|
33
|
+
getFilename() {
|
|
34
|
+
throw Error("Cannot call `context.getFilename` in `createOnce`");
|
|
35
|
+
},
|
|
36
|
+
get physicalFilename() {
|
|
37
|
+
throw Error("Cannot access `context.physicalFilename` in `createOnce`");
|
|
38
|
+
},
|
|
39
|
+
getPhysicalFilename() {
|
|
40
|
+
throw Error("Cannot call `context.getPhysicalFilename` in `createOnce`");
|
|
41
|
+
},
|
|
42
|
+
get cwd() {
|
|
43
|
+
throw Error("Cannot access `context.cwd` in `createOnce`");
|
|
44
|
+
},
|
|
45
|
+
getCwd() {
|
|
46
|
+
throw Error("Cannot call `context.getCwd` in `createOnce`");
|
|
47
|
+
},
|
|
48
|
+
get sourceCode() {
|
|
49
|
+
throw Error("Cannot access `context.sourceCode` in `createOnce`");
|
|
50
|
+
},
|
|
51
|
+
getSourceCode() {
|
|
52
|
+
throw Error("Cannot call `context.getSourceCode` in `createOnce`");
|
|
53
|
+
},
|
|
54
|
+
get languageOptions() {
|
|
55
|
+
throw Error("Cannot access `context.languageOptions` in `createOnce`");
|
|
56
|
+
},
|
|
57
|
+
get settings() {
|
|
58
|
+
throw Error("Cannot access `context.settings` in `createOnce`");
|
|
59
|
+
},
|
|
60
|
+
extend(extension) {
|
|
61
|
+
return Object.freeze(Object.assign(Object.create(this), extension));
|
|
62
|
+
},
|
|
63
|
+
get parserOptions() {
|
|
64
|
+
throw Error("Cannot access `context.parserOptions` in `createOnce`");
|
|
65
|
+
},
|
|
66
|
+
get parserPath() {
|
|
67
|
+
throw Error("Cannot access `context.parserPath` in `createOnce`");
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
//#endregion
|
|
7
71
|
//#region src/utils/allowlist.ts
|
|
8
72
|
/**
|
|
9
73
|
* Shared regex-allowlist helpers used by rules that accept an `allowlist`
|
|
@@ -473,7 +537,7 @@ function rebuildClassString(split, newClasses) {
|
|
|
473
537
|
}
|
|
474
538
|
//#endregion
|
|
475
539
|
//#region src/rules/no-duplicate-classes.ts
|
|
476
|
-
const noDuplicateClasses =
|
|
540
|
+
const noDuplicateClasses = defineRule({
|
|
477
541
|
meta: {
|
|
478
542
|
type: "problem",
|
|
479
543
|
docs: { description: "Disallow duplicate Tailwind CSS classes" },
|
|
@@ -508,7 +572,7 @@ const noDuplicateClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
508
572
|
});
|
|
509
573
|
//#endregion
|
|
510
574
|
//#region src/rules/no-unnecessary-whitespace.ts
|
|
511
|
-
const noUnnecessaryWhitespace =
|
|
575
|
+
const noUnnecessaryWhitespace = defineRule({
|
|
512
576
|
meta: {
|
|
513
577
|
type: "suggestion",
|
|
514
578
|
docs: { description: "Disallow unnecessary whitespace in Tailwind CSS class strings" },
|
|
@@ -721,7 +785,7 @@ function reattachImportant(bare, position) {
|
|
|
721
785
|
* `consistent-variant-order` (partitions them last) and
|
|
722
786
|
* `no-contradicting-variants` (they can't contradict a base class).
|
|
723
787
|
*/
|
|
724
|
-
const PSEUDO_ELEMENT_VARIANTS = new Set([
|
|
788
|
+
const PSEUDO_ELEMENT_VARIANTS = /* @__PURE__ */ new Set([
|
|
725
789
|
"before",
|
|
726
790
|
"after",
|
|
727
791
|
"file",
|
|
@@ -1696,7 +1760,7 @@ const IMPORT_RE = /@import\s+(?:url\(\s*)?['"]([^'"]+)['"]/g;
|
|
|
1696
1760
|
*/
|
|
1697
1761
|
function hashableContent(entryPath, entryContent) {
|
|
1698
1762
|
const parts = [entryContent];
|
|
1699
|
-
const seen = new Set([(0, node_path.resolve)(entryPath)]);
|
|
1763
|
+
const seen = /* @__PURE__ */ new Set([(0, node_path.resolve)(entryPath)]);
|
|
1700
1764
|
const visit = (cssPath, content, depth) => {
|
|
1701
1765
|
if (depth <= 0) return;
|
|
1702
1766
|
const baseDir = (0, node_path.dirname)(cssPath);
|
|
@@ -2407,7 +2471,7 @@ const DEPRECATED_MAP = {
|
|
|
2407
2471
|
"bg-gradient-to-l": "bg-linear-to-l",
|
|
2408
2472
|
"bg-gradient-to-tl": "bg-linear-to-tl"
|
|
2409
2473
|
};
|
|
2410
|
-
const noDeprecatedClasses =
|
|
2474
|
+
const noDeprecatedClasses = defineRule({
|
|
2411
2475
|
meta: {
|
|
2412
2476
|
type: "problem",
|
|
2413
2477
|
docs: { description: "Disallow deprecated Tailwind CSS v4 classes" },
|
|
@@ -2449,7 +2513,7 @@ const noDeprecatedClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2449
2513
|
});
|
|
2450
2514
|
//#endregion
|
|
2451
2515
|
//#region src/rules/no-unknown-classes.ts
|
|
2452
|
-
const noUnknownClasses =
|
|
2516
|
+
const noUnknownClasses = defineRule({
|
|
2453
2517
|
meta: {
|
|
2454
2518
|
type: "problem",
|
|
2455
2519
|
docs: { description: "Disallow classes that are not defined in the Tailwind CSS design system" },
|
|
@@ -2689,7 +2753,7 @@ function shouldSkipPair(a, b, propsA, propsB, rules = {}) {
|
|
|
2689
2753
|
for (const { a: reA, b: reB } of pairs) if (reA.test(ua) && reB.test(ub) || reA.test(ub) && reB.test(ua)) return true;
|
|
2690
2754
|
return false;
|
|
2691
2755
|
}
|
|
2692
|
-
const noConflictingClasses =
|
|
2756
|
+
const noConflictingClasses = defineRule({
|
|
2693
2757
|
meta: {
|
|
2694
2758
|
type: "problem",
|
|
2695
2759
|
docs: { description: "Disallow Tailwind CSS classes that generate conflicting CSS properties" },
|
|
@@ -3073,7 +3137,7 @@ function preserveImportantPosition(original, canonicalized) {
|
|
|
3073
3137
|
const bare = splitImportant(utility).bare;
|
|
3074
3138
|
return variant + reattachImportant(bare, position);
|
|
3075
3139
|
}
|
|
3076
|
-
const enforceCanonical =
|
|
3140
|
+
const enforceCanonical = defineRule({
|
|
3077
3141
|
meta: {
|
|
3078
3142
|
type: "suggestion",
|
|
3079
3143
|
docs: { description: "Enforce canonical Tailwind CSS class names using canonicalizeCandidates()" },
|
|
@@ -3167,7 +3231,7 @@ function sortClassesSync(cssPath, classes) {
|
|
|
3167
3231
|
}
|
|
3168
3232
|
//#endregion
|
|
3169
3233
|
//#region src/rules/enforce-sort-order.ts
|
|
3170
|
-
const enforceSortOrder =
|
|
3234
|
+
const enforceSortOrder = defineRule({
|
|
3171
3235
|
meta: {
|
|
3172
3236
|
type: "suggestion",
|
|
3173
3237
|
docs: { description: "Enforce consistent sort order of Tailwind CSS classes using the official class order" },
|
|
@@ -3260,7 +3324,7 @@ const enforceSortOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
3260
3324
|
//#endregion
|
|
3261
3325
|
//#region src/rules/enforce-shorthand.ts
|
|
3262
3326
|
const VALUE_RE = /^(?:m[trbl]|mx|my|p[trbl]|px|py|[wh]|rounded-t[lr]|rounded-b[lr]|min-[wh]|max-[wh])-(.+)$/;
|
|
3263
|
-
const INVALID_SIZE_VALUES = new Set([
|
|
3327
|
+
const INVALID_SIZE_VALUES = /* @__PURE__ */ new Set([
|
|
3264
3328
|
"screen",
|
|
3265
3329
|
"dvw",
|
|
3266
3330
|
"dvh",
|
|
@@ -3332,7 +3396,7 @@ function createShorthandRules(value) {
|
|
|
3332
3396
|
}
|
|
3333
3397
|
];
|
|
3334
3398
|
}
|
|
3335
|
-
const enforceShorthand =
|
|
3399
|
+
const enforceShorthand = defineRule({
|
|
3336
3400
|
meta: {
|
|
3337
3401
|
type: "suggestion",
|
|
3338
3402
|
docs: { description: "Enforce shorthand Tailwind CSS classes when all axes have the same value" },
|
|
@@ -3553,7 +3617,7 @@ function createDirectionalMapper(context, opts) {
|
|
|
3553
3617
|
}
|
|
3554
3618
|
return { check };
|
|
3555
3619
|
}
|
|
3556
|
-
const enforceLogical =
|
|
3620
|
+
const enforceLogical = defineRule({
|
|
3557
3621
|
meta: {
|
|
3558
3622
|
type: "suggestion",
|
|
3559
3623
|
docs: { description: "Enforce logical (RTL-friendly) Tailwind CSS properties instead of physical ones" },
|
|
@@ -3579,7 +3643,7 @@ const enforceLogical = (0, _oxlint_plugins.defineRule)({
|
|
|
3579
3643
|
});
|
|
3580
3644
|
//#endregion
|
|
3581
3645
|
//#region src/rules/enforce-physical.ts
|
|
3582
|
-
const enforcePhysical =
|
|
3646
|
+
const enforcePhysical = defineRule({
|
|
3583
3647
|
meta: {
|
|
3584
3648
|
type: "suggestion",
|
|
3585
3649
|
docs: { description: "Enforce physical Tailwind CSS properties instead of logical ones for consistency in LTR-only projects" },
|
|
@@ -3606,7 +3670,7 @@ const enforcePhysical = (0, _oxlint_plugins.defineRule)({
|
|
|
3606
3670
|
//#endregion
|
|
3607
3671
|
//#region src/rules/max-class-count.ts
|
|
3608
3672
|
const DEFAULT_MAX = 20;
|
|
3609
|
-
const maxClassCount =
|
|
3673
|
+
const maxClassCount = defineRule({
|
|
3610
3674
|
meta: {
|
|
3611
3675
|
type: "suggestion",
|
|
3612
3676
|
docs: { description: "Enforce a maximum number of Tailwind CSS classes per element" },
|
|
@@ -3639,7 +3703,7 @@ const maxClassCount = (0, _oxlint_plugins.defineRule)({
|
|
|
3639
3703
|
});
|
|
3640
3704
|
//#endregion
|
|
3641
3705
|
//#region src/rules/no-restricted-classes.ts
|
|
3642
|
-
const noRestrictedClasses =
|
|
3706
|
+
const noRestrictedClasses = defineRule({
|
|
3643
3707
|
meta: {
|
|
3644
3708
|
type: "problem",
|
|
3645
3709
|
docs: { description: "Disallow specific Tailwind CSS classes" },
|
|
@@ -3726,7 +3790,7 @@ const noRestrictedClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
3726
3790
|
});
|
|
3727
3791
|
//#endregion
|
|
3728
3792
|
//#region src/rules/no-arbitrary-value.ts
|
|
3729
|
-
const noArbitraryValue =
|
|
3793
|
+
const noArbitraryValue = defineRule({
|
|
3730
3794
|
meta: {
|
|
3731
3795
|
type: "suggestion",
|
|
3732
3796
|
docs: { description: "Disallow arbitrary values in Tailwind CSS classes" },
|
|
@@ -3766,7 +3830,7 @@ const noArbitraryValue = (0, _oxlint_plugins.defineRule)({
|
|
|
3766
3830
|
});
|
|
3767
3831
|
//#endregion
|
|
3768
3832
|
//#region src/rules/enforce-consistent-important-position.ts
|
|
3769
|
-
const enforceConsistentImportantPosition =
|
|
3833
|
+
const enforceConsistentImportantPosition = defineRule({
|
|
3770
3834
|
meta: {
|
|
3771
3835
|
type: "suggestion",
|
|
3772
3836
|
docs: { description: "Enforce consistent position of the important (!) modifier. Default: suffix (Tailwind v4 canonical form). Note: using \"prefix\" may conflict with enforce-canonical which normalizes to suffix." },
|
|
@@ -3836,7 +3900,7 @@ function fixClass(cls) {
|
|
|
3836
3900
|
* Detects `-utility-[value]` and suggests `utility-[-value]`.
|
|
3837
3901
|
* e.g. `-top-[5px]` → `top-[-5px]`
|
|
3838
3902
|
*/
|
|
3839
|
-
const enforceNegativeArbitraryValues =
|
|
3903
|
+
const enforceNegativeArbitraryValues = defineRule({
|
|
3840
3904
|
meta: {
|
|
3841
3905
|
type: "suggestion",
|
|
3842
3906
|
docs: { description: "Enforce moving the negative sign inside arbitrary value brackets: -top-[5px] → top-[-5px]" },
|
|
@@ -3887,7 +3951,7 @@ function convertClass(cls, syntax) {
|
|
|
3887
3951
|
}
|
|
3888
3952
|
return null;
|
|
3889
3953
|
}
|
|
3890
|
-
const enforceConsistentVariableSyntax =
|
|
3954
|
+
const enforceConsistentVariableSyntax = defineRule({
|
|
3891
3955
|
meta: {
|
|
3892
3956
|
type: "suggestion",
|
|
3893
3957
|
docs: { description: "Enforce consistent CSS variable syntax: bg-[var(--color)] ↔ bg-(--color)" },
|
|
@@ -4009,7 +4073,7 @@ function getUtilityPrefix(utility) {
|
|
|
4009
4073
|
const dashIdx = u.indexOf("-");
|
|
4010
4074
|
return dashIdx >= 0 ? u.slice(0, dashIdx) : u;
|
|
4011
4075
|
}
|
|
4012
|
-
const noDarkWithoutLight =
|
|
4076
|
+
const noDarkWithoutLight = defineRule({
|
|
4013
4077
|
meta: {
|
|
4014
4078
|
type: "problem",
|
|
4015
4079
|
docs: { description: "Require a base (light) utility when using dark: (or other scheme) variant" },
|
|
@@ -4106,7 +4170,7 @@ function isColorUtility(utility) {
|
|
|
4106
4170
|
for (const prefix of COLOR_UTILITY_PREFIXES) if (utility === prefix || utility.startsWith(`${prefix}-`)) return true;
|
|
4107
4171
|
return false;
|
|
4108
4172
|
}
|
|
4109
|
-
const noHardcodedColors =
|
|
4173
|
+
const noHardcodedColors = defineRule({
|
|
4110
4174
|
meta: {
|
|
4111
4175
|
type: "suggestion",
|
|
4112
4176
|
docs: { description: "Disallow hardcoded color values in Tailwind CSS classes" },
|
|
@@ -4147,7 +4211,7 @@ const noHardcodedColors = (0, _oxlint_plugins.defineRule)({
|
|
|
4147
4211
|
});
|
|
4148
4212
|
//#endregion
|
|
4149
4213
|
//#region src/rules/no-contradicting-variants.ts
|
|
4150
|
-
const noContradictingVariants =
|
|
4214
|
+
const noContradictingVariants = defineRule({
|
|
4151
4215
|
meta: {
|
|
4152
4216
|
type: "suggestion",
|
|
4153
4217
|
docs: { description: "Disallow variant-prefixed classes that are redundant because the base class already applies unconditionally" },
|
|
@@ -4254,7 +4318,7 @@ const DEFAULT_VARIANT_ORDER = [
|
|
|
4254
4318
|
"rtl",
|
|
4255
4319
|
"open"
|
|
4256
4320
|
];
|
|
4257
|
-
const consistentVariantOrder =
|
|
4321
|
+
const consistentVariantOrder = defineRule({
|
|
4258
4322
|
meta: {
|
|
4259
4323
|
type: "suggestion",
|
|
4260
4324
|
docs: { description: "Enforce a consistent order for Tailwind CSS variant prefixes" },
|
|
@@ -4411,7 +4475,7 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
4411
4475
|
//#endregion
|
|
4412
4476
|
//#region src/rules/enforce-consistent-line-wrapping.ts
|
|
4413
4477
|
const DEFAULT_PRINT_WIDTH = 80;
|
|
4414
|
-
const enforceConsistentLineWrapping =
|
|
4478
|
+
const enforceConsistentLineWrapping = defineRule({
|
|
4415
4479
|
meta: {
|
|
4416
4480
|
type: "suggestion",
|
|
4417
4481
|
docs: { description: "Warn when a class string exceeds the configured print width" },
|
|
@@ -4480,7 +4544,7 @@ const enforceConsistentLineWrapping = (0, _oxlint_plugins.defineRule)({
|
|
|
4480
4544
|
});
|
|
4481
4545
|
//#endregion
|
|
4482
4546
|
//#region src/rules/no-unnecessary-arbitrary-value.ts
|
|
4483
|
-
const noUnnecessaryArbitraryValue =
|
|
4547
|
+
const noUnnecessaryArbitraryValue = defineRule({
|
|
4484
4548
|
meta: {
|
|
4485
4549
|
type: "suggestion",
|
|
4486
4550
|
docs: { description: "Disallow arbitrary values when a named Tailwind class produces the same CSS" },
|
|
@@ -4550,56 +4614,9 @@ function detectRawVariable(utility) {
|
|
|
4550
4614
|
};
|
|
4551
4615
|
return null;
|
|
4552
4616
|
}
|
|
4553
|
-
const preferThemeTokens = (0, _oxlint_plugins.defineRule)({
|
|
4554
|
-
meta: {
|
|
4555
|
-
type: "suggestion",
|
|
4556
|
-
docs: { description: "Prefer named theme-token utilities over raw CSS variable references when a matching utility exists" },
|
|
4557
|
-
fixable: "code",
|
|
4558
|
-
schema: [{
|
|
4559
|
-
type: "object",
|
|
4560
|
-
properties: { entryPoint: { type: "string" } },
|
|
4561
|
-
additionalProperties: false
|
|
4562
|
-
}],
|
|
4563
|
-
hasSuggestions: true,
|
|
4564
|
-
defaultOptions: [{}],
|
|
4565
|
-
messages: {
|
|
4566
|
-
preferNamed: "\"{{className}}\" can be written as \"{{replacement}}\". Use the named theme token.",
|
|
4567
|
-
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\".",
|
|
4568
|
-
...DS_UNAVAILABLE_MESSAGE
|
|
4569
|
-
}
|
|
4570
|
-
},
|
|
4571
|
-
createOnce(context) {
|
|
4572
|
-
const getDS = createLazyLoader(context);
|
|
4573
|
-
function check(locations) {
|
|
4574
|
-
if (locations.length === 0) return;
|
|
4575
|
-
const ds = safeGetDS(getDS, context, locations[0].node);
|
|
4576
|
-
if (!ds) return;
|
|
4577
|
-
const { cache } = ds;
|
|
4578
|
-
for (const loc of locations) {
|
|
4579
|
-
const split = splitClassesWithSeparators(loc.value);
|
|
4580
|
-
const offending = split.classes.flatMap((cls) => {
|
|
4581
|
-
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
4582
|
-
const { bare: bareUtility, position } = splitImportant(utility);
|
|
4583
|
-
const match = detectRawVariable(bareUtility);
|
|
4584
|
-
if (!match) return [];
|
|
4585
|
-
const candidate = `${match.prefix}-${match.varName}${match.modifier}`;
|
|
4586
|
-
if (!cache.isValid(candidate)) return [];
|
|
4587
|
-
const namedEquivalent = cache.getNamedEquivalent(bareUtility);
|
|
4588
|
-
if (namedEquivalent && namedEquivalent === `${match.prefix}-${match.varName}`) return [];
|
|
4589
|
-
return [{
|
|
4590
|
-
cls,
|
|
4591
|
-
replacement: variant + reattachImportant(candidate, position)
|
|
4592
|
-
}];
|
|
4593
|
-
});
|
|
4594
|
-
reportClassReplacements(context, loc, split, split.classes, offending, { messageId: "preferNamed" });
|
|
4595
|
-
}
|
|
4596
|
-
}
|
|
4597
|
-
return createExtractorVisitors(context, check);
|
|
4598
|
-
}
|
|
4599
|
-
});
|
|
4600
4617
|
//#endregion
|
|
4601
4618
|
//#region src/index.ts
|
|
4602
|
-
const plugin =
|
|
4619
|
+
const plugin = definePlugin({
|
|
4603
4620
|
meta: { name: "tailwindcss" },
|
|
4604
4621
|
rules: {
|
|
4605
4622
|
"no-duplicate-classes": noDuplicateClasses,
|
|
@@ -4624,7 +4641,53 @@ const plugin = (0, _oxlint_plugins.definePlugin)({
|
|
|
4624
4641
|
"consistent-variant-order": consistentVariantOrder,
|
|
4625
4642
|
"enforce-consistent-line-wrapping": enforceConsistentLineWrapping,
|
|
4626
4643
|
"no-unnecessary-arbitrary-value": noUnnecessaryArbitraryValue,
|
|
4627
|
-
"prefer-theme-tokens":
|
|
4644
|
+
"prefer-theme-tokens": defineRule({
|
|
4645
|
+
meta: {
|
|
4646
|
+
type: "suggestion",
|
|
4647
|
+
docs: { description: "Prefer named theme-token utilities over raw CSS variable references when a matching utility exists" },
|
|
4648
|
+
fixable: "code",
|
|
4649
|
+
schema: [{
|
|
4650
|
+
type: "object",
|
|
4651
|
+
properties: { entryPoint: { type: "string" } },
|
|
4652
|
+
additionalProperties: false
|
|
4653
|
+
}],
|
|
4654
|
+
hasSuggestions: true,
|
|
4655
|
+
defaultOptions: [{}],
|
|
4656
|
+
messages: {
|
|
4657
|
+
preferNamed: "\"{{className}}\" can be written as \"{{replacement}}\". Use the named theme token.",
|
|
4658
|
+
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\".",
|
|
4659
|
+
...DS_UNAVAILABLE_MESSAGE
|
|
4660
|
+
}
|
|
4661
|
+
},
|
|
4662
|
+
createOnce(context) {
|
|
4663
|
+
const getDS = createLazyLoader(context);
|
|
4664
|
+
function check(locations) {
|
|
4665
|
+
if (locations.length === 0) return;
|
|
4666
|
+
const ds = safeGetDS(getDS, context, locations[0].node);
|
|
4667
|
+
if (!ds) return;
|
|
4668
|
+
const { cache } = ds;
|
|
4669
|
+
for (const loc of locations) {
|
|
4670
|
+
const split = splitClassesWithSeparators(loc.value);
|
|
4671
|
+
const offending = split.classes.flatMap((cls) => {
|
|
4672
|
+
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
4673
|
+
const { bare: bareUtility, position } = splitImportant(utility);
|
|
4674
|
+
const match = detectRawVariable(bareUtility);
|
|
4675
|
+
if (!match) return [];
|
|
4676
|
+
const candidate = `${match.prefix}-${match.varName}${match.modifier}`;
|
|
4677
|
+
if (!cache.isValid(candidate)) return [];
|
|
4678
|
+
const namedEquivalent = cache.getNamedEquivalent(bareUtility);
|
|
4679
|
+
if (namedEquivalent && namedEquivalent === `${match.prefix}-${match.varName}`) return [];
|
|
4680
|
+
return [{
|
|
4681
|
+
cls,
|
|
4682
|
+
replacement: variant + reattachImportant(candidate, position)
|
|
4683
|
+
}];
|
|
4684
|
+
});
|
|
4685
|
+
reportClassReplacements(context, loc, split, split.classes, offending, { messageId: "preferNamed" });
|
|
4686
|
+
}
|
|
4687
|
+
}
|
|
4688
|
+
return createExtractorVisitors(context, check);
|
|
4689
|
+
}
|
|
4690
|
+
})
|
|
4628
4691
|
}
|
|
4629
4692
|
});
|
|
4630
4693
|
//#endregion
|