@soujvnunes/eslint-config 0.9.0 → 0.11.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 +7 -4
- package/dist/index.d.ts +1 -12
- package/dist/index.js +302 -332
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,10 +41,10 @@ export default createBaseConfig()
|
|
|
41
41
|
|
|
42
42
|
| Option | Default | Purpose |
|
|
43
43
|
| --- | --- | --- |
|
|
44
|
-
| `importGroups` | react, next, module, parent, sibling, index | Full import-order groups; insert your `@/...` paths |
|
|
44
|
+
| `importGroups` | react, next, module, parent, sibling, index | Full import-order groups, which replace the default list; insert your `@/...` paths |
|
|
45
45
|
| `ignores` | (none) | Extra ignore globs, merged after the built-in defaults |
|
|
46
46
|
| `tsconfigRootDir` | `process.cwd()` | Root for typescript-eslint's project service |
|
|
47
|
-
| `tailwindEntryPoint` | (none) | Tailwind v4 CSS entry path. 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, and `no-restricted-classes`, which flags an arbitrary-value class such as `text-[11px]`. The stylistic rules stay off, since `prettier-plugin-tailwindcss` already owns class order |
|
|
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
49
|
| `classMergeName` | `'cn'` | The class-merge helper name a ternary passed straight to it is banned inside of |
|
|
50
50
|
| `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 |
|
|
@@ -69,19 +69,22 @@ These are the opinions most likely to surprise an existing codebase. All of them
|
|
|
69
69
|
|
|
70
70
|
**No warning severity.** Every rule either fails or is not present. A deliberate exception is an `eslint-disable` comment rather than a warning, and `reportUnusedDisableDirectives` is on, so a disable comment that suppresses nothing is itself an error.
|
|
71
71
|
|
|
72
|
-
**No comments in code: `soujvnunes/no-comments`.** It reports every comment in a JS or TS file except
|
|
72
|
+
**No comments in code: `soujvnunes/no-comments`.** It reports every comment in a JS or TS file, JSDoc included, except a tool directive. A tool directive that does work stays, matched by name: `eslint-disable`, `@ts-expect-error`, `@ts-ignore`, `@ts-nocheck`, `@ts-check`, `prettier-ignore`, `biome-ignore`, a coverage pragma (`istanbul`, `c8`, `v8`, `node:coverage`), a minifier annotation (`@__PURE__`, `#__NO_SIDE_EFFECTS__` and the rest of the `__NAME__` family), a `webpack` or `turbopack` magic comment, `@vite-ignore`, `//# sourceMappingURL`, a triple-slash reference, `/* global */`, `@jsx` with its `Frag`, `ImportSource` and `Runtime` forms, `@vitest-environment`, `@jest-environment`, `@refresh reset`, `@license`, `@preserve`, `@format`, `@prettier`, `@internal` standing alone (read by TypeScript's `stripInternal`; with prose after it, it is a JSDoc like any other), a JSDoc whose only content is a `@deprecated` tag with or without its sentence, on one line or several (read by editors and by `@typescript-eslint/no-deprecated`; another tag after it, or the same text in a `//` line, reports, while a scoped package name such as `@scope/pkg` in its sentence is not a tag, and an em dash in its sentence reports without a fix), `gitleaks:allow` anywhere in a one-line comment that shares its line with code, before it or after it (gitleaks reads it only on the line of the finding), the `/*!` banner and the `#!` line. Any other comment that opens with `@` or `#`, such as `// @todo`, is prose and reports. In a `.js`, `.mjs`, `.cjs` or `.jsx` file a JSDoc whose first tag is a type annotation `checkJs` reads (`@type`, `@typedef`, `@callback`, `@satisfies`, `@template`, `@param`, `@returns`, `@import`, `@enum`, `@extends`, `@augments`, `@implements`, `@this`, `@overload`) and carries the type the tag takes (a `{Type}` after `@type`, `@param`, `@returns`, `@return`, `@satisfies`, `@enum` and `@this`; a `{Type}` or a name that ends its line after `@typedef` and `@callback`; a `{constraint}` or a comma list of names that ends its line after `@template`; a `{Type}` or a type that ends its line after `@extends`, `@augments` and `@implements`; an `import` clause with its `from` after `@import`; a typed `@param` or `@returns` later in the same comment after `@overload`), stays as well, wherever it sits, since deleting it removes the type check. Every other JSDoc reports wherever it sits: above an exported symbol, on a member of an exported class, interface, type or enum, on a key of an exported object, in a `declare global` block and in a `.d.ts` file alike. The rule used to keep those and took a `jsdoc` option to report them; the option is gone, so passing it is a config error and a config that set `{ jsdoc: 'never' }` drops it. A `{/* */}` in JSX and a comment inside a JSX tag are reported like any other comment. The fix deletes the comment: its whole line when it stands alone, back to the code when it trails, and one space when code sits on both sides. Five cases are left to the author: a JSX container between text, a comment inside a tag, a multi-line comment with code on both of its edges (deleting it could join two lines that semicolon insertion keeps apart), a JSDoc holding an `@` tag, and a comment that is all a block holds, since deleting it would leave an empty block that `no-empty` reports (a function body is not such a block, since `no-empty` never reports one, so its lone comment is deleted). A reason the code cannot carry belongs in the README. Both presets turn it on at error, beside `soujvnunes/one-line-comments`, which still collapses a multi-line `@deprecated` JSDoc to one line.
|
|
73
73
|
|
|
74
74
|
**Type-aware rules are enabled**, including `no-floating-promises`, `no-misused-promises`, `await-thenable`, `no-deprecated` and `no-unnecessary-type-assertion`. These need the project service, which is wired by default (see above). They are the rules most likely to surface real findings in a codebase adopting this config, and most are not autofixable.
|
|
75
75
|
|
|
76
76
|
**`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
77
|
|
|
78
|
-
**
|
|
78
|
+
**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
79
|
|
|
80
80
|
- `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
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.
|
|
82
|
+
- `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
83
|
|
|
83
84
|
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
85
|
|
|
86
|
+
This package's tests run every client-boundary case under two settings, espree with no globals and the Next preset's TypeScript parser with browser globals, since a global the config or a TypeScript lib declares resolves differently from an undeclared one.
|
|
87
|
+
|
|
85
88
|
Adopting this in an existing repo is usually one `eslint --fix` pass plus a short list of genuine fixes from the type-aware rules.
|
|
86
89
|
|
|
87
90
|
## Accessibility on the Next preset
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Linter } from 'eslint';
|
|
2
2
|
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
3
3
|
|
|
4
|
-
declare const oneLineComments: ESLintUtils.RuleModule<"block" | "
|
|
4
|
+
declare const oneLineComments: ESLintUtils.RuleModule<"block" | "adjacent" | "paragraphs" | "notDoc" | "orphanDoc", [], unknown, ESLintUtils.RuleListener>;
|
|
5
5
|
|
|
6
6
|
type CompatiblePlugin = {
|
|
7
7
|
meta: {
|
|
@@ -11,28 +11,17 @@ type CompatiblePlugin = {
|
|
|
11
11
|
declare const soujvnunesPlugin: CompatiblePlugin;
|
|
12
12
|
|
|
13
13
|
interface ConfigOptions {
|
|
14
|
-
/** Extra ignore globs, merged after the defaults. */
|
|
15
14
|
ignores?: string[];
|
|
16
|
-
/** Full import-order groups (replaces the default skeleton). */
|
|
17
15
|
importGroups?: (string | string[])[];
|
|
18
|
-
/** Root for typescript-eslint's project service. Defaults to cwd. */
|
|
19
16
|
tsconfigRootDir?: string;
|
|
20
|
-
/** Path to the Tailwind v4 CSS entry (the file with `@import "tailwindcss"` + `@theme`, e.g. `./app/tailwind.config.css`). When set on the Next preset, it wires the bundled `eslint-plugin-better-tailwindcss` correctness rules, chiefly `no-unknown-classes`, which flags a class not registered in the theme (a dead token `tsc`/build cannot see; see DESIGN-TOKENS). Leave it unset and the plugin stays off, since without the entry the rule cannot resolve the theme and would flag every class. */
|
|
21
17
|
tailwindEntryPoint?: string;
|
|
22
|
-
/** Utility prefixes exempt from the arbitrary-Tailwind-value ban, for a shape with no theme token (e.g. `['grid-cols', 'grid-rows']` for `grid-cols-[200px_1fr]`). Only read when `tailwindEntryPoint` is set. */
|
|
23
18
|
allowArbitraryClasses?: string[];
|
|
24
|
-
/** The `cn()`-like helper name a ternary passed straight to it is banned inside of. */
|
|
25
19
|
classMergeName?: string;
|
|
26
|
-
/** Modules next.config.* loads, beside a next.config.ts, .mts or .cts itself (the .js and .mjs forms sit in the default ignores), restricted with the same repo's `no-restricted-imports` patterns (`['@/*']`) as the config file: relative imports only. */
|
|
27
20
|
nextConfigModules?: string[];
|
|
28
|
-
/** Globs wired to `soujvnunes/one-export-per-file`, the probe-only one-value-export-per-module rule. Unwired (no globs) leaves the rule exported but off. */
|
|
29
21
|
strictExportGlobs?: string[];
|
|
30
|
-
/** Extra flat-config objects appended at the end. */
|
|
31
22
|
extend?: Linter.Config[];
|
|
32
23
|
}
|
|
33
|
-
/** Base config for TypeScript libraries (no React/Next layers). */
|
|
34
24
|
declare const createBaseConfig: (options?: ConfigOptions) => any[];
|
|
35
|
-
/** Full config for Next.js apps: base plus React, React Hooks, jsx-a11y and Next plugins. */
|
|
36
25
|
declare const createNextConfig: (options?: ConfigOptions) => any[];
|
|
37
26
|
|
|
38
27
|
export { type ConfigOptions, createBaseConfig, createNextConfig, oneLineComments, soujvnunesPlugin };
|
package/dist/index.js
CHANGED
|
@@ -29,8 +29,18 @@ var findUseClientDirective = (program) => {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
// needsClient.ts
|
|
32
|
-
import { AST_NODE_TYPES as
|
|
32
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES13, TSESLint as TSESLint5 } from "@typescript-eslint/utils";
|
|
33
|
+
|
|
34
|
+
// browserGlobals.ts
|
|
33
35
|
import globals from "globals";
|
|
36
|
+
var BROWSER_GLOBALS = /* @__PURE__ */ new Set([
|
|
37
|
+
...Object.keys(globals.browser).filter(
|
|
38
|
+
(name) => !Object.hasOwn(globals.node, name) && !Object.hasOwn(globals.builtin, name)
|
|
39
|
+
),
|
|
40
|
+
"navigator",
|
|
41
|
+
"localStorage",
|
|
42
|
+
"sessionStorage"
|
|
43
|
+
]);
|
|
34
44
|
|
|
35
45
|
// calleeName.ts
|
|
36
46
|
import { AST_NODE_TYPES as AST_NODE_TYPES2 } from "@typescript-eslint/utils";
|
|
@@ -407,6 +417,9 @@ var createClassifier = (sourceCode, importMembersAreData) => {
|
|
|
407
417
|
return { classify: classify2, classifyTag, positionOf, variableOf };
|
|
408
418
|
};
|
|
409
419
|
|
|
420
|
+
// createClientWalk.ts
|
|
421
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES12, TSESLint as TSESLint4 } from "@typescript-eslint/utils";
|
|
422
|
+
|
|
410
423
|
// isEventHandler.ts
|
|
411
424
|
var isEventHandler = (key) => /^on[A-Z]/u.test(key);
|
|
412
425
|
|
|
@@ -414,173 +427,183 @@ var isEventHandler = (key) => /^on[A-Z]/u.test(key);
|
|
|
414
427
|
var FUNCTION_ATTRIBUTES = /* @__PURE__ */ new Set(["ref", "action", "formAction"]);
|
|
415
428
|
var isFunctionAttribute = (key) => isEventHandler(key) || FUNCTION_ATTRIBUTES.has(key);
|
|
416
429
|
|
|
417
|
-
//
|
|
430
|
+
// isHookName.ts
|
|
431
|
+
var isHookName = (name) => /^use[A-Z]/u.test(name);
|
|
432
|
+
|
|
433
|
+
// createClientWalk.ts
|
|
418
434
|
var { DefinitionType: DefinitionType4 } = TSESLint4.Scope;
|
|
419
|
-
var HOOK = /^use[A-Z]/u;
|
|
420
|
-
var STYLESHEET = /\.(?:css|scss|sass|less)$/u;
|
|
421
435
|
var CLIENT_CALLS = /* @__PURE__ */ new Set(["use", "createContext", "createPortal", "flushSync"]);
|
|
422
|
-
var CLIENT_MODULES = /* @__PURE__ */ new Set(["next/dynamic", "client-only"]);
|
|
423
436
|
var CLASS_BASES = /* @__PURE__ */ new Set(["Component", "PureComponent"]);
|
|
437
|
+
var createClientWalk = (sourceCode, { classify: classify2, classifyTag, positionOf, variableOf }, countsOnlyFunctions = false) => {
|
|
438
|
+
const isData = (node) => classify2(node, "prop").data;
|
|
439
|
+
const isFunctionExpression = (node) => node?.type === AST_NODE_TYPES12.ArrowFunctionExpression || node?.type === AST_NODE_TYPES12.FunctionExpression;
|
|
440
|
+
const isBoundToFunction = (node) => !!variableOf(node, node.name)?.defs.some(
|
|
441
|
+
(def) => def.type === DefinitionType4.FunctionName || def.type === DefinitionType4.Variable && def.node.type === AST_NODE_TYPES12.VariableDeclarator && isFunctionExpression(def.node.init)
|
|
442
|
+
);
|
|
443
|
+
const isFunctionValue = (node) => isFunctionExpression(node) || node.type === AST_NODE_TYPES12.Identifier && isBoundToFunction(node);
|
|
444
|
+
const isClientValue = (node) => countsOnlyFunctions ? isFunctionValue(node) : !isData(node);
|
|
445
|
+
const callNames = (callee) => {
|
|
446
|
+
if (callee.type !== AST_NODE_TYPES12.Identifier) return [calleeName(callee)];
|
|
447
|
+
return [callee.name, importedName(variableOf(callee, callee.name))];
|
|
448
|
+
};
|
|
449
|
+
const needsNode = (node) => {
|
|
450
|
+
switch (node.type) {
|
|
451
|
+
case AST_NODE_TYPES12.CallExpression:
|
|
452
|
+
return callNames(node.callee).some((name) => isHookName(name) || CLIENT_CALLS.has(name));
|
|
453
|
+
case AST_NODE_TYPES12.ClassDeclaration:
|
|
454
|
+
case AST_NODE_TYPES12.ClassExpression:
|
|
455
|
+
return !!node.superClass && CLASS_BASES.has(calleeName(node.superClass));
|
|
456
|
+
case AST_NODE_TYPES12.MemberExpression:
|
|
457
|
+
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;
|
|
458
|
+
case AST_NODE_TYPES12.JSXOpeningElement: {
|
|
459
|
+
if (!classifyTag(node).data) return true;
|
|
460
|
+
const isTag = positionOf(node) === "text";
|
|
461
|
+
return node.attributes.some((attribute) => {
|
|
462
|
+
if (attribute.type === AST_NODE_TYPES12.JSXSpreadAttribute)
|
|
463
|
+
return isTag ? !isData(attribute.argument) : isClientValue(attribute.argument);
|
|
464
|
+
const key = attribute.name.type === AST_NODE_TYPES12.JSXIdentifier ? attribute.name.name : "";
|
|
465
|
+
if (isEventHandler(key)) return true;
|
|
466
|
+
const { value } = attribute;
|
|
467
|
+
if (value?.type !== AST_NODE_TYPES12.JSXExpressionContainer) return false;
|
|
468
|
+
if (isTag) return isFunctionAttribute(key) && !isData(value.expression);
|
|
469
|
+
return key !== "className" && isClientValue(value.expression);
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
case AST_NODE_TYPES12.JSXExpressionContainer:
|
|
473
|
+
return node.parent.type === AST_NODE_TYPES12.JSXElement && positionOf(node.parent.openingElement) === "prop" && isClientValue(node.expression);
|
|
474
|
+
default:
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
const walk = (node) => needsNode(node) || childNodes(node, sourceCode.visitorKeys).some(walk);
|
|
479
|
+
return walk;
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
// needsClient.ts
|
|
483
|
+
var { DefinitionType: DefinitionType5 } = TSESLint5.Scope;
|
|
484
|
+
var STYLESHEET = /\.(?:css|scss|sass|less)$/u;
|
|
485
|
+
var CLIENT_MODULES = /* @__PURE__ */ new Set(["next/dynamic", "client-only"]);
|
|
424
486
|
var PURE_CALLS = /* @__PURE__ */ new Set(["cva", "tv"]);
|
|
425
487
|
var INERT_TYPES = /* @__PURE__ */ new Set([
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
488
|
+
AST_NODE_TYPES13.Literal,
|
|
489
|
+
AST_NODE_TYPES13.TemplateLiteral,
|
|
490
|
+
AST_NODE_TYPES13.TemplateElement,
|
|
491
|
+
AST_NODE_TYPES13.Identifier,
|
|
492
|
+
AST_NODE_TYPES13.UnaryExpression,
|
|
493
|
+
AST_NODE_TYPES13.BinaryExpression,
|
|
494
|
+
AST_NODE_TYPES13.LogicalExpression,
|
|
495
|
+
AST_NODE_TYPES13.ConditionalExpression,
|
|
496
|
+
AST_NODE_TYPES13.ArrayExpression,
|
|
497
|
+
AST_NODE_TYPES13.ObjectExpression,
|
|
498
|
+
AST_NODE_TYPES13.Property,
|
|
499
|
+
AST_NODE_TYPES13.SpreadElement,
|
|
500
|
+
AST_NODE_TYPES13.RestElement,
|
|
501
|
+
AST_NODE_TYPES13.ObjectPattern,
|
|
502
|
+
AST_NODE_TYPES13.ArrayPattern,
|
|
503
|
+
AST_NODE_TYPES13.AssignmentPattern,
|
|
504
|
+
AST_NODE_TYPES13.JSXElement,
|
|
505
|
+
AST_NODE_TYPES13.JSXFragment,
|
|
506
|
+
AST_NODE_TYPES13.JSXOpeningElement,
|
|
507
|
+
AST_NODE_TYPES13.JSXClosingElement,
|
|
508
|
+
AST_NODE_TYPES13.JSXOpeningFragment,
|
|
509
|
+
AST_NODE_TYPES13.JSXClosingFragment,
|
|
510
|
+
AST_NODE_TYPES13.JSXAttribute,
|
|
511
|
+
AST_NODE_TYPES13.JSXSpreadAttribute,
|
|
512
|
+
AST_NODE_TYPES13.JSXExpressionContainer,
|
|
513
|
+
AST_NODE_TYPES13.JSXEmptyExpression,
|
|
514
|
+
AST_NODE_TYPES13.JSXText,
|
|
515
|
+
AST_NODE_TYPES13.JSXIdentifier,
|
|
516
|
+
AST_NODE_TYPES13.JSXNamespacedName,
|
|
517
|
+
AST_NODE_TYPES13.TSAsExpression,
|
|
518
|
+
AST_NODE_TYPES13.TSSatisfiesExpression,
|
|
519
|
+
AST_NODE_TYPES13.TSNonNullExpression
|
|
458
520
|
]);
|
|
459
521
|
var TYPE_DECLARATIONS = /* @__PURE__ */ new Set([
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
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"
|
|
522
|
+
AST_NODE_TYPES13.TSInterfaceDeclaration,
|
|
523
|
+
AST_NODE_TYPES13.TSTypeAliasDeclaration,
|
|
524
|
+
AST_NODE_TYPES13.TSDeclareFunction
|
|
471
525
|
]);
|
|
472
526
|
var isValueReference = (reference) => reference.isValueReference !== false;
|
|
473
527
|
var verdicts = /* @__PURE__ */ new WeakMap();
|
|
474
528
|
var analyze = (sourceCode) => {
|
|
475
|
-
const
|
|
476
|
-
const
|
|
529
|
+
const classifier = createClassifier(sourceCode, false);
|
|
530
|
+
const { variableOf } = classifier;
|
|
531
|
+
const walk = createClientWalk(sourceCode, classifier);
|
|
477
532
|
const isComponentBinding = (identifier) => {
|
|
478
533
|
const variable = variableOf(identifier, identifier.name);
|
|
479
534
|
const isNamedLikeComponent = isComponentName(variable?.name);
|
|
480
535
|
return everyDef(
|
|
481
536
|
variable,
|
|
482
|
-
(def) => def.type ===
|
|
537
|
+
(def) => def.type === DefinitionType5.Type || isNamedLikeComponent && (def.type === DefinitionType5.FunctionName || def.type === DefinitionType5.Variable && isComponentInit(def.node.init))
|
|
483
538
|
);
|
|
484
539
|
};
|
|
485
540
|
const isLocalRead = (node) => {
|
|
486
541
|
let root = node;
|
|
487
|
-
while (root.type ===
|
|
542
|
+
while (root.type === AST_NODE_TYPES13.MemberExpression) {
|
|
488
543
|
if (root.computed && !isInert(root.property)) return false;
|
|
489
544
|
root = root.object;
|
|
490
545
|
}
|
|
491
|
-
const variable = root.type ===
|
|
492
|
-
return everyDef(variable, (def) => def.type ===
|
|
546
|
+
const variable = root.type === AST_NODE_TYPES13.Identifier ? variableOf(root, root.name) : null;
|
|
547
|
+
return everyDef(variable, (def) => def.type === DefinitionType5.Variable);
|
|
493
548
|
};
|
|
494
|
-
const isPlainCallee = (callee) => callee.type ===
|
|
549
|
+
const isPlainCallee = (callee) => callee.type === AST_NODE_TYPES13.Identifier || callee.type === AST_NODE_TYPES13.MemberExpression && !callee.computed && isPlainCallee(callee.object);
|
|
495
550
|
const isInert = (node) => {
|
|
496
551
|
if (isFunctionNode(node)) return true;
|
|
497
|
-
if (node.type ===
|
|
498
|
-
if (node.type ===
|
|
499
|
-
if (node.type ===
|
|
552
|
+
if (node.type === AST_NODE_TYPES13.UnaryExpression && node.operator === "delete") return false;
|
|
553
|
+
if (node.type === AST_NODE_TYPES13.MemberExpression) return isLocalRead(node);
|
|
554
|
+
if (node.type === AST_NODE_TYPES13.CallExpression)
|
|
500
555
|
return isPlainCallee(node.callee) && (PURE_CALLS.has(calleeName(node.callee)) || isComponentWrapperCall(node)) && node.arguments.every(isInert);
|
|
501
556
|
return INERT_TYPES.has(node.type) && childNodes(node, sourceCode.visitorKeys).every(isInert);
|
|
502
557
|
};
|
|
503
558
|
const exportsOnlyComponents = (declaration) => {
|
|
504
559
|
if (TYPE_DECLARATIONS.has(declaration.type)) return true;
|
|
505
|
-
if (declaration.type ===
|
|
560
|
+
if (declaration.type === AST_NODE_TYPES13.FunctionDeclaration)
|
|
506
561
|
return isComponentName(declaration.id?.name);
|
|
507
|
-
if (declaration.type !==
|
|
562
|
+
if (declaration.type !== AST_NODE_TYPES13.VariableDeclaration) return false;
|
|
508
563
|
return declaration.declarations.every(
|
|
509
|
-
(declarator) => declarator.id.type ===
|
|
564
|
+
(declarator) => declarator.id.type === AST_NODE_TYPES13.Identifier && isComponentName(declarator.id.name) && declarator.init !== null && isComponentInit(declarator.init) && isInert(declarator.init)
|
|
510
565
|
);
|
|
511
566
|
};
|
|
512
567
|
const isServerSafeStatement = (statement) => {
|
|
513
568
|
switch (statement.type) {
|
|
514
|
-
case
|
|
569
|
+
case AST_NODE_TYPES13.ExpressionStatement:
|
|
515
570
|
return statement.directive !== void 0;
|
|
516
|
-
case
|
|
571
|
+
case AST_NODE_TYPES13.ImportDeclaration:
|
|
517
572
|
if (statement.importKind === "type") return true;
|
|
518
573
|
if (statement.specifiers.length === 0) return STYLESHEET.test(statement.source.value);
|
|
519
574
|
return !CLIENT_MODULES.has(statement.source.value);
|
|
520
|
-
case
|
|
575
|
+
case AST_NODE_TYPES13.FunctionDeclaration:
|
|
521
576
|
return true;
|
|
522
|
-
case
|
|
577
|
+
case AST_NODE_TYPES13.TSEnumDeclaration:
|
|
523
578
|
return statement.body.members.every(
|
|
524
579
|
(member) => !member.initializer || isInert(member.initializer)
|
|
525
580
|
);
|
|
526
|
-
case
|
|
581
|
+
case AST_NODE_TYPES13.VariableDeclaration:
|
|
527
582
|
return statement.declarations.every(
|
|
528
583
|
(declarator) => isInert(declarator.id) && (!declarator.init || isInert(declarator.init))
|
|
529
584
|
);
|
|
530
|
-
case
|
|
585
|
+
case AST_NODE_TYPES13.ExportAllDeclaration:
|
|
531
586
|
return statement.exportKind === "type";
|
|
532
|
-
case
|
|
587
|
+
case AST_NODE_TYPES13.ExportNamedDeclaration: {
|
|
533
588
|
if (statement.exportKind === "type") return true;
|
|
534
589
|
const isTypeOnly = statement.specifiers.length > 0 && statement.specifiers.every((specifier) => specifier.exportKind === "type");
|
|
535
590
|
if (statement.source) return isTypeOnly;
|
|
536
591
|
if (statement.declaration) return exportsOnlyComponents(statement.declaration);
|
|
537
592
|
return statement.specifiers.every(
|
|
538
|
-
(specifier) => specifier.exportKind === "type" || specifier.local.type ===
|
|
593
|
+
(specifier) => specifier.exportKind === "type" || specifier.local.type === AST_NODE_TYPES13.Identifier && isComponentBinding(specifier.local)
|
|
539
594
|
);
|
|
540
595
|
}
|
|
541
|
-
case
|
|
596
|
+
case AST_NODE_TYPES13.ExportDefaultDeclaration: {
|
|
542
597
|
const { declaration } = statement;
|
|
543
|
-
if (declaration.type ===
|
|
598
|
+
if (declaration.type === AST_NODE_TYPES13.FunctionDeclaration)
|
|
544
599
|
return isComponentName(declaration.id?.name);
|
|
545
|
-
if (declaration.type ===
|
|
600
|
+
if (declaration.type === AST_NODE_TYPES13.Identifier) return isComponentBinding(declaration);
|
|
546
601
|
return isComponentWrapperCall(declaration) && isComponentInit(declaration) && isInert(declaration);
|
|
547
602
|
}
|
|
548
603
|
default:
|
|
549
604
|
return TYPE_DECLARATIONS.has(statement.type);
|
|
550
605
|
}
|
|
551
606
|
};
|
|
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
607
|
if (!sourceCode.ast.body.every(isServerSafeStatement) || walk(sourceCode.ast)) return true;
|
|
585
608
|
const scope = sourceCode.getScope(sourceCode.ast);
|
|
586
609
|
return scope.through.some(
|
|
@@ -623,10 +646,10 @@ var needlessUseClient = ESLintUtils.RuleCreator.withoutDocs({
|
|
|
623
646
|
});
|
|
624
647
|
|
|
625
648
|
// noComments.ts
|
|
626
|
-
import { AST_NODE_TYPES as
|
|
649
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES15, AST_TOKEN_TYPES as AST_TOKEN_TYPES2, ESLintUtils as ESLintUtils2 } from "@typescript-eslint/utils";
|
|
627
650
|
|
|
628
651
|
// commentKinds.ts
|
|
629
|
-
import { AST_NODE_TYPES as
|
|
652
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES14, AST_TOKEN_TYPES } from "@typescript-eslint/utils";
|
|
630
653
|
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
654
|
var ALLOW_MARKER = /\bgitleaks:allow\b/u;
|
|
632
655
|
var BLOCK_DIRECTIVE = /^\s*(?:eslint\s|eslint-env\b|global\s|globals\s|exported\s)/u;
|
|
@@ -659,15 +682,23 @@ var TYPE_TAGS = /* @__PURE__ */ new Map([
|
|
|
659
682
|
]);
|
|
660
683
|
var ANNOTATION = /^\s*[@#]/u;
|
|
661
684
|
var BLOCK_ANNOTATION = /^\s*[\w-]+:\S/u;
|
|
685
|
+
var DEPRECATION = /^@deprecated(?![\w-])/u;
|
|
686
|
+
var LATER_TAG = /\s@\w[\w-]*(?![\w/-])/u;
|
|
662
687
|
var isComment = (token) => token?.type === AST_TOKEN_TYPES.Line || token?.type === AST_TOKEN_TYPES.Block;
|
|
663
688
|
var isDocShaped = (comment) => comment.type === AST_TOKEN_TYPES.Block && comment.value.startsWith("*");
|
|
664
689
|
var isBanner = (comment) => comment.type === AST_TOKEN_TYPES.Block && comment.value.startsWith("!");
|
|
665
690
|
var pragmaText = (comment) => comment.value.replace(/^\*+/u, "");
|
|
691
|
+
var docText = (comment) => comment.value.split(/\r?\n/u).map((line) => line.trim().replace(/^\*+/u, "").trim()).filter(Boolean).join(" ");
|
|
692
|
+
var isDeprecation = (comment) => {
|
|
693
|
+
if (!isDocShaped(comment)) return false;
|
|
694
|
+
const text = docText(comment);
|
|
695
|
+
return DEPRECATION.test(text) && !LATER_TAG.test(text);
|
|
696
|
+
};
|
|
666
697
|
var isDirectiveText = (text) => DIRECTIVE.test(text) || ANNOTATION.test(text);
|
|
667
698
|
var isDirective = (comment) => isDirectiveText(pragmaText(comment)) || comment.type === AST_TOKEN_TYPES.Block && (BLOCK_DIRECTIVE.test(comment.value) || !isDocShaped(comment) && BLOCK_ANNOTATION.test(comment.value));
|
|
668
699
|
var isToolDirective = (comment) => {
|
|
669
700
|
const text = pragmaText(comment);
|
|
670
|
-
return DIRECTIVE.test(text) || PRAGMA.test(text) || comment.type === AST_TOKEN_TYPES.Block && BLOCK_DIRECTIVE.test(comment.value);
|
|
701
|
+
return DIRECTIVE.test(text) || PRAGMA.test(text) || isDeprecation(comment) || comment.type === AST_TOKEN_TYPES.Block && BLOCK_DIRECTIVE.test(comment.value);
|
|
671
702
|
};
|
|
672
703
|
var holdsTag = (comment) => /(?:^|\s)@\w/u.test(pragmaText(comment));
|
|
673
704
|
var isTypeAnnotation = (comment) => {
|
|
@@ -690,7 +721,7 @@ var createCommentLookup = (sourceCode) => {
|
|
|
690
721
|
const enclosingNode = (comment) => nodeAt(comment.range[0]);
|
|
691
722
|
const jsxContainer = (comment) => {
|
|
692
723
|
const node = enclosingNode(comment);
|
|
693
|
-
return node?.type ===
|
|
724
|
+
return node?.type === AST_NODE_TYPES14.JSXEmptyExpression ? node.parent : null;
|
|
694
725
|
};
|
|
695
726
|
const sidesOf = (span) => {
|
|
696
727
|
const { lines } = sourceCode;
|
|
@@ -714,194 +745,44 @@ var createCommentLookup = (sourceCode) => {
|
|
|
714
745
|
};
|
|
715
746
|
|
|
716
747
|
// noComments.ts
|
|
717
|
-
var EXPORTS = /* @__PURE__ */ new Set([
|
|
718
|
-
AST_NODE_TYPES14.ExportNamedDeclaration,
|
|
719
|
-
AST_NODE_TYPES14.ExportDefaultDeclaration,
|
|
720
|
-
AST_NODE_TYPES14.ExportAllDeclaration
|
|
721
|
-
]);
|
|
722
|
-
var DOCUMENTED = /* @__PURE__ */ new Set([
|
|
723
|
-
AST_NODE_TYPES14.ClassDeclaration,
|
|
724
|
-
AST_NODE_TYPES14.FunctionDeclaration,
|
|
725
|
-
AST_NODE_TYPES14.TSDeclareFunction,
|
|
726
|
-
AST_NODE_TYPES14.VariableDeclaration,
|
|
727
|
-
AST_NODE_TYPES14.TSInterfaceDeclaration,
|
|
728
|
-
AST_NODE_TYPES14.TSTypeAliasDeclaration,
|
|
729
|
-
AST_NODE_TYPES14.TSEnumDeclaration,
|
|
730
|
-
AST_NODE_TYPES14.TSModuleDeclaration,
|
|
731
|
-
AST_NODE_TYPES14.PropertyDefinition,
|
|
732
|
-
AST_NODE_TYPES14.MethodDefinition,
|
|
733
|
-
AST_NODE_TYPES14.TSAbstractPropertyDefinition,
|
|
734
|
-
AST_NODE_TYPES14.TSAbstractMethodDefinition,
|
|
735
|
-
AST_NODE_TYPES14.AccessorProperty,
|
|
736
|
-
AST_NODE_TYPES14.TSAbstractAccessorProperty,
|
|
737
|
-
AST_NODE_TYPES14.TSParameterProperty,
|
|
738
|
-
AST_NODE_TYPES14.TSIndexSignature,
|
|
739
|
-
AST_NODE_TYPES14.TSPropertySignature,
|
|
740
|
-
AST_NODE_TYPES14.TSMethodSignature,
|
|
741
|
-
AST_NODE_TYPES14.TSCallSignatureDeclaration,
|
|
742
|
-
AST_NODE_TYPES14.TSConstructSignatureDeclaration,
|
|
743
|
-
AST_NODE_TYPES14.TSEnumMember,
|
|
744
|
-
AST_NODE_TYPES14.Property
|
|
745
|
-
]);
|
|
746
|
-
var BOUNDARIES = /* @__PURE__ */ new Set([
|
|
747
|
-
AST_NODE_TYPES14.Program,
|
|
748
|
-
AST_NODE_TYPES14.BlockStatement,
|
|
749
|
-
AST_NODE_TYPES14.StaticBlock
|
|
750
|
-
]);
|
|
751
|
-
var MODULE_STATEMENTS = /* @__PURE__ */ new Set([
|
|
752
|
-
AST_NODE_TYPES14.ImportDeclaration,
|
|
753
|
-
AST_NODE_TYPES14.ExportNamedDeclaration,
|
|
754
|
-
AST_NODE_TYPES14.ExportDefaultDeclaration,
|
|
755
|
-
AST_NODE_TYPES14.ExportAllDeclaration,
|
|
756
|
-
AST_NODE_TYPES14.TSExportAssignment
|
|
757
|
-
]);
|
|
758
|
-
var MEMBER_OPENERS = /* @__PURE__ */ new Set(["{", ";", ","]);
|
|
759
748
|
var JS_FILE = /\.[cm]?jsx?$/u;
|
|
760
|
-
var DECLARATION_FILE = /\.d\.[cm]?ts$/u;
|
|
761
749
|
var EM_DASH = String.fromCodePoint(8212);
|
|
762
|
-
var
|
|
763
|
-
var
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
if (
|
|
770
|
-
|
|
771
|
-
return
|
|
772
|
-
};
|
|
773
|
-
var deferredExports = (body) => {
|
|
774
|
-
const names = /* @__PURE__ */ new Set();
|
|
775
|
-
const add = (node) => {
|
|
776
|
-
const name = identifierName(node);
|
|
777
|
-
if (name) names.add(name);
|
|
778
|
-
};
|
|
779
|
-
for (const statement of body) {
|
|
780
|
-
const commonJs = commonJsExport(statement);
|
|
781
|
-
if (commonJs?.type === AST_NODE_TYPES14.ObjectExpression) {
|
|
782
|
-
for (const property of commonJs.properties) {
|
|
783
|
-
if (property.type === AST_NODE_TYPES14.Property) add(property.value);
|
|
784
|
-
}
|
|
785
|
-
} else add(commonJs);
|
|
786
|
-
if (statement.type === AST_NODE_TYPES14.ExportNamedDeclaration && !statement.source) {
|
|
787
|
-
for (const { local } of statement.specifiers) add(local);
|
|
788
|
-
}
|
|
789
|
-
if (statement.type === AST_NODE_TYPES14.ExportDefaultDeclaration) add(statement.declaration);
|
|
790
|
-
if (statement.type === AST_NODE_TYPES14.TSExportAssignment) add(statement.expression);
|
|
791
|
-
}
|
|
792
|
-
return names;
|
|
793
|
-
};
|
|
794
|
-
var declaredIds = (statement) => {
|
|
795
|
-
if (statement.type === AST_NODE_TYPES14.VariableDeclaration) {
|
|
796
|
-
return statement.declarations.map(({ id }) => id);
|
|
797
|
-
}
|
|
798
|
-
return "id" in statement ? [statement.id] : [];
|
|
799
|
-
};
|
|
800
|
-
var boundNames = (node) => {
|
|
801
|
-
if (node?.type === AST_NODE_TYPES14.Identifier) return [node.name];
|
|
802
|
-
if (node?.type === AST_NODE_TYPES14.ObjectPattern) {
|
|
803
|
-
return node.properties.flatMap(
|
|
804
|
-
(property) => boundNames(property.type === AST_NODE_TYPES14.RestElement ? property.argument : property.value)
|
|
805
|
-
);
|
|
806
|
-
}
|
|
807
|
-
if (node?.type === AST_NODE_TYPES14.ArrayPattern) {
|
|
808
|
-
return node.elements.flatMap((element) => boundNames(element));
|
|
809
|
-
}
|
|
810
|
-
if (node?.type === AST_NODE_TYPES14.AssignmentPattern) return boundNames(node.left);
|
|
811
|
-
if (node?.type === AST_NODE_TYPES14.RestElement) return boundNames(node.argument);
|
|
812
|
-
return [];
|
|
813
|
-
};
|
|
814
|
-
var isDeferred = (statement, deferred) => declaredIds(statement).some((id) => boundNames(id).some((name) => deferred.has(name)));
|
|
815
|
-
var isModuleFile = (program) => program.body.some(
|
|
816
|
-
(statement) => MODULE_STATEMENTS.has(statement.type) || commonJsExport(statement) !== null || statement.type === AST_NODE_TYPES14.TSImportEqualsDeclaration && statement.moduleReference.type === AST_NODE_TYPES14.TSExternalModuleReference
|
|
817
|
-
);
|
|
818
|
-
var isAmbient = (statement) => statement.type === AST_NODE_TYPES14.TSInterfaceDeclaration || statement.type === AST_NODE_TYPES14.TSTypeAliasDeclaration || "declare" in statement && statement.declare === true;
|
|
819
|
-
var ambience = (block) => {
|
|
820
|
-
let declared = false;
|
|
821
|
-
let node = block.parent;
|
|
822
|
-
while (node) {
|
|
823
|
-
if (node.type === AST_NODE_TYPES14.TSModuleDeclaration) {
|
|
824
|
-
if (node.kind === "global" || node.id.type === AST_NODE_TYPES14.Literal) return "public";
|
|
825
|
-
declared ||= node.declare;
|
|
826
|
-
}
|
|
827
|
-
node = node.parent;
|
|
828
|
-
}
|
|
829
|
-
return declared ? "declared" : "local";
|
|
830
|
-
};
|
|
831
|
-
var isBoundary = (node, child, walk) => BOUNDARIES.has(node.type) || node.type === AST_NODE_TYPES14.ArrowFunctionExpression && node.body === child || !walk.throughCalls && (node.type === AST_NODE_TYPES14.CallExpression || node.type === AST_NODE_TYPES14.NewExpression) && node.arguments.some((argument) => argument === child);
|
|
832
|
-
var isPublished = (statement, walk) => {
|
|
833
|
-
const { parent } = statement;
|
|
834
|
-
if (parent?.type !== AST_NODE_TYPES14.TSModuleBlock) return true;
|
|
835
|
-
return ambience(parent) === "public" || reachesExport(parent.parent, walk);
|
|
836
|
-
};
|
|
837
|
-
var reachesExport = (start, walk) => {
|
|
838
|
-
let child = start;
|
|
839
|
-
let node = start.parent;
|
|
840
|
-
while (node) {
|
|
841
|
-
if (EXPORTS.has(node.type)) return isPublished(node, walk);
|
|
842
|
-
if (node.type === AST_NODE_TYPES14.TSModuleBlock) {
|
|
843
|
-
const scope = ambience(node);
|
|
844
|
-
if (scope !== "declared") return scope === "public";
|
|
845
|
-
}
|
|
846
|
-
if (node.type === AST_NODE_TYPES14.Program) return walk.topLevel(child);
|
|
847
|
-
if (isBoundary(node, child, walk)) return false;
|
|
848
|
-
child = node;
|
|
849
|
-
node = node.parent;
|
|
850
|
-
}
|
|
851
|
-
return false;
|
|
852
|
-
};
|
|
853
|
-
var isExportedDoc = (comment, sourceCode, lookup, decorated, walk) => {
|
|
854
|
-
const before = sourceCode.getTokenBefore(comment);
|
|
855
|
-
if (before?.loc.end.line === comment.loc.start.line && !MEMBER_OPENERS.has(before.value)) {
|
|
856
|
-
return false;
|
|
857
|
-
}
|
|
858
|
-
const token = sourceCode.getTokenAfter(comment);
|
|
859
|
-
if (!token) return false;
|
|
860
|
-
const target = decorated.get(token.range[0]);
|
|
861
|
-
if (target?.type === AST_NODE_TYPES14.ClassDeclaration && reachesExport(target, walk)) {
|
|
862
|
-
return true;
|
|
863
|
-
}
|
|
864
|
-
let node = lookup.nodeAt(token.range[0]);
|
|
865
|
-
while (node?.range[0] === token.range[0]) {
|
|
866
|
-
if (EXPORTS.has(node.type)) return isPublished(node, walk);
|
|
867
|
-
if (DOCUMENTED.has(node.type)) return reachesExport(node, walk);
|
|
868
|
-
node = node.parent ?? null;
|
|
869
|
-
}
|
|
870
|
-
return false;
|
|
750
|
+
var isJsxNode = (node) => !!node && node.type.startsWith("JSX") && node.type !== AST_NODE_TYPES15.JSXExpressionContainer;
|
|
751
|
+
var FUNCTION_NODES = /* @__PURE__ */ new Set([
|
|
752
|
+
AST_NODE_TYPES15.FunctionDeclaration,
|
|
753
|
+
AST_NODE_TYPES15.FunctionExpression,
|
|
754
|
+
AST_NODE_TYPES15.ArrowFunctionExpression
|
|
755
|
+
]);
|
|
756
|
+
var isEmptyBlock = (node) => {
|
|
757
|
+
if (node?.type === AST_NODE_TYPES15.SwitchStatement) return node.cases.length === 0;
|
|
758
|
+
if (node?.type === AST_NODE_TYPES15.StaticBlock) return node.body.length === 0;
|
|
759
|
+
return node?.type === AST_NODE_TYPES15.BlockStatement && node.body.length === 0 && !FUNCTION_NODES.has(node.parent.type);
|
|
871
760
|
};
|
|
872
|
-
var
|
|
873
|
-
var classify = (comment, sourceCode, lookup, decorated, topLevel) => {
|
|
761
|
+
var classify = (comment, lookup) => {
|
|
874
762
|
const node = lookup.enclosingNode(comment);
|
|
875
763
|
const inJsx = isJsxNode(node);
|
|
876
764
|
if (isToolDirective(comment) || lookup.isAllowMarker(comment)) {
|
|
877
765
|
return inJsx ? "jsxDirective" : "directive";
|
|
878
766
|
}
|
|
879
767
|
if (isBanner(comment)) return "banner";
|
|
880
|
-
if (inJsx) return node?.type ===
|
|
881
|
-
if (isDocShaped(comment))
|
|
882
|
-
const reaches = (throughCalls) => isExportedDoc(comment, sourceCode, lookup, decorated, { topLevel, throughCalls });
|
|
883
|
-
if (reaches(false)) return "jsdoc";
|
|
884
|
-
return reaches(true) ? "argumentDoc" : "orphanDoc";
|
|
885
|
-
}
|
|
768
|
+
if (inJsx) return node?.type === AST_NODE_TYPES15.JSXEmptyExpression ? "jsx" : "attribute";
|
|
769
|
+
if (isDocShaped(comment)) return "jsdoc";
|
|
886
770
|
return comment.type === AST_TOKEN_TYPES2.Line ? "line" : "block";
|
|
887
771
|
};
|
|
772
|
+
var KEPT = "Only a tool directive stays, such as `eslint-disable`, `@ts-expect-error`, a type annotation in a JS file, a lone `@internal` or a JSDoc holding only `@deprecated`.";
|
|
888
773
|
var MESSAGES = {
|
|
889
|
-
line:
|
|
890
|
-
block:
|
|
891
|
-
|
|
892
|
-
argumentDoc: "This JSDoc sits in an argument of an exported call or `new`, so it is published only when the callee returns its argument's type, as `Object.freeze` or a generic identity helper does. The rule cannot see the signature: delete it unless the callee keeps it.",
|
|
893
|
-
jsdoc: "This config allows no JSDoc. Delete it.",
|
|
774
|
+
line: `Comments are not allowed in code. Delete this \`//\` comment: a reason the code cannot carry belongs in the README. ${KEPT}`,
|
|
775
|
+
block: `Comments are not allowed in code. Delete this block comment: a reason the code cannot carry belongs in the README. ${KEPT}`,
|
|
776
|
+
jsdoc: `Comments are not allowed in code, JSDoc included. Delete this JSDoc: a reason the code cannot carry belongs in the README. ${KEPT}`,
|
|
894
777
|
jsx: "Comments are not allowed in JSX. Delete this `{/* */}` container; only a tool directive stays.",
|
|
895
778
|
attribute: "Comments are not allowed inside a JSX tag. Delete this one.",
|
|
896
|
-
emDash: "This JSDoc holds an em dash. Write a comma, a colon, parentheses or two sentences instead."
|
|
779
|
+
emDash: "This `@deprecated` JSDoc holds an em dash. Write a comma, a colon, parentheses or two sentences instead."
|
|
897
780
|
};
|
|
898
781
|
var MESSAGE_IDS = {
|
|
899
782
|
directive: null,
|
|
900
783
|
banner: null,
|
|
901
784
|
jsxDirective: null,
|
|
902
785
|
jsdoc: "jsdoc",
|
|
903
|
-
orphanDoc: "orphanDoc",
|
|
904
|
-
argumentDoc: "argumentDoc",
|
|
905
786
|
jsx: "jsx",
|
|
906
787
|
attribute: "attribute",
|
|
907
788
|
line: "line",
|
|
@@ -911,29 +792,17 @@ var noComments = ESLintUtils2.RuleCreator.withoutDocs({
|
|
|
911
792
|
meta: {
|
|
912
793
|
type: "suggestion",
|
|
913
794
|
docs: {
|
|
914
|
-
description: "Disallow comments in code, except tool directives
|
|
795
|
+
description: "Disallow comments in code, JSDoc included, except tool directives, a type-annotation JSDoc in a JS file, a lone `@internal` and a JSDoc holding only `@deprecated`."
|
|
915
796
|
},
|
|
916
797
|
fixable: "code",
|
|
917
|
-
schema: [
|
|
918
|
-
{
|
|
919
|
-
type: "object",
|
|
920
|
-
properties: { jsdoc: { type: "string", enum: ["exports", "never"] } },
|
|
921
|
-
additionalProperties: false
|
|
922
|
-
}
|
|
923
|
-
],
|
|
798
|
+
schema: [],
|
|
924
799
|
messages: MESSAGES
|
|
925
800
|
},
|
|
926
|
-
defaultOptions: [
|
|
927
|
-
create(context
|
|
801
|
+
defaultOptions: [],
|
|
802
|
+
create(context) {
|
|
928
803
|
const sourceCode = context.sourceCode;
|
|
929
804
|
const { lines, text } = sourceCode;
|
|
930
805
|
const lookup = createCommentLookup(sourceCode);
|
|
931
|
-
const decorated = /* @__PURE__ */ new Map();
|
|
932
|
-
const program = sourceCode.ast;
|
|
933
|
-
const deferred = deferredExports(program.body);
|
|
934
|
-
const globalScope = !isModuleFile(program);
|
|
935
|
-
const declarationFile = DECLARATION_FILE.test(context.filename);
|
|
936
|
-
const topLevel = (statement) => isDeferred(statement, deferred) || globalScope && (declarationFile || isAmbient(statement));
|
|
937
806
|
const typedJs = JS_FILE.test(context.filename);
|
|
938
807
|
const lineStart = (line) => sourceCode.getIndexFromLoc({ line, column: 0 });
|
|
939
808
|
const lineEnd = (line) => lineStart(line) + (lines[line - 1]?.length ?? 0);
|
|
@@ -943,7 +812,7 @@ var noComments = ESLintUtils2.RuleCreator.withoutDocs({
|
|
|
943
812
|
return [0, text.length];
|
|
944
813
|
};
|
|
945
814
|
const removal = (comment, kind) => {
|
|
946
|
-
if (kind === "attribute" || kind === "
|
|
815
|
+
if (kind === "attribute" || kind === "jsdoc" && holdsTag(comment) || isEmptyBlock(lookup.enclosingNode(comment))) {
|
|
947
816
|
return null;
|
|
948
817
|
}
|
|
949
818
|
const span = lookup.jsxContainer(comment) ?? comment;
|
|
@@ -967,19 +836,12 @@ var noComments = ESLintUtils2.RuleCreator.withoutDocs({
|
|
|
967
836
|
return nextStart === void 0 ? null : { range: [range[0], nextStart], text: "", lines: null };
|
|
968
837
|
};
|
|
969
838
|
return {
|
|
970
|
-
Decorator(decorator) {
|
|
971
|
-
const { parent } = decorator;
|
|
972
|
-
if ("decorators" in parent && parent.decorators[0] === decorator) {
|
|
973
|
-
decorated.set(decorator.range[0], parent);
|
|
974
|
-
}
|
|
975
|
-
},
|
|
976
839
|
"Program:exit"() {
|
|
977
840
|
const reports = [];
|
|
978
841
|
for (const comment of sourceCode.getAllComments().filter(isComment)) {
|
|
979
|
-
const kind = typedJs && isTypeAnnotation(comment) ? "directive" : classify(comment,
|
|
980
|
-
if (
|
|
981
|
-
|
|
982
|
-
reports.push({ comment, messageId: "emDash", fix: null });
|
|
842
|
+
const kind = typedJs && isTypeAnnotation(comment) ? "directive" : classify(comment, lookup);
|
|
843
|
+
if (isDeprecation(comment) && comment.value.includes(EM_DASH)) {
|
|
844
|
+
reports.push({ comment, messageId: "emDash", fix: null });
|
|
983
845
|
continue;
|
|
984
846
|
}
|
|
985
847
|
const messageId = MESSAGE_IDS[kind];
|
|
@@ -1014,37 +876,143 @@ var noComments = ESLintUtils2.RuleCreator.withoutDocs({
|
|
|
1014
876
|
}
|
|
1015
877
|
});
|
|
1016
878
|
|
|
879
|
+
// oneComponentPerClientFile.ts
|
|
880
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES16, ESLintUtils as ESLintUtils3 } from "@typescript-eslint/utils";
|
|
881
|
+
var unwrap = (node) => {
|
|
882
|
+
if (!node) return null;
|
|
883
|
+
if (!isComponentWrapper(node)) return node;
|
|
884
|
+
if (node.type === AST_NODE_TYPES16.CallExpression) return unwrap(node.arguments[0]);
|
|
885
|
+
if (node.type === AST_NODE_TYPES16.TSAsExpression || node.type === AST_NODE_TYPES16.TSSatisfiesExpression)
|
|
886
|
+
return unwrap(node.expression);
|
|
887
|
+
return node;
|
|
888
|
+
};
|
|
889
|
+
var functionOf = (init) => {
|
|
890
|
+
const node = unwrap(init);
|
|
891
|
+
return node?.type === AST_NODE_TYPES16.ArrowFunctionExpression || node?.type === AST_NODE_TYPES16.FunctionExpression ? node : null;
|
|
892
|
+
};
|
|
893
|
+
var declarationCandidates = (declaration, isExported) => {
|
|
894
|
+
if (declaration.type === AST_NODE_TYPES16.FunctionDeclaration)
|
|
895
|
+
return [{ node: declaration, fn: declaration, name: declaration.id?.name ?? "default", isExported }];
|
|
896
|
+
if (declaration.type !== AST_NODE_TYPES16.VariableDeclaration) return [];
|
|
897
|
+
return declaration.declarations.flatMap((declarator) => {
|
|
898
|
+
const fn = functionOf(declarator.init);
|
|
899
|
+
if (!fn || declarator.id.type !== AST_NODE_TYPES16.Identifier) return [];
|
|
900
|
+
return [{ node: declarator, fn, name: declarator.id.name, isExported }];
|
|
901
|
+
});
|
|
902
|
+
};
|
|
903
|
+
var statementCandidates = (statement) => {
|
|
904
|
+
if (statement.type === AST_NODE_TYPES16.ExportNamedDeclaration)
|
|
905
|
+
return statement.declaration ? declarationCandidates(statement.declaration, true) : [];
|
|
906
|
+
if (statement.type !== AST_NODE_TYPES16.ExportDefaultDeclaration)
|
|
907
|
+
return declarationCandidates(statement, false);
|
|
908
|
+
const { declaration } = statement;
|
|
909
|
+
if (declaration.type === AST_NODE_TYPES16.FunctionDeclaration)
|
|
910
|
+
return declarationCandidates(declaration, true);
|
|
911
|
+
const fn = functionOf(declaration);
|
|
912
|
+
return fn ? [{ node: statement, fn, name: "default", isExported: true }] : [];
|
|
913
|
+
};
|
|
914
|
+
var exportedLocalNames = (statement) => {
|
|
915
|
+
if (statement.type === AST_NODE_TYPES16.ExportNamedDeclaration && statement.exportKind === "type")
|
|
916
|
+
return [];
|
|
917
|
+
if (statement.type === AST_NODE_TYPES16.ExportNamedDeclaration && !statement.source)
|
|
918
|
+
return statement.specifiers.flatMap(
|
|
919
|
+
(specifier) => specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES16.Identifier ? [specifier.local.name] : []
|
|
920
|
+
);
|
|
921
|
+
if (statement.type !== AST_NODE_TYPES16.ExportDefaultDeclaration) return [];
|
|
922
|
+
const target = unwrap(statement.declaration);
|
|
923
|
+
return target?.type === AST_NODE_TYPES16.Identifier ? [target.name] : [];
|
|
924
|
+
};
|
|
925
|
+
var oneComponentPerClientFile = ESLintUtils3.RuleCreator.withoutDocs({
|
|
926
|
+
meta: {
|
|
927
|
+
type: "suggestion",
|
|
928
|
+
docs: {
|
|
929
|
+
description: "Disallow a module-level function beside the one exported component of a client module, unless its own body needs the browser."
|
|
930
|
+
},
|
|
931
|
+
schema: [],
|
|
932
|
+
messages: {
|
|
933
|
+
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."
|
|
934
|
+
}
|
|
935
|
+
},
|
|
936
|
+
defaultOptions: [],
|
|
937
|
+
create(context) {
|
|
938
|
+
const { sourceCode } = context;
|
|
939
|
+
return {
|
|
940
|
+
Program(program) {
|
|
941
|
+
if (!findUseClientDirective(program)) return;
|
|
942
|
+
const exportedNames = new Set(program.body.flatMap(exportedLocalNames));
|
|
943
|
+
const candidates = program.body.flatMap(statementCandidates).map((candidate) => ({
|
|
944
|
+
...candidate,
|
|
945
|
+
isExported: candidate.isExported || exportedNames.has(candidate.name)
|
|
946
|
+
}));
|
|
947
|
+
const component = candidates.find(
|
|
948
|
+
(candidate) => candidate.isExported && isComponentFunction(candidate.fn)
|
|
949
|
+
);
|
|
950
|
+
if (!component) return;
|
|
951
|
+
const classifier = createClassifier(sourceCode, false);
|
|
952
|
+
const { positionOf, variableOf } = classifier;
|
|
953
|
+
const walk = createClientWalk(sourceCode, classifier, true);
|
|
954
|
+
const isHookCallee = (callee) => isHookName(calleeName(callee)) || callee.type === AST_NODE_TYPES16.Identifier && isHookName(importedName(variableOf(callee, callee.name)));
|
|
955
|
+
const isHandedToClient = ({ identifier }) => {
|
|
956
|
+
const { parent } = identifier;
|
|
957
|
+
if (parent.type === AST_NODE_TYPES16.CallExpression)
|
|
958
|
+
return parent.arguments.some((argument) => argument === identifier) && isHookCallee(parent.callee);
|
|
959
|
+
if (parent.type !== AST_NODE_TYPES16.JSXExpressionContainer || parent.parent.type !== AST_NODE_TYPES16.JSXAttribute)
|
|
960
|
+
return false;
|
|
961
|
+
const attribute = parent.parent;
|
|
962
|
+
const key = attribute.name.type === AST_NODE_TYPES16.JSXIdentifier ? attribute.name.name : "";
|
|
963
|
+
return isEventHandler(key) || positionOf(attribute.parent) === "text" && isFunctionAttribute(key);
|
|
964
|
+
};
|
|
965
|
+
const isUsedByClient = (candidate) => sourceCode.getDeclaredVariables(candidate.node).some(
|
|
966
|
+
(variable) => variable.name === candidate.name && variable.references.some(isHandedToClient)
|
|
967
|
+
);
|
|
968
|
+
const readsBrowserGlobal = (fn) => sourceCode.getScope(fn).through.some(
|
|
969
|
+
(reference) => reference.isValueReference !== false && BROWSER_GLOBALS.has(reference.identifier.name) && !reference.resolved?.defs.length
|
|
970
|
+
);
|
|
971
|
+
for (const candidate of candidates) {
|
|
972
|
+
if (candidate === component || walk(candidate.fn) || readsBrowserGlobal(candidate.fn) || isUsedByClient(candidate))
|
|
973
|
+
continue;
|
|
974
|
+
context.report({
|
|
975
|
+
node: candidate.node,
|
|
976
|
+
messageId: "extra",
|
|
977
|
+
data: { component: component.name, name: candidate.name }
|
|
978
|
+
});
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
});
|
|
984
|
+
|
|
1017
985
|
// oneExportPerFile.ts
|
|
1018
|
-
import { AST_NODE_TYPES as
|
|
1019
|
-
var isTypeOnlyDeclaration = (declaration) => declaration?.type ===
|
|
986
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES17, ESLintUtils as ESLintUtils4 } from "@typescript-eslint/utils";
|
|
987
|
+
var isTypeOnlyDeclaration = (declaration) => declaration?.type === AST_NODE_TYPES17.TSInterfaceDeclaration || declaration?.type === AST_NODE_TYPES17.TSTypeAliasDeclaration || declaration?.type === AST_NODE_TYPES17.TSDeclareFunction;
|
|
1020
988
|
var declaratorEntries = (declaration) => declaration.declarations.map((declarator) => ({
|
|
1021
989
|
node: declarator,
|
|
1022
|
-
name: declarator.id.type ===
|
|
990
|
+
name: declarator.id.type === AST_NODE_TYPES17.Identifier ? declarator.id.name : "a destructured export"
|
|
1023
991
|
}));
|
|
1024
992
|
var declarationEntry = (declaration) => ({
|
|
1025
993
|
node: declaration,
|
|
1026
|
-
name: "id" in declaration && declaration.id?.type ===
|
|
994
|
+
name: "id" in declaration && declaration.id?.type === AST_NODE_TYPES17.Identifier ? declaration.id.name : "default"
|
|
1027
995
|
});
|
|
1028
996
|
var namedEntries = (node) => {
|
|
1029
997
|
if (node.exportKind === "type") return [];
|
|
1030
998
|
const { declaration, specifiers } = node;
|
|
1031
999
|
if (declaration) {
|
|
1032
1000
|
if (isTypeOnlyDeclaration(declaration)) return [];
|
|
1033
|
-
if (declaration.type ===
|
|
1001
|
+
if (declaration.type === AST_NODE_TYPES17.VariableDeclaration) return declaratorEntries(declaration);
|
|
1034
1002
|
return [declarationEntry(declaration)];
|
|
1035
1003
|
}
|
|
1036
1004
|
return specifiers.filter((specifier) => specifier.exportKind !== "type").map((specifier) => ({
|
|
1037
1005
|
node: specifier,
|
|
1038
|
-
name: specifier.exported.type ===
|
|
1006
|
+
name: specifier.exported.type === AST_NODE_TYPES17.Identifier ? specifier.exported.name : specifier.exported.value
|
|
1039
1007
|
}));
|
|
1040
1008
|
};
|
|
1041
1009
|
var exportEntries = (statement) => {
|
|
1042
|
-
if (statement.type ===
|
|
1043
|
-
if (statement.type ===
|
|
1044
|
-
return statement.declaration.type ===
|
|
1010
|
+
if (statement.type === AST_NODE_TYPES17.ExportNamedDeclaration) return namedEntries(statement);
|
|
1011
|
+
if (statement.type === AST_NODE_TYPES17.ExportDefaultDeclaration)
|
|
1012
|
+
return statement.declaration.type === AST_NODE_TYPES17.TSDeclareFunction ? [] : [{ node: statement, name: "default" }];
|
|
1045
1013
|
return [];
|
|
1046
1014
|
};
|
|
1047
|
-
var oneExportPerFile =
|
|
1015
|
+
var oneExportPerFile = ESLintUtils4.RuleCreator.withoutDocs({
|
|
1048
1016
|
meta: {
|
|
1049
1017
|
type: "suggestion",
|
|
1050
1018
|
docs: {
|
|
@@ -1073,7 +1041,7 @@ var oneExportPerFile = ESLintUtils3.RuleCreator.withoutDocs({
|
|
|
1073
1041
|
});
|
|
1074
1042
|
|
|
1075
1043
|
// oneLineComments.ts
|
|
1076
|
-
import { AST_TOKEN_TYPES as AST_TOKEN_TYPES3, ESLintUtils as
|
|
1044
|
+
import { AST_TOKEN_TYPES as AST_TOKEN_TYPES3, ESLintUtils as ESLintUtils5 } from "@typescript-eslint/utils";
|
|
1077
1045
|
var isBare = (comment) => comment.type === AST_TOKEN_TYPES3.Line && comment.value.trim() === "";
|
|
1078
1046
|
var collapse = (text) => text.replace(/\s+/gu, " ").trim();
|
|
1079
1047
|
var asLine = (body) => body ? `// ${body}` : null;
|
|
@@ -1109,7 +1077,7 @@ var isJsDoc = (comment, after) => {
|
|
|
1109
1077
|
if (!isComment(after)) return true;
|
|
1110
1078
|
return isDirective(after) || isDocShaped(after) && /^\*+\s*@/u.test(comment.value);
|
|
1111
1079
|
};
|
|
1112
|
-
var oneLineComments =
|
|
1080
|
+
var oneLineComments = ESLintUtils5.RuleCreator.withoutDocs({
|
|
1113
1081
|
meta: {
|
|
1114
1082
|
type: "layout",
|
|
1115
1083
|
docs: {
|
|
@@ -1120,9 +1088,9 @@ var oneLineComments = ESLintUtils4.RuleCreator.withoutDocs({
|
|
|
1120
1088
|
messages: {
|
|
1121
1089
|
adjacent: "Two comment lines are touching. A comment is one line, however long it runs: join them, or write one line per fact beside the code it describes.",
|
|
1122
1090
|
paragraphs: "A paragraph break inside a comment, a bare `//` between comment lines or an empty line inside a block, makes it a set of comments rather than one wrapped line, and joining it would bury every fact but the first. Write one line per fact beside the code it describes, or move the rationale to the README or the project MANIFEST.",
|
|
1123
|
-
block: "This block comment spans lines. A comment is one line, however long it runs: collapse it to one `//` line, or to one `/** \u2026 */` line when it
|
|
1091
|
+
block: "This block comment spans lines. A comment is one line, however long it runs: collapse it to one `//` line, or to one `/** \u2026 */` line when a tool reads it as JSDoc, or move the rationale to the README or the project MANIFEST.",
|
|
1124
1092
|
notDoc: "A block comment is for JSDoc and JSX only. Write this one as `//`, on its own line or at the end of one, or delete it if it is empty.",
|
|
1125
|
-
orphanDoc: "`/**`
|
|
1093
|
+
orphanDoc: "`/**` opens a JSDoc, which a tool reads only directly above the code it applies to. Move it there when a tool reads it, and delete it otherwise."
|
|
1126
1094
|
}
|
|
1127
1095
|
},
|
|
1128
1096
|
defaultOptions: [],
|
|
@@ -1212,15 +1180,15 @@ var oneLineComments = ESLintUtils4.RuleCreator.withoutDocs({
|
|
|
1212
1180
|
});
|
|
1213
1181
|
|
|
1214
1182
|
// staticJsxInClient.ts
|
|
1215
|
-
import { AST_NODE_TYPES as
|
|
1183
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES18, AST_TOKEN_TYPES as AST_TOKEN_TYPES4, ESLintUtils as ESLintUtils6 } from "@typescript-eslint/utils";
|
|
1216
1184
|
var DISABLE_KEYWORDS = ["eslint-disable-next-line", "eslint-disable-line", "eslint-disable"];
|
|
1217
|
-
var isJsx = (node) => node.type ===
|
|
1185
|
+
var isJsx = (node) => node.type === AST_NODE_TYPES18.JSXElement || node.type === AST_NODE_TYPES18.JSXFragment;
|
|
1218
1186
|
var isRenderedByComponent = (node) => {
|
|
1219
1187
|
let current = node.parent;
|
|
1220
1188
|
while (current && !isFunctionNode(current)) current = current.parent;
|
|
1221
1189
|
return !current || isComponentFunction(current);
|
|
1222
1190
|
};
|
|
1223
|
-
var staticJsxInClient =
|
|
1191
|
+
var staticJsxInClient = ESLintUtils6.RuleCreator.withoutDocs({
|
|
1224
1192
|
meta: {
|
|
1225
1193
|
type: "suggestion",
|
|
1226
1194
|
docs: {
|
|
@@ -1263,14 +1231,14 @@ var staticJsxInClient = ESLintUtils5.RuleCreator.withoutDocs({
|
|
|
1263
1231
|
return verdict.data && verdict.stable;
|
|
1264
1232
|
};
|
|
1265
1233
|
const isStaticAttribute = (attribute, position) => {
|
|
1266
|
-
if (attribute.type !==
|
|
1267
|
-
const key = attribute.name.type ===
|
|
1234
|
+
if (attribute.type !== AST_NODE_TYPES18.JSXAttribute) return false;
|
|
1235
|
+
const key = attribute.name.type === AST_NODE_TYPES18.JSXIdentifier ? attribute.name.name : "";
|
|
1268
1236
|
if (isFunctionAttribute(key)) return false;
|
|
1269
1237
|
const { value } = attribute;
|
|
1270
|
-
if (!value || value.type ===
|
|
1271
|
-
return value.type ===
|
|
1238
|
+
if (!value || value.type === AST_NODE_TYPES18.Literal) return true;
|
|
1239
|
+
return value.type === AST_NODE_TYPES18.JSXExpressionContainer && isStatic(value.expression, position);
|
|
1272
1240
|
};
|
|
1273
|
-
const childPosition = (node) => node.type ===
|
|
1241
|
+
const childPosition = (node) => node.type === AST_NODE_TYPES18.JSXElement ? positionOf(node.openingElement) : "text";
|
|
1274
1242
|
const verdicts2 = /* @__PURE__ */ new Map();
|
|
1275
1243
|
const judge = (node) => {
|
|
1276
1244
|
const cached = verdicts2.get(node);
|
|
@@ -1278,7 +1246,7 @@ var staticJsxInClient = ESLintUtils5.RuleCreator.withoutDocs({
|
|
|
1278
1246
|
const position = childPosition(node);
|
|
1279
1247
|
let isStaticNode = true;
|
|
1280
1248
|
let count = 0;
|
|
1281
|
-
if (node.type ===
|
|
1249
|
+
if (node.type === AST_NODE_TYPES18.JSXElement) {
|
|
1282
1250
|
const { openingElement } = node;
|
|
1283
1251
|
const tag = classifyTag(openingElement);
|
|
1284
1252
|
isStaticNode = tag.data && tag.stable && openingElement.attributes.every((attribute) => isStaticAttribute(attribute, position));
|
|
@@ -1289,9 +1257,9 @@ var staticJsxInClient = ESLintUtils5.RuleCreator.withoutDocs({
|
|
|
1289
1257
|
const verdict2 = judge(child);
|
|
1290
1258
|
isStaticNode &&= verdict2.isStatic;
|
|
1291
1259
|
count += verdict2.count;
|
|
1292
|
-
} else if (child.type ===
|
|
1260
|
+
} else if (child.type === AST_NODE_TYPES18.JSXExpressionContainer)
|
|
1293
1261
|
isStaticNode &&= isStatic(child.expression, position);
|
|
1294
|
-
else if (child.type !==
|
|
1262
|
+
else if (child.type !== AST_NODE_TYPES18.JSXText) isStaticNode = false;
|
|
1295
1263
|
}
|
|
1296
1264
|
const verdict = { isStatic: isStaticNode, count };
|
|
1297
1265
|
verdicts2.set(node, verdict);
|
|
@@ -1320,9 +1288,9 @@ var staticJsxInClient = ESLintUtils5.RuleCreator.withoutDocs({
|
|
|
1320
1288
|
else if (isJsx(child)) {
|
|
1321
1289
|
flush();
|
|
1322
1290
|
visit(child);
|
|
1323
|
-
} else if (child.type ===
|
|
1291
|
+
} else if (child.type === AST_NODE_TYPES18.JSXExpressionContainer && !isStatic(child.expression, position))
|
|
1324
1292
|
flush();
|
|
1325
|
-
else if (child.type ===
|
|
1293
|
+
else if (child.type === AST_NODE_TYPES18.JSXSpreadChild) flush();
|
|
1326
1294
|
}
|
|
1327
1295
|
flush();
|
|
1328
1296
|
};
|
|
@@ -1341,7 +1309,8 @@ var plugin = {
|
|
|
1341
1309
|
"no-comments": noComments,
|
|
1342
1310
|
"no-needless-use-client": needlessUseClient,
|
|
1343
1311
|
"no-static-jsx-in-client": staticJsxInClient,
|
|
1344
|
-
"one-export-per-file": oneExportPerFile
|
|
1312
|
+
"one-export-per-file": oneExportPerFile,
|
|
1313
|
+
"one-component-per-client-file": oneComponentPerClientFile
|
|
1345
1314
|
}
|
|
1346
1315
|
};
|
|
1347
1316
|
var soujvnunesPlugin = plugin;
|
|
@@ -1624,7 +1593,8 @@ var buildConfig = ({
|
|
|
1624
1593
|
plugins: { soujvnunes: soujvnunesPlugin },
|
|
1625
1594
|
rules: {
|
|
1626
1595
|
"soujvnunes/no-needless-use-client": "error",
|
|
1627
|
-
"soujvnunes/no-static-jsx-in-client": "error"
|
|
1596
|
+
"soujvnunes/no-static-jsx-in-client": "error",
|
|
1597
|
+
"soujvnunes/one-component-per-client-file": "error"
|
|
1628
1598
|
}
|
|
1629
1599
|
};
|
|
1630
1600
|
const programBanRule = (message) => restrictedSyntaxRule(ALL_SELECTOR_KEYS, [
|