@soujvnunes/eslint-config 0.11.0 → 0.12.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
@@ -46,6 +46,7 @@ export default createBaseConfig()
46
46
  | `tsconfigRootDir` | `process.cwd()` | Root for typescript-eslint's project service |
47
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
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
+ | `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 |
49
50
  | `classMergeName` | `'cn'` | The class-merge helper name a ternary passed straight to it is banned inside of |
50
51
  | `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
52
  | `strictExportGlobs` | `[]` | Globs wired to `soujvnunes/one-export-per-file`. With no globs the rule stays exported but off |
@@ -118,6 +119,26 @@ Both are Next-preset only, since a plain TypeScript library's `index.ts` is its
118
119
 
119
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.
120
121
 
122
+ ## Design class rules, when `design` is set
123
+
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.
125
+
126
+ ```js
127
+ export default createNextConfig({ tailwindEntryPoint: './app/tailwind.config.css', design: true })
128
+ ```
129
+
130
+ | Entry | Reports | Passes |
131
+ | --- | --- | --- |
132
+ | Responsive switch | `sm:flex`, `md:flex`, `max-sm:hidden`, `max-md:hidden` | `lg:flex`, `max-lg:flex` |
133
+ | Dark variant | `dark:bg-surface`, unless `design: { dark: true }` | `bg-surface` |
134
+ | 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
+ | 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` |
139
+
140
+ A decimal and `px` are outside the scale, a fraction and a keyword are not. Each report states its rule in plain words.
141
+
121
142
  ## Module boundaries
122
143
 
123
144
  - `nextConfigModules` restricts a `next.config.ts`, `.mts` or `.cts` and the modules it names to relative imports only (`no-restricted-imports` on `['@/*']`), on the Next preset. A `next.config.js` or `.mjs` is not linted at all, since `*.config.js` and `*.config.mjs` are in the default ignores; the modules it names still are. A config file that imports through the `@/...` alias resolves it differently at build time than the app does, so anything the config loads stays relative.
package/dist/index.d.ts CHANGED
@@ -16,6 +16,9 @@ interface ConfigOptions {
16
16
  tsconfigRootDir?: string;
17
17
  tailwindEntryPoint?: string;
18
18
  allowArbitraryClasses?: string[];
19
+ design?: boolean | {
20
+ dark?: boolean;
21
+ };
19
22
  classMergeName?: string;
20
23
  nextConfigModules?: string[];
21
24
  strictExportGlobs?: string[];
package/dist/index.js CHANGED
@@ -14,6 +14,95 @@ import unusedImports from "eslint-plugin-unused-imports";
14
14
  import globals2 from "globals";
15
15
  import tseslint from "typescript-eslint";
16
16
 
17
+ // designClassRestrictions.ts
18
+ var anyOf = (parts) => `(?:${parts.join("|")})`;
19
+ var CLASS_START = "(?:^|:)!?";
20
+ var CLASS_END = "!?$";
21
+ var CLASS_VALUE = "[^\\s!]+";
22
+ var SPACING_STEPS = ["0", "4", "8", "12", "16", "24", "40", "64", "104", "168"];
23
+ var SCALED_UTILITIES = [
24
+ "p[xytrblse]?",
25
+ "m[xytrblse]?",
26
+ "gap(?:-[xy])?",
27
+ "space-[xy]",
28
+ "inset(?:-[xy])?",
29
+ "top",
30
+ "right",
31
+ "bottom",
32
+ "left",
33
+ "start",
34
+ "end",
35
+ "w",
36
+ "h",
37
+ "size",
38
+ "min-w",
39
+ "min-h",
40
+ "max-h",
41
+ "basis"
42
+ ];
43
+ var COLOUR_UTILITIES = [
44
+ "bg",
45
+ "text",
46
+ "border",
47
+ "ring",
48
+ "outline",
49
+ "fill",
50
+ "stroke",
51
+ "divide",
52
+ "shadow",
53
+ "from",
54
+ "via",
55
+ "to"
56
+ ];
57
+ var MOTION_UTILITIES = [
58
+ `transition(?:-(?!none${CLASS_END})${CLASS_VALUE})?`,
59
+ `animate-(?!none${CLASS_END})${CLASS_VALUE}`,
60
+ `duration-${CLASS_VALUE}`,
61
+ `ease-${CLASS_VALUE}`,
62
+ `delay-${CLASS_VALUE}`
63
+ ];
64
+ var STOCK_FONT_SIZES = ["xs", "sm", "base", "lg", "xl", "[2-9]xl"];
65
+ var RESPONSIVE_VARIANTS = "(?:^|:)(?:max-)?(?:sm|md):";
66
+ var DARK_VARIANT = "(?:^|:)dark:";
67
+ var MOTION_SAFE_VARIANT = "(?:.*:)?motion-safe:";
68
+ var MOTION_PATTERN = `^(?!${MOTION_SAFE_VARIANT})(?:.*:)?!?${anyOf(MOTION_UTILITIES)}${CLASS_END}`;
69
+ 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}`;
71
+ 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
+ {
75
+ pattern: RESPONSIVE_VARIANTS,
76
+ message: "Use one responsive switch, at `lg:`. Drop the `sm:`, `md:`, `max-sm:` and `max-md:` variants."
77
+ },
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
+ {
85
+ pattern: MOTION_PATTERN,
86
+ message: "Put motion behind `motion-safe:` so reduced-motion users get none; only `transition-none` and `animate-none` pass without it."
87
+ },
88
+ {
89
+ pattern: FONT_SIZE_PATTERN,
90
+ message: "Avoid a stock font size (`text-xs` to `text-9xl`); use a type scale alias from the theme."
91
+ },
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.`
95
+ },
96
+ {
97
+ pattern: OPACITY_PATTERN,
98
+ 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
+ },
100
+ {
101
+ pattern: MAX_WIDTH_PATTERN,
102
+ message: "Avoid `max-w-*`; set the width from the grid columns instead."
103
+ }
104
+ ];
105
+
17
106
  // needlessUseClient.ts
18
107
  import { ESLintUtils } from "@typescript-eslint/utils";
19
108
 
@@ -1510,6 +1599,7 @@ var buildConfig = ({
1510
1599
  tsconfigRootDir = process.cwd(),
1511
1600
  tailwindEntryPoint,
1512
1601
  allowArbitraryClasses = [],
1602
+ design = false,
1513
1603
  classMergeName = "cn",
1514
1604
  nextConfigModules = [],
1515
1605
  strictExportGlobs = [],
@@ -1548,6 +1638,8 @@ var buildConfig = ({
1548
1638
  settings["import-x/resolver-next"] = [createTypeScriptImportResolver({ alwaysTryTypes: true })];
1549
1639
  settings["jsx-a11y"] = { components: JSX_A11Y_COMPONENTS };
1550
1640
  if (tailwindEntryPoint) {
1641
+ const allowDark = typeof design === "object" && design.dark === true;
1642
+ const designRestrictions = design ? designClassRestrictions({ dark: allowDark }) : [];
1551
1643
  plugins["better-tailwindcss"] = betterTailwind;
1552
1644
  Object.assign(rules, {
1553
1645
  "better-tailwindcss/no-unknown-classes": "error",
@@ -1560,7 +1652,8 @@ var buildConfig = ({
1560
1652
  {
1561
1653
  pattern: arbitraryTailwindValuePattern(allowArbitraryClasses),
1562
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-[...])."
1563
- }
1655
+ },
1656
+ ...designRestrictions
1564
1657
  ]
1565
1658
  }
1566
1659
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soujvnunes/eslint-config",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Shared flat ESLint config factories (base + Next.js).",
5
5
  "license": "MIT",
6
6
  "author": "soujvnunes",