@soujvnunes/eslint-config 0.11.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,9 +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 |
49
- | `classMergeName` | `'cn'` | The class-merge helper name a ternary passed straight to it is banned inside of |
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 |
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 |
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 |
50
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 |
51
67
  | `strictExportGlobs` | `[]` | Globs wired to `soujvnunes/one-export-per-file`. With no globs the rule stays exported but off |
52
68
  | `extend` | `[]` | Extra flat-config objects appended at the end |
@@ -78,7 +94,7 @@ These are the opinions most likely to surprise an existing codebase. All of them
78
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.
79
95
 
80
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.
81
- - `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.
82
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.
83
99
 
84
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.
@@ -110,13 +126,52 @@ Two more `no-restricted-syntax` overrides, each adding a `Program` selector to t
110
126
 
111
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.
112
128
 
113
- ## `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
114
147
 
115
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.
116
149
 
117
150
  ## Arbitrary Tailwind values, when `tailwindEntryPoint` is set
118
151
 
119
- `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.
153
+
154
+ ## Design class rules, when `design` is set
155
+
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.
157
+
158
+ ```js
159
+ export default createNextConfig({ tailwindEntryPoint: './app/tailwind.config.css', design: true })
160
+ ```
161
+
162
+ | Entry | Reports | Passes |
163
+ | --- | --- | --- |
164
+ | Responsive switch | `sm:flex`, `md:flex`, `max-sm:hidden`, `max-md:hidden` | `lg:flex`, `max-lg:flex` |
165
+ | Dark variant | `dark:bg-surface`, unless `design: { dark: true }` | `bg-surface` |
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` |
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) |
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` |
173
+
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.
120
175
 
121
176
  ## Module boundaries
122
177
 
package/dist/index.d.ts CHANGED
@@ -15,7 +15,12 @@ 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[];
21
+ design?: boolean | {
22
+ dark?: boolean;
23
+ };
19
24
  classMergeName?: string;
20
25
  nextConfigModules?: string[];
21
26
  strictExportGlobs?: string[];
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";
@@ -14,6 +16,115 @@ import unusedImports from "eslint-plugin-unused-imports";
14
16
  import globals2 from "globals";
15
17
  import tseslint from "typescript-eslint";
16
18
 
19
+ // designClassRestrictions.ts
20
+ var anyOf = (parts) => `(?:${parts.join("|")})`;
21
+ var CLASS_START = "(?:^|:)!?";
22
+ var CLASS_END = "!?$";
23
+ var CLASS_VALUE = "[^\\s!]+";
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 = [
40
+ "p[xytrblse]?",
41
+ "m[xytrblse]?",
42
+ "gap(?:-[xy])?",
43
+ "space-[xy]",
44
+ "inset(?:-[xy])?",
45
+ "top",
46
+ "right",
47
+ "bottom",
48
+ "left",
49
+ "start",
50
+ "end"
51
+ ];
52
+ var SIZING_UTILITIES = ["w", "h", "size", "min-w", "min-h", "max-w", "max-h", "basis"];
53
+ var COLOUR_UTILITIES = [
54
+ "bg",
55
+ "text",
56
+ "border",
57
+ "ring",
58
+ "outline",
59
+ "fill",
60
+ "stroke",
61
+ "divide",
62
+ "shadow",
63
+ "from",
64
+ "via",
65
+ "to"
66
+ ];
67
+ var MOTION_UTILITIES = [
68
+ `transition(?:-(?!none${CLASS_END})${CLASS_VALUE})?`,
69
+ `animate-(?!none${CLASS_END})${CLASS_VALUE}`,
70
+ `duration-${CLASS_VALUE}`,
71
+ `ease-${CLASS_VALUE}`,
72
+ `delay-${CLASS_VALUE}`
73
+ ];
74
+ var STOCK_FONT_SIZES = ["xs", "sm", "base", "lg", "xl", "[2-9]xl"];
75
+ var UNBOUNDED_CAPS = ["full", "none", "fit", "min", "max"];
76
+ var RESPONSIVE_VARIANTS = "(?:^|:)(?:max-)?(?:sm|md):";
77
+ var DARK_VARIANT = "(?:^|:)dark:";
78
+ var MOTION_SAFE_VARIANT = "(?:.*:)?motion-safe:";
79
+ var MOTION_PATTERN = `^(?!${MOTION_SAFE_VARIANT})(?:.*:)?!?${anyOf(MOTION_UTILITIES)}${CLASS_END}`;
80
+ var FONT_SIZE_PATTERN = `${CLASS_START}text-${anyOf(STOCK_FONT_SIZES)}(?:/${CLASS_VALUE})?${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);
84
+ var OPACITY_PATTERN = `${CLASS_START}${anyOf(COLOUR_UTILITIES)}-(?:[a-zA-Z0-9-]+|\\([^)\\s]+\\))/(?:\\d+(?:\\.\\d+)?|\\[[^\\]\\s]+\\]|\\([^)\\s]+\\))${CLASS_END}`;
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: {
89
+ pattern: RESPONSIVE_VARIANTS,
90
+ message: "Use one responsive switch, at `lg:`. Drop the `sm:`, `md:`, `max-sm:` and `max-md:` variants."
91
+ },
92
+ darkVariant: {
93
+ pattern: DARK_VARIANT,
94
+ message: "Avoid the `dark:` variant, or turn dark mode on with `design: { dark: true }`."
95
+ },
96
+ motion: {
97
+ pattern: MOTION_PATTERN,
98
+ message: "Put motion behind `motion-safe:` so reduced-motion users get none; only `transition-none` and `animate-none` pass without it."
99
+ },
100
+ fontSize: {
101
+ pattern: FONT_SIZE_PATTERN,
102
+ message: "Avoid a stock font size (`text-xs` to `text-9xl`); use a type scale alias from the theme."
103
+ },
104
+ spacingUnit: {
105
+ pattern: SPACING_PATTERN,
106
+ message: `Spacing takes 0 or ${GENERAL_SET}; this number is off it, and \`px\` is too.`
107
+ },
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: {
113
+ pattern: OPACITY_PATTERN,
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."
115
+ },
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.`
123
+ }
124
+ };
125
+ var DARK_KEY = "darkVariant";
126
+ var designClassRestrictions = ({ dark }) => Object.entries(DESIGN_CLASS_RESTRICTIONS).filter(([key]) => !dark || key !== DARK_KEY).map(([, restriction]) => restriction);
127
+
17
128
  // needlessUseClient.ts
18
129
  import { ESLintUtils } from "@typescript-eslint/utils";
19
130
 
@@ -1450,6 +1561,34 @@ var RESTRICTED_SELECTORS = {
1450
1561
  cloneElementMember: {
1451
1562
  selector: "MemberExpression[object.name='React'][property.name='cloneElement']",
1452
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>`."
1453
1592
  }
1454
1593
  };
1455
1594
  var ALL_SELECTOR_KEYS = Object.keys(RESTRICTED_SELECTORS);
@@ -1460,6 +1599,21 @@ var cnTernarySelector = (classMergeName) => ({
1460
1599
  selector: `CallExpression[callee.name='${classMergeName}'] > ConditionalExpression`,
1461
1600
  message: "Avoid a ternary inside `cn()`; use a cva variant or an object entry instead."
1462
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
+ };
1463
1617
  var restrictedSyntaxRule = (keys, extra = []) => ({
1464
1618
  "no-restricted-syntax": ["error", ...keys.map((key) => RESTRICTED_SELECTORS[key]), ...extra]
1465
1619
  });
@@ -1500,8 +1654,12 @@ var importOrderRule = (groups) => ({
1500
1654
  });
1501
1655
  var escapeForRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1502
1656
  var arbitraryTailwindValuePattern = (allow) => {
1503
- const exempt = allow.length ? `(?!(?:${allow.map(escapeForRegExp).join("|")})-)` : "";
1504
- 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})!?$`;
1505
1663
  };
1506
1664
  var buildConfig = ({
1507
1665
  next = false,
@@ -1509,12 +1667,16 @@ var buildConfig = ({
1509
1667
  importGroups = DEFAULT_IMPORT_GROUPS,
1510
1668
  tsconfigRootDir = process.cwd(),
1511
1669
  tailwindEntryPoint,
1670
+ tailwindCwd,
1671
+ ignoreClasses = [],
1512
1672
  allowArbitraryClasses = [],
1673
+ design = false,
1513
1674
  classMergeName = "cn",
1514
1675
  nextConfigModules = [],
1515
1676
  strictExportGlobs = [],
1516
1677
  extend = []
1517
1678
  } = {}) => {
1679
+ const classMergeBans = next || tailwindEntryPoint ? [cnTernarySelector(classMergeName)] : [];
1518
1680
  const plugins = {
1519
1681
  "import-x": importXPlugin,
1520
1682
  "import-helpers": importHelpers,
@@ -1526,7 +1688,7 @@ var buildConfig = ({
1526
1688
  ...importRules,
1527
1689
  ...securityRules,
1528
1690
  ...generalRules,
1529
- ...restrictedSyntaxRule(ALL_SELECTOR_KEYS, next ? [cnTernarySelector(classMergeName)] : []),
1691
+ ...restrictedSyntaxRule(ALL_SELECTOR_KEYS, classMergeBans),
1530
1692
  ...importOrderRule(importGroups)
1531
1693
  };
1532
1694
  const languageGlobals = { ...globals2.node, ...globals2.es2021 };
@@ -1547,32 +1709,40 @@ var buildConfig = ({
1547
1709
  settings.react = { version: "detect" };
1548
1710
  settings["import-x/resolver-next"] = [createTypeScriptImportResolver({ alwaysTryTypes: true })];
1549
1711
  settings["jsx-a11y"] = { components: JSX_A11Y_COMPONENTS };
1550
- if (tailwindEntryPoint) {
1551
- plugins["better-tailwindcss"] = betterTailwind;
1552
- Object.assign(rules, {
1553
- "better-tailwindcss/no-unknown-classes": "error",
1554
- "better-tailwindcss/no-conflicting-classes": "error",
1555
- "better-tailwindcss/no-concatenated-classes": "error",
1556
- "better-tailwindcss/no-restricted-classes": [
1557
- "error",
1558
- {
1559
- restrict: [
1560
- {
1561
- pattern: arbitraryTailwindValuePattern(allowArbitraryClasses),
1562
- 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-[...])."
1563
- }
1564
- ]
1565
- }
1566
- ]
1567
- });
1568
- settings["better-tailwindcss"] = { entryPoint: tailwindEntryPoint };
1569
- }
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
+ };
1570
1740
  }
1571
1741
  const rootConfigOverride = {
1572
1742
  files: ["*.{mjs,js,ts,mts,cts}"],
1573
1743
  rules: {
1574
1744
  "import-x/no-default-export": "off",
1575
- ...restrictedSyntaxRule(NON_EXPORT_DEFAULT_KEYS, next ? [cnTernarySelector(classMergeName)] : [])
1745
+ ...restrictedSyntaxRule(NON_EXPORT_DEFAULT_KEYS, classMergeBans)
1576
1746
  }
1577
1747
  };
1578
1748
  const nextFileConventionsOverride = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soujvnunes/eslint-config",
3
- "version": "0.11.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",