@soujvnunes/eslint-config 0.12.0 → 0.13.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 CHANGED
@@ -37,6 +37,19 @@ import { createBaseConfig } from '@soujvnunes/eslint-config'
37
37
  export default createBaseConfig()
38
38
  ```
39
39
 
40
+ ```js
41
+ // eslint.config.mjs at the workspace root, for a package under ui/ that writes Tailwind classes and has no Next.js app
42
+ import { createBaseConfig } from '@soujvnunes/eslint-config'
43
+
44
+ export default createBaseConfig({
45
+ tailwindCwd: './ui',
46
+ tailwindEntryPoint: './theme.css',
47
+ design: true,
48
+ allowArbitraryClasses: ['mask-type'],
49
+ ignoreClasses: ['^sb-unstyled$'],
50
+ })
51
+ ```
52
+
40
53
  ## Options
41
54
 
42
55
  | Option | Default | Purpose |
@@ -44,10 +57,12 @@ export default createBaseConfig()
44
57
  | `importGroups` | react, next, module, parent, sibling, index | Full import-order groups, which replace the default list; insert your `@/...` paths |
45
58
  | `ignores` | (none) | Extra ignore globs, merged after the built-in defaults |
46
59
  | `tsconfigRootDir` | `process.cwd()` | Root for typescript-eslint's project service |
47
- | `tailwindEntryPoint` | (none) | Tailwind v4 CSS entry path: the file holding `@import "tailwindcss"` and `@theme`, such as `./app/tailwind.config.css`. When set on the Next preset, wires `eslint-plugin-better-tailwindcss` correctness rules such as `no-unknown-classes`, which flags a class not registered in the theme (a dead token neither `tsc` nor the build sees), and `no-restricted-classes`, which flags an arbitrary-value class such as `text-[11px]`. Left unset, the plugin stays off, since without the entry `no-unknown-classes` cannot resolve the theme and would flag every class. The stylistic rules stay off, since `prettier-plugin-tailwindcss` already owns class order |
48
- | `allowArbitraryClasses` | `[]` | Utility prefixes exempt from the arbitrary-Tailwind-value ban, for a shape with no theme token (`['grid-cols']` for `grid-cols-[200px_1fr]`). Read only when `tailwindEntryPoint` is set |
60
+ | `tailwindEntryPoint` | (none) | Tailwind v4 CSS entry path: the file holding `@import "tailwindcss"` and `@theme`, such as `./app/tailwind.config.css`. When set, on either preset, wires `eslint-plugin-better-tailwindcss` correctness rules such as `no-unknown-classes`, which flags a class not registered in the theme (a dead token neither `tsc` nor the build sees), and `no-restricted-classes`, which flags an arbitrary-value class such as `text-[11px]`. Left unset, the plugin stays off, since without the entry `no-unknown-classes` cannot resolve the theme and would flag every class. The stylistic rules stay off, since `prettier-plugin-tailwindcss` already owns class order. With `tailwindCwd` set, the path is read from that folder |
61
+ | `tailwindCwd` | (none) | The folder the class plugin resolves `tailwindcss` and the entry point from, passed to it as its `cwd` setting. The plugin resolves `tailwindcss/package.json` from ESLint's working directory and, finding none, disables its rules with one console line, so in a workspace whose root does not install Tailwind every class rule would pass while linting nothing. Set it to the package that installs Tailwind, and write `tailwindEntryPoint` relative to it. Read only when `tailwindEntryPoint` is set |
62
+ | `ignoreClasses` | `[]` | Regular expression patterns `no-unknown-classes` leaves alone, for a class a tool owns (`['^sb-unstyled$']` for Storybook's `sb-unstyled`). Read only when `tailwindEntryPoint` is set |
63
+ | `allowArbitraryClasses` | `[]` | Entries exempt from the arbitrary-Tailwind-value ban, for a shape with no theme token: a utility prefix (`['grid-cols']` for `grid-cols-[200px_1fr]`) or the property of a class that sets one in brackets (`['mask-type']` for `[mask-type:alpha]`). Read only when `tailwindEntryPoint` is set |
49
64
  | `design` | `false` | `true` or `{ dark?: boolean }` adds the design class rules to `no-restricted-classes`, for a theme that follows the design scales. Read only when `tailwindEntryPoint` is set. `{ dark: true }` allows the `dark:` variant. See "Design class rules" below |
50
- | `classMergeName` | `'cn'` | The class-merge helper name a ternary passed straight to it is banned inside of |
65
+ | `classMergeName` | `'cn'` | The class-merge helper name a ternary passed straight to it is banned inside of. Banned wherever `tailwindEntryPoint` is set, and on the Next preset whether it is set or not. With `tailwindEntryPoint` set, the class rules read the strings and object keys of a call by this name too: a name the class plugin does not read by default is added to its selectors beside the defaults |
51
66
  | `nextConfigModules` | `[]` | Modules `next.config.*` loads, restricted to relative imports (`no-restricted-imports` on `['@/*']`) the same as a `next.config.ts`, `.mts` or `.cts` itself, on the Next preset |
52
67
  | `strictExportGlobs` | `[]` | Globs wired to `soujvnunes/one-export-per-file`. With no globs the rule stays exported but off |
53
68
  | `extend` | `[]` | Extra flat-config objects appended at the end |
@@ -79,7 +94,7 @@ These are the opinions most likely to surprise an existing codebase. All of them
79
94
  **Three client-boundary rules on the Next preset, none autofixable.** All three read `.jsx` and `.tsx` files that open with `'use client'`, and skip `error` and `global-error`, which Next requires to be client components.
80
95
 
81
96
  - `soujvnunes/no-needless-use-client` reports the directive only when the file holds nothing a server module could not: it works from an allow-list rather than a list of known needs. Every module-level statement has to be an import with bindings (or a stylesheet), a type, a function declaration, a constant whose value, pattern defaults and markup included, builds by running nothing (literals, functions, objects and arrays of those, reads off local constants, and `cva`, `tv`, `memo` or `forwardRef`), or an export of a PascalCase component or a type; a side-effect import, an `if`, a call, `client-only`, `next/dynamic` and any value re-export each keep the directive. Every tag has to be one a server component can render: a tag name, an import, one level into a namespace import (`LabelPrimitive.Root`, and named imports from `radix-ui`, which exports namespaces), a component declared at module level, or a tag the parent passed in whose default passes the same test; an alias (`const MotionDiv = motion.div`), a styled tag, a higher-order result, or anything shaped like a context provider (a name ending in `Context`, `Ctx` or `Provider` under any import alias, or one lone `value` attribute on an element with children) does not qualify. Every value handed to a component, as a prop, a spread, a child, or a tag's `ref`, `action` or `formAction`, has to be data: literals (a RegExp is not), JSX, the props the component received, and objects, arrays and constants built only from those. A default, in a parameter, a destructured local or any pattern enclosing them, counts only when its value is data; a callback's argument is not a prop; a reassigned `let`, an object written through a member, a mutating method (`push`, `splice`) or a call it is handed to, and a key a later spread may replace are not data; and a read that names a string, array, number or object method (`LABEL.toUpperCase`, `ROWS.map`) is a function. A tag's other attributes and children can only hold data anyway, and `className` is a string by contract. On top of that, a hook call, `createContext`, `createPortal` or `flushSync` (matched by both the local and the imported name, so an alias hides neither), an `on*` handler, a class component or a browser-only global read as a value (bare or through `globalThis`) keeps the directive. A file without the directive still runs on the client when a client component imports it, so the fix is to delete the line.
82
- - `soujvnunes/no-static-jsx-in-client` reports a subtree of three or more elements, or a run of static siblings under a dynamic parent, that reads only literals, imports and module-level constants whose value is itself static. It reports only in a file that needs the client, or whose directive is kept by disabling the other rule (file-wide, on the line before, or on the same line), since in any other file that rule's fix, deleting the directive, already moves the markup to the server. The two rules share one analysis per file. The tags have to pass the same test as above and be the same on every render, no handler, `ref` or form action may sit on a tag, and a value handed to a component may not be a bare import, a namespace member or anything holding one, since that is most likely a function; a read through a named import (a copy dictionary) is static. Markup a library callback or an event handler builds is skipped, since no server parent exists to take it. That markup ships to the browser and hydrates for nothing. Render it in the server parent and pass it in as `children` or a named `ReactNode` prop; moving it to a file without the directive does not help while the client file imports it. The threshold is the `minElements` option.
97
+ - `soujvnunes/no-static-jsx-in-client` reports a subtree of three or more elements, or a run of static siblings under a dynamic parent, that reads only literals, imports and module-level constants whose value is itself static. It reports only in a file that needs the client, or whose directive is kept by disabling the other rule (file-wide, on the line before, or on the same line), since in any other file that rule's fix, deleting the directive, already moves the markup to the server. The two rules share one analysis per file. The tags have to pass the same test as above and be the same on every render, no handler, `ref` or form action may sit on a tag, and a value handed to a component may not be a bare import, a namespace member or anything holding one, since that is most likely a function; a read through a named import (a copy dictionary) is static. Markup a library callback or an event handler builds is skipped, since no server parent exists to take it. That markup ships to the browser and hydrates for nothing. Render it in the server parent and pass it in as `children` or a named `ReactNode` prop; moving it to a file without the directive does not help while the client file imports it. Markup a server action depends on stays inside the form: a honeypot input the action checks, moved out into a prop of the caller, no longer sits in the form it guards, so keep it there with a disable directive that gives its reason. The threshold is the `minElements` option.
83
98
  - `soujvnunes/one-component-per-client-file` keeps a client file to the one component it exists for. The first exported function component (named or default, through `memo`, `forwardRef`, `as` or `satisfies`, or exported later by name) is that component, and every other module-level function declaration or `const` holding a function is reported, exported or not, unless that function's own body needs the browser: a hook call, `createContext`, `createPortal` or `flushSync`, an `on*` handler or a function handed to a tag, a class component, or a browser-only global read bare or through `globalThis`, by the same detectors the first rule reads, applied to that one function. One detector differs: a value the function hands to a component, as a prop, a spread or a child, keeps it only when that value is a function: an inline arrow or function expression, or a name bound in the file to a function declaration or to a `const` holding an arrow or function expression. So a static sub-component that passes a callback's argument on to another component (`items.map((item) => <Item label={item} />)`) is reported. A function the file hands straight to client code is kept as well, whatever its body: one that appears as the whole value of an `on*` attribute (`onClick={onClick}`, `onValueChange={onValueChange}`), of a tag's `ref`, `action` or `formAction`, or as an argument of a hook call (`useEffect(effect, [])`), since a server parent cannot pass a function to a client component, so the client side has to hold it. The check reads the reference itself: a helper called inside an inline handler (`onClick={() => save(id)}`) is still reported. A `cva()` const or any other value that is not a function is left alone, and so is a function declared inside the component. A file with no exported component reports nothing, since there is no one component to name. A helper the component calls still ships wherever it lives, so moving it to its own module (a pure function under `utils/`, a hook under `lib/`) keeps the client file to one component and makes the helper importable from a server parent; only markup the server parent renders and passes in as `children` leaves the bundle.
84
99
 
85
100
  Measured on a Next app with 77 client files, with the TypeScript parser and browser globals the preset uses: the first rule found the 3 wrappers around a Radix primitive and `cn()` that were known to be needless, and nothing else once `error` files were exempt; the second found 16 static subtrees in 8 files, every one a block of labels and inputs or a heading a server parent could render. A threshold of two elements found 43, most of them label and input pairs that are not worth a refactor.
@@ -111,17 +126,34 @@ Two more `no-restricted-syntax` overrides, each adding a `Program` selector to t
111
126
 
112
127
  Both are Next-preset only, since a plain TypeScript library's `index.ts` is its npm entry point, not the barrel the Next convention (`MODULARITY`) warns about; `createBaseConfig` never sees either override, which is why this very package's own `eslint-config/index.ts` is not flagged by its own rule.
113
128
 
114
- ## `cn()` ternary ban, on the Next preset
129
+ ## Class rules outside Next.js
130
+
131
+ `createBaseConfig` takes `tailwindEntryPoint`, `design`, `allowArbitraryClasses`, `classMergeName`, `tailwindCwd` and `ignoreClasses`, so a package with no Next.js app lints its classes the way an app does. With `tailwindEntryPoint` set on the base preset, it gets the `better-tailwindcss` rules `no-unknown-classes`, `no-conflicting-classes` and `no-concatenated-classes` against that entry point, the arbitrary-value ban with its `allowArbitraryClasses` exemptions, the ban on a ternary inside the class merge call, and, with `design` set, the design class rules below. The rules read strings in `class`, `className`, the merge call and `cva(` calls. A variable-form utility passes (`bg-(--x)`, `px-(--button-md-px)`) and the bracket form fails (`bg-[var(--x)]`). Without `tailwindEntryPoint` none of it is wired, and the Next preset keeps the rule set it had.
132
+
133
+ The plugin resolves both `tailwindcss` and the entry point from one folder, ESLint's working directory unless `tailwindCwd` names another. A workspace whose root installs no Tailwind sets `tailwindCwd` to the package that does, and writes `tailwindEntryPoint` relative to that folder.
134
+
135
+ ## React 19 shapes, on both presets
136
+
137
+ Four refusals sit beside the class rules. The first three are `no-restricted-syntax` selectors on both presets, whether or not `tailwindEntryPoint` is set, and the fourth is part of the arbitrary-value entry. A repository meets them at its upgrade and moves to `ref` as a prop, `use` and the context as its own provider in the same change.
138
+
139
+ | Rule | Reports | Passes |
140
+ | --- | --- | --- |
141
+ | `forwardRef` | an import from `react`, a bare call and `React.forwardRef` | a component that takes `ref` as a prop |
142
+ | `useContext` | an import from `react`, a bare call and `React.useContext` | `use(ThemeContext)` |
143
+ | Context provider | a JSX element named by a member expression that ends in `.Provider` on an object whose name ends in `Context`: `<ThemeContext.Provider>`, reported once on the opening element | `<ThemeContext>`, and `<NavRail.Provider>` or a library `<Tooltip.Provider>`, since the rule reads no types |
144
+ | Property in brackets | a class that sets a property in brackets, with or without a variant in front: `[mask-type:alpha]`, `[--x:1rem]`, `hover:[mask-type:alpha]` | the same class with its property named in `allowArbitraryClasses` (`['mask-type']`), and a bracketed variant such as `[&_p]:flex` |
145
+
146
+ ## `cn()` ternary ban, on the Next preset and wherever `tailwindEntryPoint` is set
115
147
 
116
148
  `CallExpression[callee.name='cn'] > ConditionalExpression` is its own entry in the same selector composition, so the file-convention overrides above cannot drop it independently of the export-default filtering: it rides along with every other selector wherever `no-restricted-syntax` is set. The callee name comes from `classMergeName` (default `'cn'`), for a repo whose merge helper is named `clsx` or something else. Use a `cva` variant or an object entry instead of `cn(base, condition ? 'a' : 'b')`. Measured on a Next app: 16 sites across 9 files, 8 of them in one badge component.
117
149
 
118
150
  ## Arbitrary Tailwind values, when `tailwindEntryPoint` is set
119
151
 
120
- `better-tailwindcss/no-restricted-classes` bans a bracketed value on a utility (`text-[11px]`, `tracking-[0.08em]`, `bg-[#000]/50`) while leaving a bracketed **variant** alone (`data-[state=open]:`, `group-data-[state=open]:`, `peer-data-[checked]:`, `supports-[display:grid]:`, `[&_>_svg]:`), since those precede a colon and the ban only matches the class's own trailing bracket. `allowArbitraryClasses` exempts a utility prefix that has no theme-token shape at all, such as `grid-cols` for `grid-cols-[200px_1fr]`. Measured on a Next app: 28 distinct values at 52 sites, mostly `text-[Npx]` and `tracking-[Nem]`, none of which has a matching theme token today.
152
+ `better-tailwindcss/no-restricted-classes` bans a bracketed value on a utility (`text-[11px]`, `tracking-[0.08em]`, `bg-[#000]/50`) while leaving a bracketed **variant** alone (`data-[state=open]:`, `group-data-[state=open]:`, `peer-data-[checked]:`, `supports-[display:grid]:`, `[&_>_svg]:`), since those precede a colon and the ban only matches the class's own trailing bracket. `allowArbitraryClasses` exempts a utility prefix that has no theme-token shape at all, such as `grid-cols` for `grid-cols-[200px_1fr]`. The ban also reads a class that sets a property in brackets (`[mask-type:alpha]`, `[--x:1rem]`, with or without a variant in front), and an entry of `allowArbitraryClasses` exempts the property it names: `mask-type` lets `[mask-type:alpha]` pass. Measured on a Next app: 28 distinct values at 52 sites, mostly `text-[Npx]` and `tracking-[Nem]`, none of which has a matching theme token today.
121
153
 
122
154
  ## Design class rules, when `design` is set
123
155
 
124
- `design: true` (or `design: { dark: true }`) adds seven entries to `better-tailwindcss/no-restricted-classes`, beside the arbitrary-value entry and only where `tailwindEntryPoint` is set. Without the option nothing changes. Each pattern is matched against the whole class with its variants, so `hover:lg:p-2` is read the same as `p-2`, and the first entry that matches reports.
156
+ `design: true` (or `design: { dark: true }`) adds nine entries to `better-tailwindcss/no-restricted-classes`, beside the arbitrary-value entry and only where `tailwindEntryPoint` is set. Without the option nothing changes. Each pattern is matched against the whole class with its variants, so `hover:lg:p-2` is read the same as `p-2`, and the first entry that matches reports.
125
157
 
126
158
  ```js
127
159
  export default createNextConfig({ tailwindEntryPoint: './app/tailwind.config.css', design: true })
@@ -133,11 +165,13 @@ export default createNextConfig({ tailwindEntryPoint: './app/tailwind.config.css
133
165
  | Dark variant | `dark:bg-surface`, unless `design: { dark: true }` | `bg-surface` |
134
166
  | Motion | `transition`, `transition-colors`, `animate-spin`, `duration-300`, `ease-in`, `delay-150` with no `motion-safe:` variant | `motion-safe:transition`, `motion-safe:lg:duration-300`, `transition-none`, `animate-none` |
135
167
  | Stock font size | `text-xs`, `text-sm`, `text-base`, `text-lg`, `text-xl`, `text-2xl` to `text-9xl`, `text-sm/6` | `text-body` (a theme alias) |
136
- | Spacing and size scale | a number outside 0, 4, 8, 12, 16, 24, 40, 64, 104, 168 on a padding, margin, gap, space, inset, top, right, bottom, left, start, end, `w`, `h`, `size`, `min-w`, `min-h`, `max-h` or `basis` utility: `p-2`, `mt-0.5`, `w-px`, `h-48`, `-mt-10` | `p-4`, `-mt-8`, `w-1/2`, `w-full`, `h-auto`, `size-fit`, `mx-auto` |
137
- | Opacity modifier | `bg-surface/50`, `text-foreground/70`, `border-line/20`, `ring-focus/40`, `outline-line/10`, `fill-icon/60`, `stroke-icon/60`, `divide-line/20`, `shadow-shade/30`, `from-surface/50`, `via-surface/50`, `to-surface/50` | `bg-surface`, `w-1/2`, `bg-linear-to-r/oklch` |
138
- | Max width | `max-w-xl`, `max-w-full`, `lg:max-w-prose` | `w-full`, `min-w-0` |
168
+ | Spacing unit | a number outside 0 and the general set on a padding, margin, gap, space, inset, top, right, bottom, left, start or end utility, negative forms included, and `px`: `p-10`, `gap-104`, `p-116`, `mt-0.5`, `p-px`, `-mt-10` | `p-0`, `p-20`, `gap-96`, `-ml-8` |
169
+ | Sizing unit | a number outside 0, the general set and the layout set on a `w`, `h`, `size`, `min-w`, `min-h`, `max-w`, `max-h` or `basis` utility, and `px`: `w-100`, `w-168`, `h-10`, `w-px` | `w-0`, `w-304`, `h-64`, `basis-488`, `max-w-1280`, `w-full`, `h-auto`, `size-fit` |
170
+ | Opacity modifier | `bg-surface/50`, `text-foreground/70`, `border-line/20`, `ring-focus/40`, `outline-line/10`, `fill-icon/60`, `stroke-icon/60`, `divide-line/20`, `shadow-shade/30`, `from-surface/50`, `via-surface/50`, `to-surface/50` | `bg-surface`, `aspect-16/9`, `bg-linear-to-r/oklch` |
171
+ | Named cap | a named `max-w-*`: `max-w-xl`, `max-w-prose`, `max-w-screen-lg`, `max-w-page`, `lg:max-w-prose` | `max-w-488`, `max-w-1280`, `max-w-full`, `max-w-none`, `max-w-fit`, `max-w-min`, `max-w-max` |
172
+ | Column or fraction | `col-span-<n>`, `col-start-<n>`, `col-end-<n>`, `grid-cols-4` and above, `grid-cols-subgrid`, and a fraction on a sizing utility: `col-span-8`, `grid-cols-12`, `w-1/2`, `basis-1/3` | `col-span-full`, `grid-cols-1` to `grid-cols-3`, `w-full`, `w-304` |
139
173
 
140
- A decimal and `px` are outside the scale, a fraction and a keyword are not. Each report states its rule in plain words.
174
+ The two sets are written out once here. The general set is 4 to 96 in steps of 4 (twenty-four values), plus 0, and it is the only set spacing takes. The layout set is 84, 116, 136, 188, 220, 304, 356, 488, 576, 792, 932 and 1280, and sizing takes it beside the general set. 84, 88, 92 and 96 pass on both kinds of utility, since the lint cannot tell a control from a block and a review holds that. A cap is a layout unit written by its number, never a name. A fraction is outside both sets, a keyword is not, and each report states its rule in plain words.
141
175
 
142
176
  ## Module boundaries
143
177
 
package/dist/index.d.ts CHANGED
@@ -15,6 +15,8 @@ interface ConfigOptions {
15
15
  importGroups?: (string | string[])[];
16
16
  tsconfigRootDir?: string;
17
17
  tailwindEntryPoint?: string;
18
+ tailwindCwd?: string;
19
+ ignoreClasses?: string[];
18
20
  allowArbitraryClasses?: string[];
19
21
  design?: boolean | {
20
22
  dark?: boolean;
package/dist/index.js CHANGED
@@ -4,6 +4,8 @@ import nextPlugin from "@next/eslint-plugin-next";
4
4
  import prettier from "eslint-config-prettier";
5
5
  import { createTypeScriptImportResolver } from "eslint-import-resolver-typescript";
6
6
  import betterTailwind from "eslint-plugin-better-tailwindcss";
7
+ import { getDefaultSelectors } from "eslint-plugin-better-tailwindcss/api/defaults";
8
+ import { MatcherType, SelectorKind } from "eslint-plugin-better-tailwindcss/api/types";
7
9
  import importHelpers from "eslint-plugin-import-helpers";
8
10
  import importXPlugin from "eslint-plugin-import-x";
9
11
  import jsxA11y from "eslint-plugin-jsx-a11y";
@@ -19,8 +21,22 @@ var anyOf = (parts) => `(?:${parts.join("|")})`;
19
21
  var CLASS_START = "(?:^|:)!?";
20
22
  var CLASS_END = "!?$";
21
23
  var CLASS_VALUE = "[^\\s!]+";
22
- var SPACING_STEPS = ["0", "4", "8", "12", "16", "24", "40", "64", "104", "168"];
23
- var SCALED_UTILITIES = [
24
+ var GENERAL_UNIT_FIRST = 4;
25
+ var GENERAL_UNIT_LAST = 96;
26
+ var GENERAL_UNIT_STEP = 4;
27
+ var GENERAL_UNITS = Array.from(
28
+ { length: (GENERAL_UNIT_LAST - GENERAL_UNIT_FIRST) / GENERAL_UNIT_STEP + 1 },
29
+ (_, index) => GENERAL_UNIT_FIRST + index * GENERAL_UNIT_STEP
30
+ );
31
+ var LAYOUT_UNITS = [84, 116, 136, 188, 220, 304, 356, 488, 576, 792, 932, 1280];
32
+ var unitsOf = (...sets) => [
33
+ ...new Set(sets.flat().map(String))
34
+ ];
35
+ var SPACING_UNITS = unitsOf([0], GENERAL_UNITS);
36
+ var SIZING_UNITS = unitsOf([0], GENERAL_UNITS, LAYOUT_UNITS);
37
+ var GENERAL_SET = `the general set (${GENERAL_UNIT_FIRST} to ${GENERAL_UNIT_LAST} in steps of ${GENERAL_UNIT_STEP})`;
38
+ var LAYOUT_SET = `the layout set (${LAYOUT_UNITS.join(", ")})`;
39
+ var SPACING_UTILITIES = [
24
40
  "p[xytrblse]?",
25
41
  "m[xytrblse]?",
26
42
  "gap(?:-[xy])?",
@@ -31,15 +47,9 @@ var SCALED_UTILITIES = [
31
47
  "bottom",
32
48
  "left",
33
49
  "start",
34
- "end",
35
- "w",
36
- "h",
37
- "size",
38
- "min-w",
39
- "min-h",
40
- "max-h",
41
- "basis"
50
+ "end"
42
51
  ];
52
+ var SIZING_UTILITIES = ["w", "h", "size", "min-w", "min-h", "max-w", "max-h", "basis"];
43
53
  var COLOUR_UTILITIES = [
44
54
  "bg",
45
55
  "text",
@@ -62,46 +72,58 @@ var MOTION_UTILITIES = [
62
72
  `delay-${CLASS_VALUE}`
63
73
  ];
64
74
  var STOCK_FONT_SIZES = ["xs", "sm", "base", "lg", "xl", "[2-9]xl"];
75
+ var UNBOUNDED_CAPS = ["full", "none", "fit", "min", "max"];
65
76
  var RESPONSIVE_VARIANTS = "(?:^|:)(?:max-)?(?:sm|md):";
66
77
  var DARK_VARIANT = "(?:^|:)dark:";
67
78
  var MOTION_SAFE_VARIANT = "(?:.*:)?motion-safe:";
68
79
  var MOTION_PATTERN = `^(?!${MOTION_SAFE_VARIANT})(?:.*:)?!?${anyOf(MOTION_UTILITIES)}${CLASS_END}`;
69
80
  var FONT_SIZE_PATTERN = `${CLASS_START}text-${anyOf(STOCK_FONT_SIZES)}(?:/${CLASS_VALUE})?${CLASS_END}`;
70
- var OFF_SCALE_PATTERN = `${CLASS_START}-?${anyOf(SCALED_UTILITIES)}-(?!${anyOf(SPACING_STEPS)}${CLASS_END})(?:\\d+(?:\\.\\d+)?|px)${CLASS_END}`;
81
+ var offScalePattern = (sign, utilities, units) => `${CLASS_START}${sign}${anyOf(utilities)}-(?!${anyOf(units)}${CLASS_END})(?:\\d+(?:\\.\\d+)?|px)${CLASS_END}`;
82
+ var SPACING_PATTERN = offScalePattern("-?", SPACING_UTILITIES, SPACING_UNITS);
83
+ var SIZING_PATTERN = offScalePattern("", SIZING_UTILITIES, SIZING_UNITS);
71
84
  var OPACITY_PATTERN = `${CLASS_START}${anyOf(COLOUR_UTILITIES)}-(?:[a-zA-Z0-9-]+|\\([^)\\s]+\\))/(?:\\d+(?:\\.\\d+)?|\\[[^\\]\\s]+\\]|\\([^)\\s]+\\))${CLASS_END}`;
72
- var MAX_WIDTH_PATTERN = `${CLASS_START}max-w-`;
73
- var designClassRestrictions = ({ dark }) => [
74
- {
85
+ var NAMED_CAP_PATTERN = `${CLASS_START}max-w-(?!${anyOf(UNBOUNDED_CAPS)}${CLASS_END})(?!\\d+(?:\\.\\d+)?(?:/\\d+)?${CLASS_END})(?!\\[)${CLASS_VALUE}${CLASS_END}`;
86
+ var COLUMN_OR_FRACTION_PATTERN = `${CLASS_START}(?:col-(?:span|start|end)-\\d+|grid-cols-(?:[4-9]|[1-9]\\d+|subgrid)|${anyOf(SIZING_UTILITIES)}-\\d+/\\d+)${CLASS_END}`;
87
+ var DESIGN_CLASS_RESTRICTIONS = {
88
+ responsiveVariant: {
75
89
  pattern: RESPONSIVE_VARIANTS,
76
90
  message: "Use one responsive switch, at `lg:`. Drop the `sm:`, `md:`, `max-sm:` and `max-md:` variants."
77
91
  },
78
- ...dark ? [] : [
79
- {
80
- pattern: DARK_VARIANT,
81
- message: "Avoid the `dark:` variant, or turn dark mode on with `design: { dark: true }`."
82
- }
83
- ],
84
- {
92
+ darkVariant: {
93
+ pattern: DARK_VARIANT,
94
+ message: "Avoid the `dark:` variant, or turn dark mode on with `design: { dark: true }`."
95
+ },
96
+ motion: {
85
97
  pattern: MOTION_PATTERN,
86
98
  message: "Put motion behind `motion-safe:` so reduced-motion users get none; only `transition-none` and `animate-none` pass without it."
87
99
  },
88
- {
100
+ fontSize: {
89
101
  pattern: FONT_SIZE_PATTERN,
90
102
  message: "Avoid a stock font size (`text-xs` to `text-9xl`); use a type scale alias from the theme."
91
103
  },
92
- {
93
- pattern: OFF_SCALE_PATTERN,
94
- message: `Use a value from the scale (${SPACING_STEPS.join(", ")}); this one is off it. A fraction or a keyword such as \`w-1/2\` or \`w-full\` is fine.`
104
+ spacingUnit: {
105
+ pattern: SPACING_PATTERN,
106
+ message: `Spacing takes 0 or ${GENERAL_SET}; this number is off it, and \`px\` is too.`
95
107
  },
96
- {
108
+ sizingUnit: {
109
+ pattern: SIZING_PATTERN,
110
+ message: `A size takes 0, ${GENERAL_SET} or ${LAYOUT_SET}; this number is in neither set. A keyword such as \`w-full\` is fine.`
111
+ },
112
+ opacity: {
97
113
  pattern: OPACITY_PATTERN,
98
114
  message: "Avoid a `/N` modifier on a colour or a text utility; use an alpha colour token or a type scale alias from the theme."
99
115
  },
100
- {
101
- pattern: MAX_WIDTH_PATTERN,
102
- message: "Avoid `max-w-*`; set the width from the grid columns instead."
116
+ namedCap: {
117
+ pattern: NAMED_CAP_PATTERN,
118
+ message: `A cap is a layout unit written by its number, such as \`max-w-488\` or \`max-w-1280\`, never a name. The layout set is ${LAYOUT_UNITS.join(", ")}.`
119
+ },
120
+ columnOrFraction: {
121
+ pattern: COLUMN_OR_FRACTION_PATTERN,
122
+ message: `Do not set a width from a column count or a fraction: a block hugs its content, fills its container (\`w-full\`, \`flex-1\`) or takes a layout unit (${LAYOUT_SET}). \`col-span-full\` and \`grid-cols-1\` to \`grid-cols-3\` are fine.`
103
123
  }
104
- ];
124
+ };
125
+ var DARK_KEY = "darkVariant";
126
+ var designClassRestrictions = ({ dark }) => Object.entries(DESIGN_CLASS_RESTRICTIONS).filter(([key]) => !dark || key !== DARK_KEY).map(([, restriction]) => restriction);
105
127
 
106
128
  // needlessUseClient.ts
107
129
  import { ESLintUtils } from "@typescript-eslint/utils";
@@ -1539,6 +1561,34 @@ var RESTRICTED_SELECTORS = {
1539
1561
  cloneElementMember: {
1540
1562
  selector: "MemberExpression[object.name='React'][property.name='cloneElement']",
1541
1563
  message: "Avoid React.cloneElement; pass data through props instead of mutating a child element."
1564
+ },
1565
+ forwardRefImport: {
1566
+ selector: "ImportDeclaration[source.value='react'] > ImportSpecifier[imported.name='forwardRef']",
1567
+ message: "Avoid forwardRef; `ref` is a prop since React 19, so a component takes it as a prop."
1568
+ },
1569
+ forwardRefCall: {
1570
+ selector: "CallExpression[callee.name='forwardRef']",
1571
+ message: "Avoid forwardRef; `ref` is a prop since React 19, so a component takes it as a prop."
1572
+ },
1573
+ forwardRefMember: {
1574
+ selector: "MemberExpression[object.name='React'][property.name='forwardRef']",
1575
+ message: "Avoid React.forwardRef; `ref` is a prop since React 19, so a component takes it as a prop."
1576
+ },
1577
+ useContextImport: {
1578
+ selector: "ImportDeclaration[source.value='react'] > ImportSpecifier[imported.name='useContext']",
1579
+ message: "Avoid useContext; read a context with `use`."
1580
+ },
1581
+ useContextCall: {
1582
+ selector: "CallExpression[callee.name='useContext']",
1583
+ message: "Avoid useContext; read a context with `use`."
1584
+ },
1585
+ useContextMember: {
1586
+ selector: "MemberExpression[object.name='React'][property.name='useContext']",
1587
+ message: "Avoid React.useContext; read a context with `use`."
1588
+ },
1589
+ contextProvider: {
1590
+ selector: "JSXOpeningElement > JSXMemberExpression[property.name='Provider'][object.name=/Context$/]",
1591
+ message: "Avoid `<XContext.Provider>`; since React 19 the context is its own provider, so render `<XContext>`."
1542
1592
  }
1543
1593
  };
1544
1594
  var ALL_SELECTOR_KEYS = Object.keys(RESTRICTED_SELECTORS);
@@ -1549,6 +1599,21 @@ var cnTernarySelector = (classMergeName) => ({
1549
1599
  selector: `CallExpression[callee.name='${classMergeName}'] > ConditionalExpression`,
1550
1600
  message: "Avoid a ternary inside `cn()`; use a cva variant or an object entry instead."
1551
1601
  });
1602
+ var classMergeSelectors = (classMergeName) => {
1603
+ const name = `^${classMergeName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`;
1604
+ const defaults = getDefaultSelectors();
1605
+ const readByDefault = defaults.some(
1606
+ (selector) => selector.kind === SelectorKind.Callee && "name" in selector && selector.name === name
1607
+ );
1608
+ return readByDefault ? void 0 : [
1609
+ ...defaults,
1610
+ {
1611
+ kind: SelectorKind.Callee,
1612
+ name,
1613
+ match: [{ type: MatcherType.String }, { type: MatcherType.ObjectKey }]
1614
+ }
1615
+ ];
1616
+ };
1552
1617
  var restrictedSyntaxRule = (keys, extra = []) => ({
1553
1618
  "no-restricted-syntax": ["error", ...keys.map((key) => RESTRICTED_SELECTORS[key]), ...extra]
1554
1619
  });
@@ -1589,8 +1654,12 @@ var importOrderRule = (groups) => ({
1589
1654
  });
1590
1655
  var escapeForRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1591
1656
  var arbitraryTailwindValuePattern = (allow) => {
1592
- const exempt = allow.length ? `(?!(?:${allow.map(escapeForRegExp).join("|")})-)` : "";
1593
- return `(?:^|:)!?-?${exempt}[a-zA-Z][a-zA-Z0-9-]*-\\[[^\\]]+\\](?:/[a-zA-Z0-9.]+)?!?$`;
1657
+ const names = allow.map(escapeForRegExp).join("|");
1658
+ const exemptUtility = allow.length ? `(?!(?:${names})-)` : "";
1659
+ const exemptProperty = allow.length ? `(?!(?:${names}):)` : "";
1660
+ const utilityValue = `-?${exemptUtility}[a-zA-Z][a-zA-Z0-9-]*-\\[[^\\]]+\\](?:/[a-zA-Z0-9.]+)?`;
1661
+ const bracketedProperty = `\\[${exemptProperty}-{0,2}[a-zA-Z][a-zA-Z0-9-]*:[^\\]]+\\]`;
1662
+ return `(?:^|:)!?(?:${utilityValue}|${bracketedProperty})!?$`;
1594
1663
  };
1595
1664
  var buildConfig = ({
1596
1665
  next = false,
@@ -1598,6 +1667,8 @@ var buildConfig = ({
1598
1667
  importGroups = DEFAULT_IMPORT_GROUPS,
1599
1668
  tsconfigRootDir = process.cwd(),
1600
1669
  tailwindEntryPoint,
1670
+ tailwindCwd,
1671
+ ignoreClasses = [],
1601
1672
  allowArbitraryClasses = [],
1602
1673
  design = false,
1603
1674
  classMergeName = "cn",
@@ -1605,6 +1676,7 @@ var buildConfig = ({
1605
1676
  strictExportGlobs = [],
1606
1677
  extend = []
1607
1678
  } = {}) => {
1679
+ const classMergeBans = next || tailwindEntryPoint ? [cnTernarySelector(classMergeName)] : [];
1608
1680
  const plugins = {
1609
1681
  "import-x": importXPlugin,
1610
1682
  "import-helpers": importHelpers,
@@ -1616,7 +1688,7 @@ var buildConfig = ({
1616
1688
  ...importRules,
1617
1689
  ...securityRules,
1618
1690
  ...generalRules,
1619
- ...restrictedSyntaxRule(ALL_SELECTOR_KEYS, next ? [cnTernarySelector(classMergeName)] : []),
1691
+ ...restrictedSyntaxRule(ALL_SELECTOR_KEYS, classMergeBans),
1620
1692
  ...importOrderRule(importGroups)
1621
1693
  };
1622
1694
  const languageGlobals = { ...globals2.node, ...globals2.es2021 };
@@ -1637,35 +1709,40 @@ var buildConfig = ({
1637
1709
  settings.react = { version: "detect" };
1638
1710
  settings["import-x/resolver-next"] = [createTypeScriptImportResolver({ alwaysTryTypes: true })];
1639
1711
  settings["jsx-a11y"] = { components: JSX_A11Y_COMPONENTS };
1640
- if (tailwindEntryPoint) {
1641
- const allowDark = typeof design === "object" && design.dark === true;
1642
- const designRestrictions = design ? designClassRestrictions({ dark: allowDark }) : [];
1643
- plugins["better-tailwindcss"] = betterTailwind;
1644
- Object.assign(rules, {
1645
- "better-tailwindcss/no-unknown-classes": "error",
1646
- "better-tailwindcss/no-conflicting-classes": "error",
1647
- "better-tailwindcss/no-concatenated-classes": "error",
1648
- "better-tailwindcss/no-restricted-classes": [
1649
- "error",
1650
- {
1651
- restrict: [
1652
- {
1653
- pattern: arbitraryTailwindValuePattern(allowArbitraryClasses),
1654
- message: "Avoid an arbitrary Tailwind value ($0); use a theme token, or list its prefix in allowArbitraryClasses when it has none (e.g. grid-cols-[...])."
1655
- },
1656
- ...designRestrictions
1657
- ]
1658
- }
1659
- ]
1660
- });
1661
- settings["better-tailwindcss"] = { entryPoint: tailwindEntryPoint };
1662
- }
1712
+ }
1713
+ if (tailwindEntryPoint) {
1714
+ const allowDark = typeof design === "object" && design.dark === true;
1715
+ const designRestrictions = design ? designClassRestrictions({ dark: allowDark }) : [];
1716
+ plugins["better-tailwindcss"] = betterTailwind;
1717
+ Object.assign(rules, {
1718
+ "better-tailwindcss/no-unknown-classes": ignoreClasses.length ? ["error", { ignore: ignoreClasses }] : "error",
1719
+ "better-tailwindcss/no-conflicting-classes": "error",
1720
+ "better-tailwindcss/no-concatenated-classes": "error",
1721
+ "better-tailwindcss/no-restricted-classes": [
1722
+ "error",
1723
+ {
1724
+ restrict: [
1725
+ {
1726
+ pattern: arbitraryTailwindValuePattern(allowArbitraryClasses),
1727
+ message: "Avoid an arbitrary Tailwind value or a property set in brackets ($0); use a theme token, or list its prefix (grid-cols) or its property (mask-type) in allowArbitraryClasses when it has none."
1728
+ },
1729
+ ...designRestrictions
1730
+ ]
1731
+ }
1732
+ ]
1733
+ });
1734
+ const selectors = classMergeSelectors(classMergeName);
1735
+ settings["better-tailwindcss"] = {
1736
+ entryPoint: tailwindEntryPoint,
1737
+ ...tailwindCwd && { cwd: tailwindCwd },
1738
+ ...selectors && { selectors }
1739
+ };
1663
1740
  }
1664
1741
  const rootConfigOverride = {
1665
1742
  files: ["*.{mjs,js,ts,mts,cts}"],
1666
1743
  rules: {
1667
1744
  "import-x/no-default-export": "off",
1668
- ...restrictedSyntaxRule(NON_EXPORT_DEFAULT_KEYS, next ? [cnTernarySelector(classMergeName)] : [])
1745
+ ...restrictedSyntaxRule(NON_EXPORT_DEFAULT_KEYS, classMergeBans)
1669
1746
  }
1670
1747
  };
1671
1748
  const nextFileConventionsOverride = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soujvnunes/eslint-config",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Shared flat ESLint config factories (base + Next.js).",
5
5
  "license": "MIT",
6
6
  "author": "soujvnunes",