oxlint-tailwindcss 1.3.1 → 1.3.3
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 +3 -1
- package/dist/index.cjs +233 -80
- package/dist/index.d.cts +4021 -1
- package/dist/index.d.mts +4021 -1
- package/dist/index.mjs +164 -10
- package/package.json +3 -6
package/README.md
CHANGED
|
@@ -125,7 +125,9 @@ order:
|
|
|
125
125
|
```
|
|
126
126
|
|
|
127
127
|
**Pattern B — one `.oxlintrc.json` per package**, each with its own string `entryPoint`. oxlint
|
|
128
|
-
resolves the closest config to the file being linted
|
|
128
|
+
resolves the closest config to the file being linted, and a relative `entryPoint` is anchored to
|
|
129
|
+
that config's directory (falling back to the working directory), so it resolves to the same CSS
|
|
130
|
+
whether oxlint runs from the package (CLI) or the workspace root (editor).
|
|
129
131
|
|
|
130
132
|
See the full [monorepo guide](https://oxlint-tailwindcss.pages.dev/monorepo) for examples of both.
|
|
131
133
|
|
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.70.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" },
|
|
@@ -1991,6 +2055,19 @@ function safeFilename(context) {
|
|
|
1991
2055
|
}
|
|
1992
2056
|
}
|
|
1993
2057
|
/**
|
|
2058
|
+
* Safely read `context.cwd`, falling back to `process.cwd()`. Same try/catch
|
|
2059
|
+
* pattern as the other accessors (the getter throws in `createOnce` on older
|
|
2060
|
+
* oxlint). The fallback keeps relative-path resolution working even when the
|
|
2061
|
+
* linter never populates `cwd`.
|
|
2062
|
+
*/
|
|
2063
|
+
function safeCwd(context) {
|
|
2064
|
+
try {
|
|
2065
|
+
return context.cwd ?? process.cwd();
|
|
2066
|
+
} catch {
|
|
2067
|
+
return process.cwd();
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
/**
|
|
1994
2071
|
* Lazily memoize a compiled options object across visitor calls.
|
|
1995
2072
|
*
|
|
1996
2073
|
* Every rule with options reinvents:
|
|
@@ -2106,6 +2183,76 @@ function resolveByGlobMapping(mappings, filePath, baseDir) {
|
|
|
2106
2183
|
return null;
|
|
2107
2184
|
}
|
|
2108
2185
|
/**
|
|
2186
|
+
* oxlint discovers nested configuration by walking up from each linted file
|
|
2187
|
+
* looking for files with these names. We mirror that walk to find the config
|
|
2188
|
+
* directory a relative `entryPoint` should be anchored to.
|
|
2189
|
+
*/
|
|
2190
|
+
const OXLINT_CONFIG_NAMES = [".oxlintrc.json"];
|
|
2191
|
+
/** Memoizes the nearest-config walk per starting directory (cleared in tests). */
|
|
2192
|
+
const nearestConfigDirCache = /* @__PURE__ */ new Map();
|
|
2193
|
+
/**
|
|
2194
|
+
* Find the directory of the **nearest** enclosing oxlint config, walking up
|
|
2195
|
+
* from `filePath` toward the filesystem root. Returns `undefined` if none is
|
|
2196
|
+
* found. This is the config oxlint applies to the file under its default
|
|
2197
|
+
* nested-config discovery, so a relative `entryPoint` declared in it is meant
|
|
2198
|
+
* to resolve relative to that directory — not the process CWD, which differs
|
|
2199
|
+
* between the CLI (`cd package && oxlint`) and an editor (CWD = workspace
|
|
2200
|
+
* root). See issue #39.
|
|
2201
|
+
*
|
|
2202
|
+
* Stops at the first match (early exit), so in the common case it touches only
|
|
2203
|
+
* the file's package, not the whole path to root.
|
|
2204
|
+
*/
|
|
2205
|
+
function nearestConfigDir(filePath) {
|
|
2206
|
+
const start = (0, node_path.dirname)((0, node_path.resolve)(filePath));
|
|
2207
|
+
const cached = nearestConfigDirCache.get(start);
|
|
2208
|
+
if (cached !== void 0) return cached ?? void 0;
|
|
2209
|
+
let dir = start;
|
|
2210
|
+
for (;;) {
|
|
2211
|
+
if (OXLINT_CONFIG_NAMES.some((name) => (0, node_fs.existsSync)((0, node_path.resolve)(dir, name)))) {
|
|
2212
|
+
nearestConfigDirCache.set(start, dir);
|
|
2213
|
+
return dir;
|
|
2214
|
+
}
|
|
2215
|
+
const parent = (0, node_path.dirname)(dir);
|
|
2216
|
+
if (parent === dir) break;
|
|
2217
|
+
dir = parent;
|
|
2218
|
+
}
|
|
2219
|
+
nearestConfigDirCache.set(start, null);
|
|
2220
|
+
}
|
|
2221
|
+
/**
|
|
2222
|
+
* Resolve a string `entryPoint` (from `settings` or a rule option) to an
|
|
2223
|
+
* absolute path.
|
|
2224
|
+
*
|
|
2225
|
+
* Absolute paths are returned normalized and untouched. A **relative** path is
|
|
2226
|
+
* anchored to the directory of the nearest enclosing `.oxlintrc.json` (the
|
|
2227
|
+
* config oxlint applies to the file), with the CWD as a single fallback:
|
|
2228
|
+
*
|
|
2229
|
+
* 1. nearest config dir — if its candidate file exists, use it;
|
|
2230
|
+
* 2. CWD — if its candidate file exists, use it;
|
|
2231
|
+
* 3. otherwise resolve against the nearest config dir (else CWD) so the
|
|
2232
|
+
* downstream "could not stat" diagnostic names the package-local path the
|
|
2233
|
+
* user most likely intended — i.e. fail loud rather than silently reach
|
|
2234
|
+
* past the nearest config into an unrelated ancestor.
|
|
2235
|
+
*
|
|
2236
|
+
* Deliberately a two-step [config dir → CWD] resolution, NOT a walk through
|
|
2237
|
+
* every ancestor config: the v1 charter is deterministic + fail-loud, and a
|
|
2238
|
+
* multi-ancestor existence probe would let a coincidentally same-named CSS in
|
|
2239
|
+
* an unrelated parent silently shadow a genuine misconfiguration.
|
|
2240
|
+
*
|
|
2241
|
+
* This makes resolution independent of where oxlint is launched from: the
|
|
2242
|
+
* editor (CWD = workspace root) and the CLI (CWD = package dir) now agree on
|
|
2243
|
+
* the same CSS file in a Pattern-B monorepo (issue #39).
|
|
2244
|
+
*/
|
|
2245
|
+
function resolveStringEntryPoint(entry, filePath, cwd) {
|
|
2246
|
+
if ((0, node_path.isAbsolute)(entry)) return (0, node_path.resolve)(entry);
|
|
2247
|
+
const configDir = filePath ? nearestConfigDir(filePath) : void 0;
|
|
2248
|
+
const bases = configDir && configDir !== cwd ? [configDir, cwd] : [cwd];
|
|
2249
|
+
for (const base of bases) {
|
|
2250
|
+
const candidate = (0, node_path.resolve)(base, entry);
|
|
2251
|
+
if ((0, node_fs.existsSync)(candidate)) return candidate;
|
|
2252
|
+
}
|
|
2253
|
+
return (0, node_path.resolve)(bases[0], entry);
|
|
2254
|
+
}
|
|
2255
|
+
/**
|
|
2109
2256
|
* Extract `rootFontSize` from `settings.tailwindcss` (default: 16).
|
|
2110
2257
|
*/
|
|
2111
2258
|
function rootFontSizeFromSettings(settings) {
|
|
@@ -2139,7 +2286,7 @@ function getLoadedDesignSystem(cssPath, settings) {
|
|
|
2139
2286
|
try {
|
|
2140
2287
|
mtime = (0, node_fs.statSync)(resolvedPath).mtimeMs;
|
|
2141
2288
|
} catch (cause) {
|
|
2142
|
-
throw new DesignSystemLoadError(`Could not stat CSS entry point: ${resolvedPath}`, "Check that the file exists and is readable.
|
|
2289
|
+
throw new DesignSystemLoadError(`Could not stat CSS entry point: ${resolvedPath}`, "Check that the file exists and is readable. A relative `entryPoint` is resolved against the nearest `.oxlintrc.json` directory, falling back to the oxlint working directory.", { cause: cause instanceof Error ? cause : void 0 });
|
|
2143
2290
|
}
|
|
2144
2291
|
const cached = dsCache.get(resolvedPath);
|
|
2145
2292
|
if (cached && cached.mtime === mtime) return {
|
|
@@ -2178,6 +2325,10 @@ function getLoadedDesignSystem(cssPath, settings) {
|
|
|
2178
2325
|
* 3. `settings.tailwindcss.entryPoint` as an `EntryPointMapping[]` —
|
|
2179
2326
|
* first matching glob (relative to CWD) wins.
|
|
2180
2327
|
*
|
|
2328
|
+
* A relative string entry (1 or 2) is anchored to the nearest enclosing
|
|
2329
|
+
* `.oxlintrc.json` directory rather than the CWD, so editor and CLI runs agree
|
|
2330
|
+
* in Pattern-B monorepos (issue #39); see `resolveStringEntryPoint`.
|
|
2331
|
+
*
|
|
2181
2332
|
* If none of those produce an entry point for the current file, throws
|
|
2182
2333
|
* `MissingEntryPointError`. If the resolved CSS fails to load, throws
|
|
2183
2334
|
* `DesignSystemLoadError`. Both extend `OxlintTailwindError` and are
|
|
@@ -2208,7 +2359,7 @@ function createLazyLoader(context) {
|
|
|
2208
2359
|
lastResult = void 0;
|
|
2209
2360
|
lastError = void 0;
|
|
2210
2361
|
try {
|
|
2211
|
-
lastResult = getLoadedDesignSystem(resolveEntryPointForFile(ruleOptionEntry, entryPointFromSettings(settings), filePath), settings);
|
|
2362
|
+
lastResult = getLoadedDesignSystem(resolveEntryPointForFile(ruleOptionEntry, entryPointFromSettings(settings), filePath, safeCwd(context)), settings);
|
|
2212
2363
|
} catch (err) {
|
|
2213
2364
|
if (isFatalError(err) && err instanceof Error) lastError = err;
|
|
2214
2365
|
throw err;
|
|
@@ -2218,18 +2369,21 @@ function createLazyLoader(context) {
|
|
|
2218
2369
|
};
|
|
2219
2370
|
}
|
|
2220
2371
|
/**
|
|
2221
|
-
* Pure resolution from (rule option, settings entry, file path) to
|
|
2222
|
-
* entry-point path. Exported for testability.
|
|
2372
|
+
* Pure resolution from (rule option, settings entry, file path, cwd) to an
|
|
2373
|
+
* absolute CSS entry-point path. Exported for testability.
|
|
2374
|
+
*
|
|
2375
|
+
* Relative string entries are anchored via `resolveStringEntryPoint` (nearest
|
|
2376
|
+
* `.oxlintrc.json` dir, then `cwd`); mapping arrays match relative to `cwd`.
|
|
2223
2377
|
*
|
|
2224
2378
|
* Throws `MissingEntryPointError` if nothing resolves. The error message
|
|
2225
2379
|
* names the file so the user knows which one tripped the configuration.
|
|
2226
2380
|
*/
|
|
2227
|
-
function resolveEntryPointForFile(ruleOptionEntry, settingsEntry, filePath) {
|
|
2228
|
-
if (ruleOptionEntry) return ruleOptionEntry;
|
|
2229
|
-
if (typeof settingsEntry === "string") return settingsEntry;
|
|
2381
|
+
function resolveEntryPointForFile(ruleOptionEntry, settingsEntry, filePath, cwd = process.cwd()) {
|
|
2382
|
+
if (ruleOptionEntry) return resolveStringEntryPoint(ruleOptionEntry, filePath, cwd);
|
|
2383
|
+
if (typeof settingsEntry === "string") return resolveStringEntryPoint(settingsEntry, filePath, cwd);
|
|
2230
2384
|
if (Array.isArray(settingsEntry)) {
|
|
2231
2385
|
if (!filePath) throw new MissingEntryPointError("`settings.tailwindcss.entryPoint` is a mapping array but no file path is available to match against.", "This usually means the rule ran outside the linter context. Open an issue if you see this in a real lint run.");
|
|
2232
|
-
const matched = resolveByGlobMapping(settingsEntry, filePath,
|
|
2386
|
+
const matched = resolveByGlobMapping(settingsEntry, filePath, cwd);
|
|
2233
2387
|
if (matched) return matched;
|
|
2234
2388
|
throw new MissingEntryPointError(`No \`entryPoint\` mapping matched \`${filePath}\`.`, "Add a mapping covering this file to `settings.tailwindcss.entryPoint`, or use a `\"**\"` fallback entry.");
|
|
2235
2389
|
}
|
|
@@ -2317,7 +2471,7 @@ const DEPRECATED_MAP = {
|
|
|
2317
2471
|
"bg-gradient-to-l": "bg-linear-to-l",
|
|
2318
2472
|
"bg-gradient-to-tl": "bg-linear-to-tl"
|
|
2319
2473
|
};
|
|
2320
|
-
const noDeprecatedClasses =
|
|
2474
|
+
const noDeprecatedClasses = defineRule({
|
|
2321
2475
|
meta: {
|
|
2322
2476
|
type: "problem",
|
|
2323
2477
|
docs: { description: "Disallow deprecated Tailwind CSS v4 classes" },
|
|
@@ -2359,7 +2513,7 @@ const noDeprecatedClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
2359
2513
|
});
|
|
2360
2514
|
//#endregion
|
|
2361
2515
|
//#region src/rules/no-unknown-classes.ts
|
|
2362
|
-
const noUnknownClasses =
|
|
2516
|
+
const noUnknownClasses = defineRule({
|
|
2363
2517
|
meta: {
|
|
2364
2518
|
type: "problem",
|
|
2365
2519
|
docs: { description: "Disallow classes that are not defined in the Tailwind CSS design system" },
|
|
@@ -2599,7 +2753,7 @@ function shouldSkipPair(a, b, propsA, propsB, rules = {}) {
|
|
|
2599
2753
|
for (const { a: reA, b: reB } of pairs) if (reA.test(ua) && reB.test(ub) || reA.test(ub) && reB.test(ua)) return true;
|
|
2600
2754
|
return false;
|
|
2601
2755
|
}
|
|
2602
|
-
const noConflictingClasses =
|
|
2756
|
+
const noConflictingClasses = defineRule({
|
|
2603
2757
|
meta: {
|
|
2604
2758
|
type: "problem",
|
|
2605
2759
|
docs: { description: "Disallow Tailwind CSS classes that generate conflicting CSS properties" },
|
|
@@ -2983,7 +3137,7 @@ function preserveImportantPosition(original, canonicalized) {
|
|
|
2983
3137
|
const bare = splitImportant(utility).bare;
|
|
2984
3138
|
return variant + reattachImportant(bare, position);
|
|
2985
3139
|
}
|
|
2986
|
-
const enforceCanonical =
|
|
3140
|
+
const enforceCanonical = defineRule({
|
|
2987
3141
|
meta: {
|
|
2988
3142
|
type: "suggestion",
|
|
2989
3143
|
docs: { description: "Enforce canonical Tailwind CSS class names using canonicalizeCandidates()" },
|
|
@@ -3077,7 +3231,7 @@ function sortClassesSync(cssPath, classes) {
|
|
|
3077
3231
|
}
|
|
3078
3232
|
//#endregion
|
|
3079
3233
|
//#region src/rules/enforce-sort-order.ts
|
|
3080
|
-
const enforceSortOrder =
|
|
3234
|
+
const enforceSortOrder = defineRule({
|
|
3081
3235
|
meta: {
|
|
3082
3236
|
type: "suggestion",
|
|
3083
3237
|
docs: { description: "Enforce consistent sort order of Tailwind CSS classes using the official class order" },
|
|
@@ -3242,7 +3396,7 @@ function createShorthandRules(value) {
|
|
|
3242
3396
|
}
|
|
3243
3397
|
];
|
|
3244
3398
|
}
|
|
3245
|
-
const enforceShorthand =
|
|
3399
|
+
const enforceShorthand = defineRule({
|
|
3246
3400
|
meta: {
|
|
3247
3401
|
type: "suggestion",
|
|
3248
3402
|
docs: { description: "Enforce shorthand Tailwind CSS classes when all axes have the same value" },
|
|
@@ -3463,7 +3617,7 @@ function createDirectionalMapper(context, opts) {
|
|
|
3463
3617
|
}
|
|
3464
3618
|
return { check };
|
|
3465
3619
|
}
|
|
3466
|
-
const enforceLogical =
|
|
3620
|
+
const enforceLogical = defineRule({
|
|
3467
3621
|
meta: {
|
|
3468
3622
|
type: "suggestion",
|
|
3469
3623
|
docs: { description: "Enforce logical (RTL-friendly) Tailwind CSS properties instead of physical ones" },
|
|
@@ -3489,7 +3643,7 @@ const enforceLogical = (0, _oxlint_plugins.defineRule)({
|
|
|
3489
3643
|
});
|
|
3490
3644
|
//#endregion
|
|
3491
3645
|
//#region src/rules/enforce-physical.ts
|
|
3492
|
-
const enforcePhysical =
|
|
3646
|
+
const enforcePhysical = defineRule({
|
|
3493
3647
|
meta: {
|
|
3494
3648
|
type: "suggestion",
|
|
3495
3649
|
docs: { description: "Enforce physical Tailwind CSS properties instead of logical ones for consistency in LTR-only projects" },
|
|
@@ -3516,7 +3670,7 @@ const enforcePhysical = (0, _oxlint_plugins.defineRule)({
|
|
|
3516
3670
|
//#endregion
|
|
3517
3671
|
//#region src/rules/max-class-count.ts
|
|
3518
3672
|
const DEFAULT_MAX = 20;
|
|
3519
|
-
const maxClassCount =
|
|
3673
|
+
const maxClassCount = defineRule({
|
|
3520
3674
|
meta: {
|
|
3521
3675
|
type: "suggestion",
|
|
3522
3676
|
docs: { description: "Enforce a maximum number of Tailwind CSS classes per element" },
|
|
@@ -3549,7 +3703,7 @@ const maxClassCount = (0, _oxlint_plugins.defineRule)({
|
|
|
3549
3703
|
});
|
|
3550
3704
|
//#endregion
|
|
3551
3705
|
//#region src/rules/no-restricted-classes.ts
|
|
3552
|
-
const noRestrictedClasses =
|
|
3706
|
+
const noRestrictedClasses = defineRule({
|
|
3553
3707
|
meta: {
|
|
3554
3708
|
type: "problem",
|
|
3555
3709
|
docs: { description: "Disallow specific Tailwind CSS classes" },
|
|
@@ -3636,7 +3790,7 @@ const noRestrictedClasses = (0, _oxlint_plugins.defineRule)({
|
|
|
3636
3790
|
});
|
|
3637
3791
|
//#endregion
|
|
3638
3792
|
//#region src/rules/no-arbitrary-value.ts
|
|
3639
|
-
const noArbitraryValue =
|
|
3793
|
+
const noArbitraryValue = defineRule({
|
|
3640
3794
|
meta: {
|
|
3641
3795
|
type: "suggestion",
|
|
3642
3796
|
docs: { description: "Disallow arbitrary values in Tailwind CSS classes" },
|
|
@@ -3676,7 +3830,7 @@ const noArbitraryValue = (0, _oxlint_plugins.defineRule)({
|
|
|
3676
3830
|
});
|
|
3677
3831
|
//#endregion
|
|
3678
3832
|
//#region src/rules/enforce-consistent-important-position.ts
|
|
3679
|
-
const enforceConsistentImportantPosition =
|
|
3833
|
+
const enforceConsistentImportantPosition = defineRule({
|
|
3680
3834
|
meta: {
|
|
3681
3835
|
type: "suggestion",
|
|
3682
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." },
|
|
@@ -3746,7 +3900,7 @@ function fixClass(cls) {
|
|
|
3746
3900
|
* Detects `-utility-[value]` and suggests `utility-[-value]`.
|
|
3747
3901
|
* e.g. `-top-[5px]` → `top-[-5px]`
|
|
3748
3902
|
*/
|
|
3749
|
-
const enforceNegativeArbitraryValues =
|
|
3903
|
+
const enforceNegativeArbitraryValues = defineRule({
|
|
3750
3904
|
meta: {
|
|
3751
3905
|
type: "suggestion",
|
|
3752
3906
|
docs: { description: "Enforce moving the negative sign inside arbitrary value brackets: -top-[5px] → top-[-5px]" },
|
|
@@ -3797,7 +3951,7 @@ function convertClass(cls, syntax) {
|
|
|
3797
3951
|
}
|
|
3798
3952
|
return null;
|
|
3799
3953
|
}
|
|
3800
|
-
const enforceConsistentVariableSyntax =
|
|
3954
|
+
const enforceConsistentVariableSyntax = defineRule({
|
|
3801
3955
|
meta: {
|
|
3802
3956
|
type: "suggestion",
|
|
3803
3957
|
docs: { description: "Enforce consistent CSS variable syntax: bg-[var(--color)] ↔ bg-(--color)" },
|
|
@@ -3919,7 +4073,7 @@ function getUtilityPrefix(utility) {
|
|
|
3919
4073
|
const dashIdx = u.indexOf("-");
|
|
3920
4074
|
return dashIdx >= 0 ? u.slice(0, dashIdx) : u;
|
|
3921
4075
|
}
|
|
3922
|
-
const noDarkWithoutLight =
|
|
4076
|
+
const noDarkWithoutLight = defineRule({
|
|
3923
4077
|
meta: {
|
|
3924
4078
|
type: "problem",
|
|
3925
4079
|
docs: { description: "Require a base (light) utility when using dark: (or other scheme) variant" },
|
|
@@ -4016,7 +4170,7 @@ function isColorUtility(utility) {
|
|
|
4016
4170
|
for (const prefix of COLOR_UTILITY_PREFIXES) if (utility === prefix || utility.startsWith(`${prefix}-`)) return true;
|
|
4017
4171
|
return false;
|
|
4018
4172
|
}
|
|
4019
|
-
const noHardcodedColors =
|
|
4173
|
+
const noHardcodedColors = defineRule({
|
|
4020
4174
|
meta: {
|
|
4021
4175
|
type: "suggestion",
|
|
4022
4176
|
docs: { description: "Disallow hardcoded color values in Tailwind CSS classes" },
|
|
@@ -4057,7 +4211,7 @@ const noHardcodedColors = (0, _oxlint_plugins.defineRule)({
|
|
|
4057
4211
|
});
|
|
4058
4212
|
//#endregion
|
|
4059
4213
|
//#region src/rules/no-contradicting-variants.ts
|
|
4060
|
-
const noContradictingVariants =
|
|
4214
|
+
const noContradictingVariants = defineRule({
|
|
4061
4215
|
meta: {
|
|
4062
4216
|
type: "suggestion",
|
|
4063
4217
|
docs: { description: "Disallow variant-prefixed classes that are redundant because the base class already applies unconditionally" },
|
|
@@ -4164,7 +4318,7 @@ const DEFAULT_VARIANT_ORDER = [
|
|
|
4164
4318
|
"rtl",
|
|
4165
4319
|
"open"
|
|
4166
4320
|
];
|
|
4167
|
-
const consistentVariantOrder =
|
|
4321
|
+
const consistentVariantOrder = defineRule({
|
|
4168
4322
|
meta: {
|
|
4169
4323
|
type: "suggestion",
|
|
4170
4324
|
docs: { description: "Enforce a consistent order for Tailwind CSS variant prefixes" },
|
|
@@ -4321,7 +4475,7 @@ const consistentVariantOrder = (0, _oxlint_plugins.defineRule)({
|
|
|
4321
4475
|
//#endregion
|
|
4322
4476
|
//#region src/rules/enforce-consistent-line-wrapping.ts
|
|
4323
4477
|
const DEFAULT_PRINT_WIDTH = 80;
|
|
4324
|
-
const enforceConsistentLineWrapping =
|
|
4478
|
+
const enforceConsistentLineWrapping = defineRule({
|
|
4325
4479
|
meta: {
|
|
4326
4480
|
type: "suggestion",
|
|
4327
4481
|
docs: { description: "Warn when a class string exceeds the configured print width" },
|
|
@@ -4390,7 +4544,7 @@ const enforceConsistentLineWrapping = (0, _oxlint_plugins.defineRule)({
|
|
|
4390
4544
|
});
|
|
4391
4545
|
//#endregion
|
|
4392
4546
|
//#region src/rules/no-unnecessary-arbitrary-value.ts
|
|
4393
|
-
const noUnnecessaryArbitraryValue =
|
|
4547
|
+
const noUnnecessaryArbitraryValue = defineRule({
|
|
4394
4548
|
meta: {
|
|
4395
4549
|
type: "suggestion",
|
|
4396
4550
|
docs: { description: "Disallow arbitrary values when a named Tailwind class produces the same CSS" },
|
|
@@ -4460,56 +4614,9 @@ function detectRawVariable(utility) {
|
|
|
4460
4614
|
};
|
|
4461
4615
|
return null;
|
|
4462
4616
|
}
|
|
4463
|
-
const preferThemeTokens = (0, _oxlint_plugins.defineRule)({
|
|
4464
|
-
meta: {
|
|
4465
|
-
type: "suggestion",
|
|
4466
|
-
docs: { description: "Prefer named theme-token utilities over raw CSS variable references when a matching utility exists" },
|
|
4467
|
-
fixable: "code",
|
|
4468
|
-
schema: [{
|
|
4469
|
-
type: "object",
|
|
4470
|
-
properties: { entryPoint: { type: "string" } },
|
|
4471
|
-
additionalProperties: false
|
|
4472
|
-
}],
|
|
4473
|
-
hasSuggestions: true,
|
|
4474
|
-
defaultOptions: [{}],
|
|
4475
|
-
messages: {
|
|
4476
|
-
preferNamed: "\"{{className}}\" can be written as \"{{replacement}}\". Use the named theme token.",
|
|
4477
|
-
suggestReplace: "Replace \"{{className}}\" with \"{{replacement}}\".",
|
|
4478
|
-
...DS_UNAVAILABLE_MESSAGE
|
|
4479
|
-
}
|
|
4480
|
-
},
|
|
4481
|
-
createOnce(context) {
|
|
4482
|
-
const getDS = createLazyLoader(context);
|
|
4483
|
-
function check(locations) {
|
|
4484
|
-
if (locations.length === 0) return;
|
|
4485
|
-
const ds = safeGetDS(getDS, context, locations[0].node);
|
|
4486
|
-
if (!ds) return;
|
|
4487
|
-
const { cache } = ds;
|
|
4488
|
-
for (const loc of locations) {
|
|
4489
|
-
const split = splitClassesWithSeparators(loc.value);
|
|
4490
|
-
const offending = split.classes.flatMap((cls) => {
|
|
4491
|
-
const { utility, variant } = splitUtilityAndVariant(cls);
|
|
4492
|
-
const { bare: bareUtility, position } = splitImportant(utility);
|
|
4493
|
-
const match = detectRawVariable(bareUtility);
|
|
4494
|
-
if (!match) return [];
|
|
4495
|
-
const candidate = `${match.prefix}-${match.varName}${match.modifier}`;
|
|
4496
|
-
if (!cache.isValid(candidate)) return [];
|
|
4497
|
-
const namedEquivalent = cache.getNamedEquivalent(bareUtility);
|
|
4498
|
-
if (namedEquivalent && namedEquivalent === `${match.prefix}-${match.varName}`) return [];
|
|
4499
|
-
return [{
|
|
4500
|
-
cls,
|
|
4501
|
-
replacement: variant + reattachImportant(candidate, position)
|
|
4502
|
-
}];
|
|
4503
|
-
});
|
|
4504
|
-
reportClassReplacements(context, loc, split, split.classes, offending, { messageId: "preferNamed" });
|
|
4505
|
-
}
|
|
4506
|
-
}
|
|
4507
|
-
return createExtractorVisitors(context, check);
|
|
4508
|
-
}
|
|
4509
|
-
});
|
|
4510
4617
|
//#endregion
|
|
4511
4618
|
//#region src/index.ts
|
|
4512
|
-
const plugin =
|
|
4619
|
+
const plugin = definePlugin({
|
|
4513
4620
|
meta: { name: "tailwindcss" },
|
|
4514
4621
|
rules: {
|
|
4515
4622
|
"no-duplicate-classes": noDuplicateClasses,
|
|
@@ -4534,7 +4641,53 @@ const plugin = (0, _oxlint_plugins.definePlugin)({
|
|
|
4534
4641
|
"consistent-variant-order": consistentVariantOrder,
|
|
4535
4642
|
"enforce-consistent-line-wrapping": enforceConsistentLineWrapping,
|
|
4536
4643
|
"no-unnecessary-arbitrary-value": noUnnecessaryArbitraryValue,
|
|
4537
|
-
"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
|
+
})
|
|
4538
4691
|
}
|
|
4539
4692
|
});
|
|
4540
4693
|
//#endregion
|