@soujvnunes/eslint-config 0.10.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 |
@@ -75,10 +76,11 @@ These are the opinions most likely to surprise an existing codebase. All of them
75
76
 
76
77
  **`security/detect-object-injection` is not included.** It predates TypeScript narrowing and reports every `obj[key]`, including keys already narrowed to a literal union and plain array indexes. Use `noUncheckedIndexedAccess` and an own-key (`Object.hasOwn`) guard instead.
77
78
 
78
- **Two client-boundary rules on the Next preset, neither autofixable.** Both read `.jsx` and `.tsx` files that open with `'use client'`, and skip `error` and `global-error`, which Next requires to be client components.
79
+ **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
80
 
80
81
  - `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
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.
83
+ - `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.
82
84
 
83
85
  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.
84
86
 
@@ -117,6 +119,26 @@ Both are Next-preset only, since a plain TypeScript library's `index.ts` is its
117
119
 
118
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.
119
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
+
120
142
  ## Module boundaries
121
143
 
122
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
 
@@ -29,8 +118,18 @@ var findUseClientDirective = (program) => {
29
118
  };
30
119
 
31
120
  // needsClient.ts
32
- import { AST_NODE_TYPES as AST_NODE_TYPES12, TSESLint as TSESLint4 } from "@typescript-eslint/utils";
121
+ import { AST_NODE_TYPES as AST_NODE_TYPES13, TSESLint as TSESLint5 } from "@typescript-eslint/utils";
122
+
123
+ // browserGlobals.ts
33
124
  import globals from "globals";
125
+ var BROWSER_GLOBALS = /* @__PURE__ */ new Set([
126
+ ...Object.keys(globals.browser).filter(
127
+ (name) => !Object.hasOwn(globals.node, name) && !Object.hasOwn(globals.builtin, name)
128
+ ),
129
+ "navigator",
130
+ "localStorage",
131
+ "sessionStorage"
132
+ ]);
34
133
 
35
134
  // calleeName.ts
36
135
  import { AST_NODE_TYPES as AST_NODE_TYPES2 } from "@typescript-eslint/utils";
@@ -407,6 +506,9 @@ var createClassifier = (sourceCode, importMembersAreData) => {
407
506
  return { classify: classify2, classifyTag, positionOf, variableOf };
408
507
  };
409
508
 
509
+ // createClientWalk.ts
510
+ import { AST_NODE_TYPES as AST_NODE_TYPES12, TSESLint as TSESLint4 } from "@typescript-eslint/utils";
511
+
410
512
  // isEventHandler.ts
411
513
  var isEventHandler = (key) => /^on[A-Z]/u.test(key);
412
514
 
@@ -414,173 +516,183 @@ var isEventHandler = (key) => /^on[A-Z]/u.test(key);
414
516
  var FUNCTION_ATTRIBUTES = /* @__PURE__ */ new Set(["ref", "action", "formAction"]);
415
517
  var isFunctionAttribute = (key) => isEventHandler(key) || FUNCTION_ATTRIBUTES.has(key);
416
518
 
417
- // needsClient.ts
519
+ // isHookName.ts
520
+ var isHookName = (name) => /^use[A-Z]/u.test(name);
521
+
522
+ // createClientWalk.ts
418
523
  var { DefinitionType: DefinitionType4 } = TSESLint4.Scope;
419
- var HOOK = /^use[A-Z]/u;
420
- var STYLESHEET = /\.(?:css|scss|sass|less)$/u;
421
524
  var CLIENT_CALLS = /* @__PURE__ */ new Set(["use", "createContext", "createPortal", "flushSync"]);
422
- var CLIENT_MODULES = /* @__PURE__ */ new Set(["next/dynamic", "client-only"]);
423
525
  var CLASS_BASES = /* @__PURE__ */ new Set(["Component", "PureComponent"]);
526
+ var createClientWalk = (sourceCode, { classify: classify2, classifyTag, positionOf, variableOf }, countsOnlyFunctions = false) => {
527
+ const isData = (node) => classify2(node, "prop").data;
528
+ const isFunctionExpression = (node) => node?.type === AST_NODE_TYPES12.ArrowFunctionExpression || node?.type === AST_NODE_TYPES12.FunctionExpression;
529
+ const isBoundToFunction = (node) => !!variableOf(node, node.name)?.defs.some(
530
+ (def) => def.type === DefinitionType4.FunctionName || def.type === DefinitionType4.Variable && def.node.type === AST_NODE_TYPES12.VariableDeclarator && isFunctionExpression(def.node.init)
531
+ );
532
+ const isFunctionValue = (node) => isFunctionExpression(node) || node.type === AST_NODE_TYPES12.Identifier && isBoundToFunction(node);
533
+ const isClientValue = (node) => countsOnlyFunctions ? isFunctionValue(node) : !isData(node);
534
+ const callNames = (callee) => {
535
+ if (callee.type !== AST_NODE_TYPES12.Identifier) return [calleeName(callee)];
536
+ return [callee.name, importedName(variableOf(callee, callee.name))];
537
+ };
538
+ const needsNode = (node) => {
539
+ switch (node.type) {
540
+ case AST_NODE_TYPES12.CallExpression:
541
+ return callNames(node.callee).some((name) => isHookName(name) || CLIENT_CALLS.has(name));
542
+ case AST_NODE_TYPES12.ClassDeclaration:
543
+ case AST_NODE_TYPES12.ClassExpression:
544
+ return !!node.superClass && CLASS_BASES.has(calleeName(node.superClass));
545
+ case AST_NODE_TYPES12.MemberExpression:
546
+ return node.object.type === AST_NODE_TYPES12.Identifier && node.object.name === "globalThis" && !node.computed && node.property.type === AST_NODE_TYPES12.Identifier && BROWSER_GLOBALS.has(node.property.name) && !variableOf(node.object, "globalThis")?.defs.length;
547
+ case AST_NODE_TYPES12.JSXOpeningElement: {
548
+ if (!classifyTag(node).data) return true;
549
+ const isTag = positionOf(node) === "text";
550
+ return node.attributes.some((attribute) => {
551
+ if (attribute.type === AST_NODE_TYPES12.JSXSpreadAttribute)
552
+ return isTag ? !isData(attribute.argument) : isClientValue(attribute.argument);
553
+ const key = attribute.name.type === AST_NODE_TYPES12.JSXIdentifier ? attribute.name.name : "";
554
+ if (isEventHandler(key)) return true;
555
+ const { value } = attribute;
556
+ if (value?.type !== AST_NODE_TYPES12.JSXExpressionContainer) return false;
557
+ if (isTag) return isFunctionAttribute(key) && !isData(value.expression);
558
+ return key !== "className" && isClientValue(value.expression);
559
+ });
560
+ }
561
+ case AST_NODE_TYPES12.JSXExpressionContainer:
562
+ return node.parent.type === AST_NODE_TYPES12.JSXElement && positionOf(node.parent.openingElement) === "prop" && isClientValue(node.expression);
563
+ default:
564
+ return false;
565
+ }
566
+ };
567
+ const walk = (node) => needsNode(node) || childNodes(node, sourceCode.visitorKeys).some(walk);
568
+ return walk;
569
+ };
570
+
571
+ // needsClient.ts
572
+ var { DefinitionType: DefinitionType5 } = TSESLint5.Scope;
573
+ var STYLESHEET = /\.(?:css|scss|sass|less)$/u;
574
+ var CLIENT_MODULES = /* @__PURE__ */ new Set(["next/dynamic", "client-only"]);
424
575
  var PURE_CALLS = /* @__PURE__ */ new Set(["cva", "tv"]);
425
576
  var INERT_TYPES = /* @__PURE__ */ new Set([
426
- AST_NODE_TYPES12.Literal,
427
- AST_NODE_TYPES12.TemplateLiteral,
428
- AST_NODE_TYPES12.TemplateElement,
429
- AST_NODE_TYPES12.Identifier,
430
- AST_NODE_TYPES12.UnaryExpression,
431
- AST_NODE_TYPES12.BinaryExpression,
432
- AST_NODE_TYPES12.LogicalExpression,
433
- AST_NODE_TYPES12.ConditionalExpression,
434
- AST_NODE_TYPES12.ArrayExpression,
435
- AST_NODE_TYPES12.ObjectExpression,
436
- AST_NODE_TYPES12.Property,
437
- AST_NODE_TYPES12.SpreadElement,
438
- AST_NODE_TYPES12.RestElement,
439
- AST_NODE_TYPES12.ObjectPattern,
440
- AST_NODE_TYPES12.ArrayPattern,
441
- AST_NODE_TYPES12.AssignmentPattern,
442
- AST_NODE_TYPES12.JSXElement,
443
- AST_NODE_TYPES12.JSXFragment,
444
- AST_NODE_TYPES12.JSXOpeningElement,
445
- AST_NODE_TYPES12.JSXClosingElement,
446
- AST_NODE_TYPES12.JSXOpeningFragment,
447
- AST_NODE_TYPES12.JSXClosingFragment,
448
- AST_NODE_TYPES12.JSXAttribute,
449
- AST_NODE_TYPES12.JSXSpreadAttribute,
450
- AST_NODE_TYPES12.JSXExpressionContainer,
451
- AST_NODE_TYPES12.JSXEmptyExpression,
452
- AST_NODE_TYPES12.JSXText,
453
- AST_NODE_TYPES12.JSXIdentifier,
454
- AST_NODE_TYPES12.JSXNamespacedName,
455
- AST_NODE_TYPES12.TSAsExpression,
456
- AST_NODE_TYPES12.TSSatisfiesExpression,
457
- AST_NODE_TYPES12.TSNonNullExpression
577
+ AST_NODE_TYPES13.Literal,
578
+ AST_NODE_TYPES13.TemplateLiteral,
579
+ AST_NODE_TYPES13.TemplateElement,
580
+ AST_NODE_TYPES13.Identifier,
581
+ AST_NODE_TYPES13.UnaryExpression,
582
+ AST_NODE_TYPES13.BinaryExpression,
583
+ AST_NODE_TYPES13.LogicalExpression,
584
+ AST_NODE_TYPES13.ConditionalExpression,
585
+ AST_NODE_TYPES13.ArrayExpression,
586
+ AST_NODE_TYPES13.ObjectExpression,
587
+ AST_NODE_TYPES13.Property,
588
+ AST_NODE_TYPES13.SpreadElement,
589
+ AST_NODE_TYPES13.RestElement,
590
+ AST_NODE_TYPES13.ObjectPattern,
591
+ AST_NODE_TYPES13.ArrayPattern,
592
+ AST_NODE_TYPES13.AssignmentPattern,
593
+ AST_NODE_TYPES13.JSXElement,
594
+ AST_NODE_TYPES13.JSXFragment,
595
+ AST_NODE_TYPES13.JSXOpeningElement,
596
+ AST_NODE_TYPES13.JSXClosingElement,
597
+ AST_NODE_TYPES13.JSXOpeningFragment,
598
+ AST_NODE_TYPES13.JSXClosingFragment,
599
+ AST_NODE_TYPES13.JSXAttribute,
600
+ AST_NODE_TYPES13.JSXSpreadAttribute,
601
+ AST_NODE_TYPES13.JSXExpressionContainer,
602
+ AST_NODE_TYPES13.JSXEmptyExpression,
603
+ AST_NODE_TYPES13.JSXText,
604
+ AST_NODE_TYPES13.JSXIdentifier,
605
+ AST_NODE_TYPES13.JSXNamespacedName,
606
+ AST_NODE_TYPES13.TSAsExpression,
607
+ AST_NODE_TYPES13.TSSatisfiesExpression,
608
+ AST_NODE_TYPES13.TSNonNullExpression
458
609
  ]);
459
610
  var TYPE_DECLARATIONS = /* @__PURE__ */ new Set([
460
- AST_NODE_TYPES12.TSInterfaceDeclaration,
461
- AST_NODE_TYPES12.TSTypeAliasDeclaration,
462
- AST_NODE_TYPES12.TSDeclareFunction
463
- ]);
464
- var BROWSER_GLOBALS = /* @__PURE__ */ new Set([
465
- ...Object.keys(globals.browser).filter(
466
- (name) => !Object.hasOwn(globals.node, name) && !Object.hasOwn(globals.builtin, name)
467
- ),
468
- "navigator",
469
- "localStorage",
470
- "sessionStorage"
611
+ AST_NODE_TYPES13.TSInterfaceDeclaration,
612
+ AST_NODE_TYPES13.TSTypeAliasDeclaration,
613
+ AST_NODE_TYPES13.TSDeclareFunction
471
614
  ]);
472
615
  var isValueReference = (reference) => reference.isValueReference !== false;
473
616
  var verdicts = /* @__PURE__ */ new WeakMap();
474
617
  var analyze = (sourceCode) => {
475
- const { classify: classify2, classifyTag, positionOf, variableOf } = createClassifier(sourceCode, false);
476
- const isData = (node) => classify2(node, "prop").data;
618
+ const classifier = createClassifier(sourceCode, false);
619
+ const { variableOf } = classifier;
620
+ const walk = createClientWalk(sourceCode, classifier);
477
621
  const isComponentBinding = (identifier) => {
478
622
  const variable = variableOf(identifier, identifier.name);
479
623
  const isNamedLikeComponent = isComponentName(variable?.name);
480
624
  return everyDef(
481
625
  variable,
482
- (def) => def.type === DefinitionType4.Type || isNamedLikeComponent && (def.type === DefinitionType4.FunctionName || def.type === DefinitionType4.Variable && isComponentInit(def.node.init))
626
+ (def) => def.type === DefinitionType5.Type || isNamedLikeComponent && (def.type === DefinitionType5.FunctionName || def.type === DefinitionType5.Variable && isComponentInit(def.node.init))
483
627
  );
484
628
  };
485
629
  const isLocalRead = (node) => {
486
630
  let root = node;
487
- while (root.type === AST_NODE_TYPES12.MemberExpression) {
631
+ while (root.type === AST_NODE_TYPES13.MemberExpression) {
488
632
  if (root.computed && !isInert(root.property)) return false;
489
633
  root = root.object;
490
634
  }
491
- const variable = root.type === AST_NODE_TYPES12.Identifier ? variableOf(root, root.name) : null;
492
- return everyDef(variable, (def) => def.type === DefinitionType4.Variable);
635
+ const variable = root.type === AST_NODE_TYPES13.Identifier ? variableOf(root, root.name) : null;
636
+ return everyDef(variable, (def) => def.type === DefinitionType5.Variable);
493
637
  };
494
- const isPlainCallee = (callee) => callee.type === AST_NODE_TYPES12.Identifier || callee.type === AST_NODE_TYPES12.MemberExpression && !callee.computed && isPlainCallee(callee.object);
638
+ const isPlainCallee = (callee) => callee.type === AST_NODE_TYPES13.Identifier || callee.type === AST_NODE_TYPES13.MemberExpression && !callee.computed && isPlainCallee(callee.object);
495
639
  const isInert = (node) => {
496
640
  if (isFunctionNode(node)) return true;
497
- if (node.type === AST_NODE_TYPES12.UnaryExpression && node.operator === "delete") return false;
498
- if (node.type === AST_NODE_TYPES12.MemberExpression) return isLocalRead(node);
499
- if (node.type === AST_NODE_TYPES12.CallExpression)
641
+ if (node.type === AST_NODE_TYPES13.UnaryExpression && node.operator === "delete") return false;
642
+ if (node.type === AST_NODE_TYPES13.MemberExpression) return isLocalRead(node);
643
+ if (node.type === AST_NODE_TYPES13.CallExpression)
500
644
  return isPlainCallee(node.callee) && (PURE_CALLS.has(calleeName(node.callee)) || isComponentWrapperCall(node)) && node.arguments.every(isInert);
501
645
  return INERT_TYPES.has(node.type) && childNodes(node, sourceCode.visitorKeys).every(isInert);
502
646
  };
503
647
  const exportsOnlyComponents = (declaration) => {
504
648
  if (TYPE_DECLARATIONS.has(declaration.type)) return true;
505
- if (declaration.type === AST_NODE_TYPES12.FunctionDeclaration)
649
+ if (declaration.type === AST_NODE_TYPES13.FunctionDeclaration)
506
650
  return isComponentName(declaration.id?.name);
507
- if (declaration.type !== AST_NODE_TYPES12.VariableDeclaration) return false;
651
+ if (declaration.type !== AST_NODE_TYPES13.VariableDeclaration) return false;
508
652
  return declaration.declarations.every(
509
- (declarator) => declarator.id.type === AST_NODE_TYPES12.Identifier && isComponentName(declarator.id.name) && declarator.init !== null && isComponentInit(declarator.init) && isInert(declarator.init)
653
+ (declarator) => declarator.id.type === AST_NODE_TYPES13.Identifier && isComponentName(declarator.id.name) && declarator.init !== null && isComponentInit(declarator.init) && isInert(declarator.init)
510
654
  );
511
655
  };
512
656
  const isServerSafeStatement = (statement) => {
513
657
  switch (statement.type) {
514
- case AST_NODE_TYPES12.ExpressionStatement:
658
+ case AST_NODE_TYPES13.ExpressionStatement:
515
659
  return statement.directive !== void 0;
516
- case AST_NODE_TYPES12.ImportDeclaration:
660
+ case AST_NODE_TYPES13.ImportDeclaration:
517
661
  if (statement.importKind === "type") return true;
518
662
  if (statement.specifiers.length === 0) return STYLESHEET.test(statement.source.value);
519
663
  return !CLIENT_MODULES.has(statement.source.value);
520
- case AST_NODE_TYPES12.FunctionDeclaration:
664
+ case AST_NODE_TYPES13.FunctionDeclaration:
521
665
  return true;
522
- case AST_NODE_TYPES12.TSEnumDeclaration:
666
+ case AST_NODE_TYPES13.TSEnumDeclaration:
523
667
  return statement.body.members.every(
524
668
  (member) => !member.initializer || isInert(member.initializer)
525
669
  );
526
- case AST_NODE_TYPES12.VariableDeclaration:
670
+ case AST_NODE_TYPES13.VariableDeclaration:
527
671
  return statement.declarations.every(
528
672
  (declarator) => isInert(declarator.id) && (!declarator.init || isInert(declarator.init))
529
673
  );
530
- case AST_NODE_TYPES12.ExportAllDeclaration:
674
+ case AST_NODE_TYPES13.ExportAllDeclaration:
531
675
  return statement.exportKind === "type";
532
- case AST_NODE_TYPES12.ExportNamedDeclaration: {
676
+ case AST_NODE_TYPES13.ExportNamedDeclaration: {
533
677
  if (statement.exportKind === "type") return true;
534
678
  const isTypeOnly = statement.specifiers.length > 0 && statement.specifiers.every((specifier) => specifier.exportKind === "type");
535
679
  if (statement.source) return isTypeOnly;
536
680
  if (statement.declaration) return exportsOnlyComponents(statement.declaration);
537
681
  return statement.specifiers.every(
538
- (specifier) => specifier.exportKind === "type" || specifier.local.type === AST_NODE_TYPES12.Identifier && isComponentBinding(specifier.local)
682
+ (specifier) => specifier.exportKind === "type" || specifier.local.type === AST_NODE_TYPES13.Identifier && isComponentBinding(specifier.local)
539
683
  );
540
684
  }
541
- case AST_NODE_TYPES12.ExportDefaultDeclaration: {
685
+ case AST_NODE_TYPES13.ExportDefaultDeclaration: {
542
686
  const { declaration } = statement;
543
- if (declaration.type === AST_NODE_TYPES12.FunctionDeclaration)
687
+ if (declaration.type === AST_NODE_TYPES13.FunctionDeclaration)
544
688
  return isComponentName(declaration.id?.name);
545
- if (declaration.type === AST_NODE_TYPES12.Identifier) return isComponentBinding(declaration);
689
+ if (declaration.type === AST_NODE_TYPES13.Identifier) return isComponentBinding(declaration);
546
690
  return isComponentWrapperCall(declaration) && isComponentInit(declaration) && isInert(declaration);
547
691
  }
548
692
  default:
549
693
  return TYPE_DECLARATIONS.has(statement.type);
550
694
  }
551
695
  };
552
- const callNames = (callee) => {
553
- if (callee.type !== AST_NODE_TYPES12.Identifier) return [calleeName(callee)];
554
- return [callee.name, importedName(variableOf(callee, callee.name))];
555
- };
556
- const needsNode = (node) => {
557
- switch (node.type) {
558
- case AST_NODE_TYPES12.CallExpression:
559
- return callNames(node.callee).some((name) => HOOK.test(name) || CLIENT_CALLS.has(name));
560
- case AST_NODE_TYPES12.ClassDeclaration:
561
- case AST_NODE_TYPES12.ClassExpression:
562
- return !!node.superClass && CLASS_BASES.has(calleeName(node.superClass));
563
- case AST_NODE_TYPES12.MemberExpression:
564
- return node.object.type === AST_NODE_TYPES12.Identifier && node.object.name === "globalThis" && !node.computed && node.property.type === AST_NODE_TYPES12.Identifier && BROWSER_GLOBALS.has(node.property.name) && !variableOf(node.object, "globalThis")?.defs.length;
565
- case AST_NODE_TYPES12.JSXOpeningElement: {
566
- if (!classifyTag(node).data) return true;
567
- const isTag = positionOf(node) === "text";
568
- return node.attributes.some((attribute) => {
569
- if (attribute.type === AST_NODE_TYPES12.JSXSpreadAttribute) return !isData(attribute.argument);
570
- const key = attribute.name.type === AST_NODE_TYPES12.JSXIdentifier ? attribute.name.name : "";
571
- if (isEventHandler(key)) return true;
572
- const { value } = attribute;
573
- if (value?.type !== AST_NODE_TYPES12.JSXExpressionContainer) return false;
574
- return (isTag ? isFunctionAttribute(key) : key !== "className") && !isData(value.expression);
575
- });
576
- }
577
- case AST_NODE_TYPES12.JSXExpressionContainer:
578
- return node.parent.type === AST_NODE_TYPES12.JSXElement && positionOf(node.parent.openingElement) === "prop" && !isData(node.expression);
579
- default:
580
- return false;
581
- }
582
- };
583
- const walk = (node) => needsNode(node) || childNodes(node, sourceCode.visitorKeys).some(walk);
584
696
  if (!sourceCode.ast.body.every(isServerSafeStatement) || walk(sourceCode.ast)) return true;
585
697
  const scope = sourceCode.getScope(sourceCode.ast);
586
698
  return scope.through.some(
@@ -623,10 +735,10 @@ var needlessUseClient = ESLintUtils.RuleCreator.withoutDocs({
623
735
  });
624
736
 
625
737
  // noComments.ts
626
- import { AST_NODE_TYPES as AST_NODE_TYPES14, AST_TOKEN_TYPES as AST_TOKEN_TYPES2, ESLintUtils as ESLintUtils2 } from "@typescript-eslint/utils";
738
+ import { AST_NODE_TYPES as AST_NODE_TYPES15, AST_TOKEN_TYPES as AST_TOKEN_TYPES2, ESLintUtils as ESLintUtils2 } from "@typescript-eslint/utils";
627
739
 
628
740
  // commentKinds.ts
629
- import { AST_NODE_TYPES as AST_NODE_TYPES13, AST_TOKEN_TYPES } from "@typescript-eslint/utils";
741
+ import { AST_NODE_TYPES as AST_NODE_TYPES14, AST_TOKEN_TYPES } from "@typescript-eslint/utils";
630
742
  var DIRECTIVE = /^\s*(?:eslint-disable\b|eslint-enable\b|\/\s*<|prettier-ignore|biome-ignore|(?:istanbul|c8|v8)\s+ignore\b|(?:webpack|turbopack)[A-Z]|@vitest-environment\b)/u;
631
743
  var ALLOW_MARKER = /\bgitleaks:allow\b/u;
632
744
  var BLOCK_DIRECTIVE = /^\s*(?:eslint\s|eslint-env\b|global\s|globals\s|exported\s)/u;
@@ -698,7 +810,7 @@ var createCommentLookup = (sourceCode) => {
698
810
  const enclosingNode = (comment) => nodeAt(comment.range[0]);
699
811
  const jsxContainer = (comment) => {
700
812
  const node = enclosingNode(comment);
701
- return node?.type === AST_NODE_TYPES13.JSXEmptyExpression ? node.parent : null;
813
+ return node?.type === AST_NODE_TYPES14.JSXEmptyExpression ? node.parent : null;
702
814
  };
703
815
  const sidesOf = (span) => {
704
816
  const { lines } = sourceCode;
@@ -724,16 +836,16 @@ var createCommentLookup = (sourceCode) => {
724
836
  // noComments.ts
725
837
  var JS_FILE = /\.[cm]?jsx?$/u;
726
838
  var EM_DASH = String.fromCodePoint(8212);
727
- var isJsxNode = (node) => !!node && node.type.startsWith("JSX") && node.type !== AST_NODE_TYPES14.JSXExpressionContainer;
839
+ var isJsxNode = (node) => !!node && node.type.startsWith("JSX") && node.type !== AST_NODE_TYPES15.JSXExpressionContainer;
728
840
  var FUNCTION_NODES = /* @__PURE__ */ new Set([
729
- AST_NODE_TYPES14.FunctionDeclaration,
730
- AST_NODE_TYPES14.FunctionExpression,
731
- AST_NODE_TYPES14.ArrowFunctionExpression
841
+ AST_NODE_TYPES15.FunctionDeclaration,
842
+ AST_NODE_TYPES15.FunctionExpression,
843
+ AST_NODE_TYPES15.ArrowFunctionExpression
732
844
  ]);
733
845
  var isEmptyBlock = (node) => {
734
- if (node?.type === AST_NODE_TYPES14.SwitchStatement) return node.cases.length === 0;
735
- if (node?.type === AST_NODE_TYPES14.StaticBlock) return node.body.length === 0;
736
- return node?.type === AST_NODE_TYPES14.BlockStatement && node.body.length === 0 && !FUNCTION_NODES.has(node.parent.type);
846
+ if (node?.type === AST_NODE_TYPES15.SwitchStatement) return node.cases.length === 0;
847
+ if (node?.type === AST_NODE_TYPES15.StaticBlock) return node.body.length === 0;
848
+ return node?.type === AST_NODE_TYPES15.BlockStatement && node.body.length === 0 && !FUNCTION_NODES.has(node.parent.type);
737
849
  };
738
850
  var classify = (comment, lookup) => {
739
851
  const node = lookup.enclosingNode(comment);
@@ -742,7 +854,7 @@ var classify = (comment, lookup) => {
742
854
  return inJsx ? "jsxDirective" : "directive";
743
855
  }
744
856
  if (isBanner(comment)) return "banner";
745
- if (inJsx) return node?.type === AST_NODE_TYPES14.JSXEmptyExpression ? "jsx" : "attribute";
857
+ if (inJsx) return node?.type === AST_NODE_TYPES15.JSXEmptyExpression ? "jsx" : "attribute";
746
858
  if (isDocShaped(comment)) return "jsdoc";
747
859
  return comment.type === AST_TOKEN_TYPES2.Line ? "line" : "block";
748
860
  };
@@ -853,37 +965,143 @@ var noComments = ESLintUtils2.RuleCreator.withoutDocs({
853
965
  }
854
966
  });
855
967
 
968
+ // oneComponentPerClientFile.ts
969
+ import { AST_NODE_TYPES as AST_NODE_TYPES16, ESLintUtils as ESLintUtils3 } from "@typescript-eslint/utils";
970
+ var unwrap = (node) => {
971
+ if (!node) return null;
972
+ if (!isComponentWrapper(node)) return node;
973
+ if (node.type === AST_NODE_TYPES16.CallExpression) return unwrap(node.arguments[0]);
974
+ if (node.type === AST_NODE_TYPES16.TSAsExpression || node.type === AST_NODE_TYPES16.TSSatisfiesExpression)
975
+ return unwrap(node.expression);
976
+ return node;
977
+ };
978
+ var functionOf = (init) => {
979
+ const node = unwrap(init);
980
+ return node?.type === AST_NODE_TYPES16.ArrowFunctionExpression || node?.type === AST_NODE_TYPES16.FunctionExpression ? node : null;
981
+ };
982
+ var declarationCandidates = (declaration, isExported) => {
983
+ if (declaration.type === AST_NODE_TYPES16.FunctionDeclaration)
984
+ return [{ node: declaration, fn: declaration, name: declaration.id?.name ?? "default", isExported }];
985
+ if (declaration.type !== AST_NODE_TYPES16.VariableDeclaration) return [];
986
+ return declaration.declarations.flatMap((declarator) => {
987
+ const fn = functionOf(declarator.init);
988
+ if (!fn || declarator.id.type !== AST_NODE_TYPES16.Identifier) return [];
989
+ return [{ node: declarator, fn, name: declarator.id.name, isExported }];
990
+ });
991
+ };
992
+ var statementCandidates = (statement) => {
993
+ if (statement.type === AST_NODE_TYPES16.ExportNamedDeclaration)
994
+ return statement.declaration ? declarationCandidates(statement.declaration, true) : [];
995
+ if (statement.type !== AST_NODE_TYPES16.ExportDefaultDeclaration)
996
+ return declarationCandidates(statement, false);
997
+ const { declaration } = statement;
998
+ if (declaration.type === AST_NODE_TYPES16.FunctionDeclaration)
999
+ return declarationCandidates(declaration, true);
1000
+ const fn = functionOf(declaration);
1001
+ return fn ? [{ node: statement, fn, name: "default", isExported: true }] : [];
1002
+ };
1003
+ var exportedLocalNames = (statement) => {
1004
+ if (statement.type === AST_NODE_TYPES16.ExportNamedDeclaration && statement.exportKind === "type")
1005
+ return [];
1006
+ if (statement.type === AST_NODE_TYPES16.ExportNamedDeclaration && !statement.source)
1007
+ return statement.specifiers.flatMap(
1008
+ (specifier) => specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES16.Identifier ? [specifier.local.name] : []
1009
+ );
1010
+ if (statement.type !== AST_NODE_TYPES16.ExportDefaultDeclaration) return [];
1011
+ const target = unwrap(statement.declaration);
1012
+ return target?.type === AST_NODE_TYPES16.Identifier ? [target.name] : [];
1013
+ };
1014
+ var oneComponentPerClientFile = ESLintUtils3.RuleCreator.withoutDocs({
1015
+ meta: {
1016
+ type: "suggestion",
1017
+ docs: {
1018
+ description: "Disallow a module-level function beside the one exported component of a client module, unless its own body needs the browser."
1019
+ },
1020
+ schema: [],
1021
+ messages: {
1022
+ extra: "This client file exports `{{component}}`; `{{name}}` is a second function that needs no browser of its own. Move it to its own module (a pure function under utils/, a hook under lib/), or render static markup in the server parent and pass it in as children."
1023
+ }
1024
+ },
1025
+ defaultOptions: [],
1026
+ create(context) {
1027
+ const { sourceCode } = context;
1028
+ return {
1029
+ Program(program) {
1030
+ if (!findUseClientDirective(program)) return;
1031
+ const exportedNames = new Set(program.body.flatMap(exportedLocalNames));
1032
+ const candidates = program.body.flatMap(statementCandidates).map((candidate) => ({
1033
+ ...candidate,
1034
+ isExported: candidate.isExported || exportedNames.has(candidate.name)
1035
+ }));
1036
+ const component = candidates.find(
1037
+ (candidate) => candidate.isExported && isComponentFunction(candidate.fn)
1038
+ );
1039
+ if (!component) return;
1040
+ const classifier = createClassifier(sourceCode, false);
1041
+ const { positionOf, variableOf } = classifier;
1042
+ const walk = createClientWalk(sourceCode, classifier, true);
1043
+ const isHookCallee = (callee) => isHookName(calleeName(callee)) || callee.type === AST_NODE_TYPES16.Identifier && isHookName(importedName(variableOf(callee, callee.name)));
1044
+ const isHandedToClient = ({ identifier }) => {
1045
+ const { parent } = identifier;
1046
+ if (parent.type === AST_NODE_TYPES16.CallExpression)
1047
+ return parent.arguments.some((argument) => argument === identifier) && isHookCallee(parent.callee);
1048
+ if (parent.type !== AST_NODE_TYPES16.JSXExpressionContainer || parent.parent.type !== AST_NODE_TYPES16.JSXAttribute)
1049
+ return false;
1050
+ const attribute = parent.parent;
1051
+ const key = attribute.name.type === AST_NODE_TYPES16.JSXIdentifier ? attribute.name.name : "";
1052
+ return isEventHandler(key) || positionOf(attribute.parent) === "text" && isFunctionAttribute(key);
1053
+ };
1054
+ const isUsedByClient = (candidate) => sourceCode.getDeclaredVariables(candidate.node).some(
1055
+ (variable) => variable.name === candidate.name && variable.references.some(isHandedToClient)
1056
+ );
1057
+ const readsBrowserGlobal = (fn) => sourceCode.getScope(fn).through.some(
1058
+ (reference) => reference.isValueReference !== false && BROWSER_GLOBALS.has(reference.identifier.name) && !reference.resolved?.defs.length
1059
+ );
1060
+ for (const candidate of candidates) {
1061
+ if (candidate === component || walk(candidate.fn) || readsBrowserGlobal(candidate.fn) || isUsedByClient(candidate))
1062
+ continue;
1063
+ context.report({
1064
+ node: candidate.node,
1065
+ messageId: "extra",
1066
+ data: { component: component.name, name: candidate.name }
1067
+ });
1068
+ }
1069
+ }
1070
+ };
1071
+ }
1072
+ });
1073
+
856
1074
  // oneExportPerFile.ts
857
- import { AST_NODE_TYPES as AST_NODE_TYPES15, ESLintUtils as ESLintUtils3 } from "@typescript-eslint/utils";
858
- var isTypeOnlyDeclaration = (declaration) => declaration?.type === AST_NODE_TYPES15.TSInterfaceDeclaration || declaration?.type === AST_NODE_TYPES15.TSTypeAliasDeclaration || declaration?.type === AST_NODE_TYPES15.TSDeclareFunction;
1075
+ import { AST_NODE_TYPES as AST_NODE_TYPES17, ESLintUtils as ESLintUtils4 } from "@typescript-eslint/utils";
1076
+ var isTypeOnlyDeclaration = (declaration) => declaration?.type === AST_NODE_TYPES17.TSInterfaceDeclaration || declaration?.type === AST_NODE_TYPES17.TSTypeAliasDeclaration || declaration?.type === AST_NODE_TYPES17.TSDeclareFunction;
859
1077
  var declaratorEntries = (declaration) => declaration.declarations.map((declarator) => ({
860
1078
  node: declarator,
861
- name: declarator.id.type === AST_NODE_TYPES15.Identifier ? declarator.id.name : "a destructured export"
1079
+ name: declarator.id.type === AST_NODE_TYPES17.Identifier ? declarator.id.name : "a destructured export"
862
1080
  }));
863
1081
  var declarationEntry = (declaration) => ({
864
1082
  node: declaration,
865
- name: "id" in declaration && declaration.id?.type === AST_NODE_TYPES15.Identifier ? declaration.id.name : "default"
1083
+ name: "id" in declaration && declaration.id?.type === AST_NODE_TYPES17.Identifier ? declaration.id.name : "default"
866
1084
  });
867
1085
  var namedEntries = (node) => {
868
1086
  if (node.exportKind === "type") return [];
869
1087
  const { declaration, specifiers } = node;
870
1088
  if (declaration) {
871
1089
  if (isTypeOnlyDeclaration(declaration)) return [];
872
- if (declaration.type === AST_NODE_TYPES15.VariableDeclaration) return declaratorEntries(declaration);
1090
+ if (declaration.type === AST_NODE_TYPES17.VariableDeclaration) return declaratorEntries(declaration);
873
1091
  return [declarationEntry(declaration)];
874
1092
  }
875
1093
  return specifiers.filter((specifier) => specifier.exportKind !== "type").map((specifier) => ({
876
1094
  node: specifier,
877
- name: specifier.exported.type === AST_NODE_TYPES15.Identifier ? specifier.exported.name : specifier.exported.value
1095
+ name: specifier.exported.type === AST_NODE_TYPES17.Identifier ? specifier.exported.name : specifier.exported.value
878
1096
  }));
879
1097
  };
880
1098
  var exportEntries = (statement) => {
881
- if (statement.type === AST_NODE_TYPES15.ExportNamedDeclaration) return namedEntries(statement);
882
- if (statement.type === AST_NODE_TYPES15.ExportDefaultDeclaration)
883
- return statement.declaration.type === AST_NODE_TYPES15.TSDeclareFunction ? [] : [{ node: statement, name: "default" }];
1099
+ if (statement.type === AST_NODE_TYPES17.ExportNamedDeclaration) return namedEntries(statement);
1100
+ if (statement.type === AST_NODE_TYPES17.ExportDefaultDeclaration)
1101
+ return statement.declaration.type === AST_NODE_TYPES17.TSDeclareFunction ? [] : [{ node: statement, name: "default" }];
884
1102
  return [];
885
1103
  };
886
- var oneExportPerFile = ESLintUtils3.RuleCreator.withoutDocs({
1104
+ var oneExportPerFile = ESLintUtils4.RuleCreator.withoutDocs({
887
1105
  meta: {
888
1106
  type: "suggestion",
889
1107
  docs: {
@@ -912,7 +1130,7 @@ var oneExportPerFile = ESLintUtils3.RuleCreator.withoutDocs({
912
1130
  });
913
1131
 
914
1132
  // oneLineComments.ts
915
- import { AST_TOKEN_TYPES as AST_TOKEN_TYPES3, ESLintUtils as ESLintUtils4 } from "@typescript-eslint/utils";
1133
+ import { AST_TOKEN_TYPES as AST_TOKEN_TYPES3, ESLintUtils as ESLintUtils5 } from "@typescript-eslint/utils";
916
1134
  var isBare = (comment) => comment.type === AST_TOKEN_TYPES3.Line && comment.value.trim() === "";
917
1135
  var collapse = (text) => text.replace(/\s+/gu, " ").trim();
918
1136
  var asLine = (body) => body ? `// ${body}` : null;
@@ -948,7 +1166,7 @@ var isJsDoc = (comment, after) => {
948
1166
  if (!isComment(after)) return true;
949
1167
  return isDirective(after) || isDocShaped(after) && /^\*+\s*@/u.test(comment.value);
950
1168
  };
951
- var oneLineComments = ESLintUtils4.RuleCreator.withoutDocs({
1169
+ var oneLineComments = ESLintUtils5.RuleCreator.withoutDocs({
952
1170
  meta: {
953
1171
  type: "layout",
954
1172
  docs: {
@@ -1051,15 +1269,15 @@ var oneLineComments = ESLintUtils4.RuleCreator.withoutDocs({
1051
1269
  });
1052
1270
 
1053
1271
  // staticJsxInClient.ts
1054
- import { AST_NODE_TYPES as AST_NODE_TYPES16, AST_TOKEN_TYPES as AST_TOKEN_TYPES4, ESLintUtils as ESLintUtils5 } from "@typescript-eslint/utils";
1272
+ import { AST_NODE_TYPES as AST_NODE_TYPES18, AST_TOKEN_TYPES as AST_TOKEN_TYPES4, ESLintUtils as ESLintUtils6 } from "@typescript-eslint/utils";
1055
1273
  var DISABLE_KEYWORDS = ["eslint-disable-next-line", "eslint-disable-line", "eslint-disable"];
1056
- var isJsx = (node) => node.type === AST_NODE_TYPES16.JSXElement || node.type === AST_NODE_TYPES16.JSXFragment;
1274
+ var isJsx = (node) => node.type === AST_NODE_TYPES18.JSXElement || node.type === AST_NODE_TYPES18.JSXFragment;
1057
1275
  var isRenderedByComponent = (node) => {
1058
1276
  let current = node.parent;
1059
1277
  while (current && !isFunctionNode(current)) current = current.parent;
1060
1278
  return !current || isComponentFunction(current);
1061
1279
  };
1062
- var staticJsxInClient = ESLintUtils5.RuleCreator.withoutDocs({
1280
+ var staticJsxInClient = ESLintUtils6.RuleCreator.withoutDocs({
1063
1281
  meta: {
1064
1282
  type: "suggestion",
1065
1283
  docs: {
@@ -1102,14 +1320,14 @@ var staticJsxInClient = ESLintUtils5.RuleCreator.withoutDocs({
1102
1320
  return verdict.data && verdict.stable;
1103
1321
  };
1104
1322
  const isStaticAttribute = (attribute, position) => {
1105
- if (attribute.type !== AST_NODE_TYPES16.JSXAttribute) return false;
1106
- const key = attribute.name.type === AST_NODE_TYPES16.JSXIdentifier ? attribute.name.name : "";
1323
+ if (attribute.type !== AST_NODE_TYPES18.JSXAttribute) return false;
1324
+ const key = attribute.name.type === AST_NODE_TYPES18.JSXIdentifier ? attribute.name.name : "";
1107
1325
  if (isFunctionAttribute(key)) return false;
1108
1326
  const { value } = attribute;
1109
- if (!value || value.type === AST_NODE_TYPES16.Literal) return true;
1110
- return value.type === AST_NODE_TYPES16.JSXExpressionContainer && isStatic(value.expression, position);
1327
+ if (!value || value.type === AST_NODE_TYPES18.Literal) return true;
1328
+ return value.type === AST_NODE_TYPES18.JSXExpressionContainer && isStatic(value.expression, position);
1111
1329
  };
1112
- const childPosition = (node) => node.type === AST_NODE_TYPES16.JSXElement ? positionOf(node.openingElement) : "text";
1330
+ const childPosition = (node) => node.type === AST_NODE_TYPES18.JSXElement ? positionOf(node.openingElement) : "text";
1113
1331
  const verdicts2 = /* @__PURE__ */ new Map();
1114
1332
  const judge = (node) => {
1115
1333
  const cached = verdicts2.get(node);
@@ -1117,7 +1335,7 @@ var staticJsxInClient = ESLintUtils5.RuleCreator.withoutDocs({
1117
1335
  const position = childPosition(node);
1118
1336
  let isStaticNode = true;
1119
1337
  let count = 0;
1120
- if (node.type === AST_NODE_TYPES16.JSXElement) {
1338
+ if (node.type === AST_NODE_TYPES18.JSXElement) {
1121
1339
  const { openingElement } = node;
1122
1340
  const tag = classifyTag(openingElement);
1123
1341
  isStaticNode = tag.data && tag.stable && openingElement.attributes.every((attribute) => isStaticAttribute(attribute, position));
@@ -1128,9 +1346,9 @@ var staticJsxInClient = ESLintUtils5.RuleCreator.withoutDocs({
1128
1346
  const verdict2 = judge(child);
1129
1347
  isStaticNode &&= verdict2.isStatic;
1130
1348
  count += verdict2.count;
1131
- } else if (child.type === AST_NODE_TYPES16.JSXExpressionContainer)
1349
+ } else if (child.type === AST_NODE_TYPES18.JSXExpressionContainer)
1132
1350
  isStaticNode &&= isStatic(child.expression, position);
1133
- else if (child.type !== AST_NODE_TYPES16.JSXText) isStaticNode = false;
1351
+ else if (child.type !== AST_NODE_TYPES18.JSXText) isStaticNode = false;
1134
1352
  }
1135
1353
  const verdict = { isStatic: isStaticNode, count };
1136
1354
  verdicts2.set(node, verdict);
@@ -1159,9 +1377,9 @@ var staticJsxInClient = ESLintUtils5.RuleCreator.withoutDocs({
1159
1377
  else if (isJsx(child)) {
1160
1378
  flush();
1161
1379
  visit(child);
1162
- } else if (child.type === AST_NODE_TYPES16.JSXExpressionContainer && !isStatic(child.expression, position))
1380
+ } else if (child.type === AST_NODE_TYPES18.JSXExpressionContainer && !isStatic(child.expression, position))
1163
1381
  flush();
1164
- else if (child.type === AST_NODE_TYPES16.JSXSpreadChild) flush();
1382
+ else if (child.type === AST_NODE_TYPES18.JSXSpreadChild) flush();
1165
1383
  }
1166
1384
  flush();
1167
1385
  };
@@ -1180,7 +1398,8 @@ var plugin = {
1180
1398
  "no-comments": noComments,
1181
1399
  "no-needless-use-client": needlessUseClient,
1182
1400
  "no-static-jsx-in-client": staticJsxInClient,
1183
- "one-export-per-file": oneExportPerFile
1401
+ "one-export-per-file": oneExportPerFile,
1402
+ "one-component-per-client-file": oneComponentPerClientFile
1184
1403
  }
1185
1404
  };
1186
1405
  var soujvnunesPlugin = plugin;
@@ -1380,6 +1599,7 @@ var buildConfig = ({
1380
1599
  tsconfigRootDir = process.cwd(),
1381
1600
  tailwindEntryPoint,
1382
1601
  allowArbitraryClasses = [],
1602
+ design = false,
1383
1603
  classMergeName = "cn",
1384
1604
  nextConfigModules = [],
1385
1605
  strictExportGlobs = [],
@@ -1418,6 +1638,8 @@ var buildConfig = ({
1418
1638
  settings["import-x/resolver-next"] = [createTypeScriptImportResolver({ alwaysTryTypes: true })];
1419
1639
  settings["jsx-a11y"] = { components: JSX_A11Y_COMPONENTS };
1420
1640
  if (tailwindEntryPoint) {
1641
+ const allowDark = typeof design === "object" && design.dark === true;
1642
+ const designRestrictions = design ? designClassRestrictions({ dark: allowDark }) : [];
1421
1643
  plugins["better-tailwindcss"] = betterTailwind;
1422
1644
  Object.assign(rules, {
1423
1645
  "better-tailwindcss/no-unknown-classes": "error",
@@ -1430,7 +1652,8 @@ var buildConfig = ({
1430
1652
  {
1431
1653
  pattern: arbitraryTailwindValuePattern(allowArbitraryClasses),
1432
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-[...])."
1433
- }
1655
+ },
1656
+ ...designRestrictions
1434
1657
  ]
1435
1658
  }
1436
1659
  ]
@@ -1463,7 +1686,8 @@ var buildConfig = ({
1463
1686
  plugins: { soujvnunes: soujvnunesPlugin },
1464
1687
  rules: {
1465
1688
  "soujvnunes/no-needless-use-client": "error",
1466
- "soujvnunes/no-static-jsx-in-client": "error"
1689
+ "soujvnunes/no-static-jsx-in-client": "error",
1690
+ "soujvnunes/one-component-per-client-file": "error"
1467
1691
  }
1468
1692
  };
1469
1693
  const programBanRule = (message) => restrictedSyntaxRule(ALL_SELECTOR_KEYS, [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soujvnunes/eslint-config",
3
- "version": "0.10.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",