oxlint-tailwindcss 1.10.0 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # oxlint-tailwindcss
2
2
 
3
- 23 Tailwind CSS linting rules for [oxlint](https://oxc.rs/docs/guide/usage/linter). Built for
3
+ 24 Tailwind CSS linting rules for [oxlint](https://oxc.rs/docs/guide/usage/linter). Built for
4
4
  Tailwind CSS v4 with deterministic config, typo suggestions, and autofixes.
5
5
 
6
6
  > **v1.0.0** — Upgrading from v0.x? See the
@@ -30,7 +30,7 @@ Read the story behind this plugin:
30
30
  - **Typo suggestions** — `itms-center` → "Did you mean `items-center`?"
31
31
  - **Conflict detection** — Shows exactly which CSS properties conflict and which class wins.
32
32
  - **Lightweight** — Only 2 runtime dependencies: `@tailwindcss/node` and `tailwindcss`.
33
- - **23 rules** — Correctness, style, complexity, and restriction rules with autofixes where
33
+ - **24 rules** — Correctness, style, complexity, and restriction rules with autofixes where
34
34
  possible.
35
35
  - **Variable detection** — Lints variables matching `/^classNames?$/`, `/^classes$/`, `/^styles?$/`
36
36
  (e.g. `className`, `classNames`, `classes`, `styles`) automatically.
@@ -247,7 +247,7 @@ entries are appended to the built-in defaults:
247
247
  }
248
248
  ```
249
249
 
250
- This applies to all 23 rules at once. For example, adding `"classNames"` to `attributes` makes every
250
+ This applies to all 24 rules at once. For example, adding `"classNames"` to `attributes` makes every
251
251
  rule lint `<Input classNames={{ root: "..." }} />`.
252
252
 
253
253
  To **remove** specific items from the built-in defaults, use `exclude`:
@@ -528,18 +528,22 @@ class the component merges in), so they are skipped to avoid false positives.
528
528
 
529
529
  Enforces canonical Tailwind CSS class names. Uses `canonicalizeCandidates()` from the Tailwind CSS
530
530
  engine dynamically — the same API that powers Tailwind CSS IntelliSense's `suggestCanonicalClasses`.
531
+ It only rewrites when the canonical form emits **byte-identical CSS** (a value-preserving rename or
532
+ syntax normalization), so `--fix` never changes how your design renders.
531
533
 
532
534
  ```tsx
533
535
  // ❌ Bad → ✅ Fixed
534
- "-m-0" → "m-0"
535
- "-mt-0" → "mt-0"
536
- "p-[2px]" → "p-0.5"
537
- "max-w-[400px]" → "max-w-100"
538
- "text-[var(--color-text)]/90" → "text-(--color-text)/90"
539
- "[--w-padding:theme(spacing.1)]" → "[--w-padding:--spacing(1)]"
536
+ "-m-0" → "m-0"
537
+ "-mt-0" → "mt-0"
538
+ "flex-grow-[2]" → "grow-2"
539
+ "text-[var(--color-text)]/90" → "text-(--color-text)/90"
540
540
  ```
541
541
 
542
- The px→named conversion (e.g. `p-[2px]` → `p-0.5`) depends on `rootFontSize` (default: 16).
542
+ It does **not** rewrite an arbitrary length into a spacing-scale step (`pl-[15px]` → `pl-3.75`),
543
+ even though IntelliSense suggests it: `pl-3.75` compiles to `calc(var(--spacing) * 3.75)`, which is
544
+ not byte-identical to `15px`, so the two can diverge under a `:root` override or a different root
545
+ font size. Those value-changing suggestions live in [`prefer-scale-token`](#prefer-scale-token),
546
+ report-only.
543
547
 
544
548
  **Requires design system.** **Autofix:** Replaces with canonical form.
545
549
 
@@ -935,6 +939,35 @@ CSS in those setups. (When the theme exposes the variable directly with no wrapp
935
939
 
936
940
  ---
937
941
 
942
+ #### `prefer-scale-token`
943
+
944
+ Reports a hardcoded value that is **numerically equal** to a spacing-scale step or a named theme
945
+ token, and suggests the token. This is the rule that matches Tailwind CSS IntelliSense's
946
+ `suggestCanonicalClasses` suggestion for arbitrary lengths (e.g. `pl-[15px]` → `pl-3.75`) — the
947
+ conversion `enforce-canonical` deliberately leaves alone because the CSS isn't byte-identical (see
948
+ [#78](https://github.com/sergioazoc/oxlint-tailwindcss/issues/78)).
949
+
950
+ **Report-only, on purpose.** There is no autofix: the token resolves through `var(--spacing)`, so a
951
+ `:root` override or a different root font size can make the two diverge. It only ever suggests, so
952
+ `oxlint --fix` skips it while `oxlint --fix-suggestions` applies it in bulk.
953
+
954
+ ```tsx
955
+ // ⚠️ Suggested (not auto-fixed)
956
+ "p-[10px]" → "p-2.5"
957
+ "rounded-[0.5rem]" → "rounded-lg"
958
+ ```
959
+
960
+ By default it reports values on the granularity Tailwind's own scale enumerates (multiples of
961
+ `0.5`). To match IntelliSense exactly — including dynamic steps like `pl-3.75` — set a finer `step`:
962
+
963
+ ```jsonc
964
+ { "tailwindcss/prefer-scale-token": ["warn", { "step": 0.25 }] }
965
+ ```
966
+
967
+ **Off by default.** **Requires design system.** **No autofix — suggestions only.**
968
+
969
+ ---
970
+
938
971
  ## Edge cases
939
972
 
940
973
  The class parser correctly handles:
@@ -952,9 +985,10 @@ The class parser correctly handles:
952
985
  - **`enforce-canonical`**: Named classes are canonicalized via the precomputed map (covers
953
986
  everything in `getClassList()` plus a curated list of legacy v3 spellings like `break-words`,
954
987
  `flex-grow`, `start-N`, `bg-gradient-to-*`, `bg-left-top` → `bg-top-left`). Arbitrary/CSS-var
955
- forms (`p-[2px]`, `bg-(--c)`) are canonicalized dynamically via the worker. Some valid v4 classes
956
- that don't appear in `getClassList()` and have no canonical rewrite (e.g. `border-1` is valid as a
957
- dynamic numeric value but isn't enumerated) are left untouched.
988
+ forms (`bg-(--c)`, `text-[var(--x)]`) are canonicalized dynamically via the worker when the result
989
+ is byte-identical; a value-changing form like `p-[2px]` → `p-0.5` is left to `prefer-scale-token`.
990
+ Some valid v4 classes that don't appear in `getClassList()` and have no canonical rewrite (e.g.
991
+ `border-1` is valid as a dynamic numeric value but isn't enumerated) are left untouched.
958
992
  - **`no-conflicting-classes`**: compares the emitted declarations (property, value, the custom
959
993
  properties each value reads, and which box it applies to), so compositions are derived rather than
960
994
  enumerated. Two exceptions cannot be derived and stay declared in the source: `prose` variants and
package/dist/index.cjs CHANGED
@@ -3,7 +3,7 @@ let node_crypto = require("node:crypto");
3
3
  let node_fs = require("node:fs");
4
4
  let node_path = require("node:path");
5
5
  let node_os = require("node:os");
6
- //#region ../../node_modules/.pnpm/@oxlint+plugins@1.78.0/node_modules/@oxlint/plugins/index.js
6
+ //#region ../../node_modules/.pnpm/@oxlint+plugins@1.80.0/node_modules/@oxlint/plugins/index.js
7
7
  /**
8
8
  * Define a plugin.
9
9
  *
@@ -7097,10 +7097,10 @@ const preferThemeTokens = defineRule({
7097
7097
  const { bare: bareUtility, position } = splitImportant(utility);
7098
7098
  const match = detectRawVariable(bareUtility);
7099
7099
  if (!match) return [];
7100
- const candidate = `${match.prefix}-${match.varName}${match.modifier}`;
7101
- if (!cache.isValid(candidate)) return [];
7102
- const target = `--${match.varName}`;
7103
7100
  const baseCandidate = `${match.prefix}-${match.varName}`;
7101
+ if (!cache.isValid(baseCandidate)) return [];
7102
+ const candidate = `${baseCandidate}${match.modifier}`;
7103
+ const target = `--${match.varName}`;
7104
7104
  if (!cache.getCssDeclarations(baseCandidate).some((decl) => [...decl.readsVars, ...decl.readsFallbackVars].some((read) => cache.themeVarResolvesTo(read, target))) && cache.definesVar(target)) return [];
7105
7105
  const namedEquivalent = cache.getNamedEquivalent(bareUtility);
7106
7106
  if (namedEquivalent && namedEquivalent === `${match.prefix}-${match.varName}`) return [];
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- //#region ../../node_modules/.pnpm/@oxlint+plugins@1.78.0/node_modules/@oxlint/plugins/index.d.ts
1
+ //#region ../../node_modules/.pnpm/@oxlint+plugins@1.80.0/node_modules/@oxlint/plugins/index.d.ts
2
2
  //#endregion
3
3
  //#region src-js/plugins/tokens.d.ts
4
4
  /**
@@ -969,7 +969,7 @@ type FunctionType = "FunctionDeclaration" | "FunctionExpression" | "TSDeclareFun
969
969
  interface FormalParameterRest extends Span {
970
970
  type: "RestElement";
971
971
  argument: BindingPattern;
972
- decorators?: [];
972
+ decorators?: Array<Decorator>;
973
973
  optional?: boolean;
974
974
  typeAnnotation?: TSTypeAnnotation | null;
975
975
  value?: null;
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- //#region ../../node_modules/.pnpm/@oxlint+plugins@1.78.0/node_modules/@oxlint/plugins/index.d.ts
1
+ //#region ../../node_modules/.pnpm/@oxlint+plugins@1.80.0/node_modules/@oxlint/plugins/index.d.ts
2
2
  //#endregion
3
3
  //#region src-js/plugins/tokens.d.ts
4
4
  /**
@@ -969,7 +969,7 @@ type FunctionType = "FunctionDeclaration" | "FunctionExpression" | "TSDeclareFun
969
969
  interface FormalParameterRest extends Span {
970
970
  type: "RestElement";
971
971
  argument: BindingPattern;
972
- decorators?: [];
972
+ decorators?: Array<Decorator>;
973
973
  optional?: boolean;
974
974
  typeAnnotation?: TSTypeAnnotation | null;
975
975
  value?: null;
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.78.0/node_modules/@oxlint/plugins/index.js
10
+ //#region ../../node_modules/.pnpm/@oxlint+plugins@1.80.0/node_modules/@oxlint/plugins/index.js
11
11
  /**
12
12
  * Define a plugin.
13
13
  *
@@ -7101,10 +7101,10 @@ const preferThemeTokens = defineRule({
7101
7101
  const { bare: bareUtility, position } = splitImportant(utility);
7102
7102
  const match = detectRawVariable(bareUtility);
7103
7103
  if (!match) return [];
7104
- const candidate = `${match.prefix}-${match.varName}${match.modifier}`;
7105
- if (!cache.isValid(candidate)) return [];
7106
- const target = `--${match.varName}`;
7107
7104
  const baseCandidate = `${match.prefix}-${match.varName}`;
7105
+ if (!cache.isValid(baseCandidate)) return [];
7106
+ const candidate = `${baseCandidate}${match.modifier}`;
7107
+ const target = `--${match.varName}`;
7108
7108
  if (!cache.getCssDeclarations(baseCandidate).some((decl) => [...decl.readsVars, ...decl.readsFallbackVars].some((read) => cache.themeVarResolvesTo(read, target))) && cache.definesVar(target)) return [];
7109
7109
  const namedEquivalent = cache.getNamedEquivalent(bareUtility);
7110
7110
  if (namedEquivalent && namedEquivalent === `${match.prefix}-${match.varName}`) return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxlint-tailwindcss",
3
- "version": "1.10.0",
3
+ "version": "1.10.1",
4
4
  "description": "Tailwind CSS linting rules for oxlint",
5
5
  "keywords": [
6
6
  "css",