@soujvnunes/eslint-config 0.10.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 +2 -1
- package/dist/index.js +273 -142
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -75,10 +75,11 @@ These are the opinions most likely to surprise an existing codebase. All of them
|
|
|
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
|
|
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;
|
|
@@ -698,7 +721,7 @@ var createCommentLookup = (sourceCode) => {
|
|
|
698
721
|
const enclosingNode = (comment) => nodeAt(comment.range[0]);
|
|
699
722
|
const jsxContainer = (comment) => {
|
|
700
723
|
const node = enclosingNode(comment);
|
|
701
|
-
return node?.type ===
|
|
724
|
+
return node?.type === AST_NODE_TYPES14.JSXEmptyExpression ? node.parent : null;
|
|
702
725
|
};
|
|
703
726
|
const sidesOf = (span) => {
|
|
704
727
|
const { lines } = sourceCode;
|
|
@@ -724,16 +747,16 @@ var createCommentLookup = (sourceCode) => {
|
|
|
724
747
|
// noComments.ts
|
|
725
748
|
var JS_FILE = /\.[cm]?jsx?$/u;
|
|
726
749
|
var EM_DASH = String.fromCodePoint(8212);
|
|
727
|
-
var isJsxNode = (node) => !!node && node.type.startsWith("JSX") && node.type !==
|
|
750
|
+
var isJsxNode = (node) => !!node && node.type.startsWith("JSX") && node.type !== AST_NODE_TYPES15.JSXExpressionContainer;
|
|
728
751
|
var FUNCTION_NODES = /* @__PURE__ */ new Set([
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
752
|
+
AST_NODE_TYPES15.FunctionDeclaration,
|
|
753
|
+
AST_NODE_TYPES15.FunctionExpression,
|
|
754
|
+
AST_NODE_TYPES15.ArrowFunctionExpression
|
|
732
755
|
]);
|
|
733
756
|
var isEmptyBlock = (node) => {
|
|
734
|
-
if (node?.type ===
|
|
735
|
-
if (node?.type ===
|
|
736
|
-
return node?.type ===
|
|
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);
|
|
737
760
|
};
|
|
738
761
|
var classify = (comment, lookup) => {
|
|
739
762
|
const node = lookup.enclosingNode(comment);
|
|
@@ -742,7 +765,7 @@ var classify = (comment, lookup) => {
|
|
|
742
765
|
return inJsx ? "jsxDirective" : "directive";
|
|
743
766
|
}
|
|
744
767
|
if (isBanner(comment)) return "banner";
|
|
745
|
-
if (inJsx) return node?.type ===
|
|
768
|
+
if (inJsx) return node?.type === AST_NODE_TYPES15.JSXEmptyExpression ? "jsx" : "attribute";
|
|
746
769
|
if (isDocShaped(comment)) return "jsdoc";
|
|
747
770
|
return comment.type === AST_TOKEN_TYPES2.Line ? "line" : "block";
|
|
748
771
|
};
|
|
@@ -853,37 +876,143 @@ var noComments = ESLintUtils2.RuleCreator.withoutDocs({
|
|
|
853
876
|
}
|
|
854
877
|
});
|
|
855
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
|
+
|
|
856
985
|
// oneExportPerFile.ts
|
|
857
|
-
import { AST_NODE_TYPES as
|
|
858
|
-
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;
|
|
859
988
|
var declaratorEntries = (declaration) => declaration.declarations.map((declarator) => ({
|
|
860
989
|
node: declarator,
|
|
861
|
-
name: declarator.id.type ===
|
|
990
|
+
name: declarator.id.type === AST_NODE_TYPES17.Identifier ? declarator.id.name : "a destructured export"
|
|
862
991
|
}));
|
|
863
992
|
var declarationEntry = (declaration) => ({
|
|
864
993
|
node: declaration,
|
|
865
|
-
name: "id" in declaration && declaration.id?.type ===
|
|
994
|
+
name: "id" in declaration && declaration.id?.type === AST_NODE_TYPES17.Identifier ? declaration.id.name : "default"
|
|
866
995
|
});
|
|
867
996
|
var namedEntries = (node) => {
|
|
868
997
|
if (node.exportKind === "type") return [];
|
|
869
998
|
const { declaration, specifiers } = node;
|
|
870
999
|
if (declaration) {
|
|
871
1000
|
if (isTypeOnlyDeclaration(declaration)) return [];
|
|
872
|
-
if (declaration.type ===
|
|
1001
|
+
if (declaration.type === AST_NODE_TYPES17.VariableDeclaration) return declaratorEntries(declaration);
|
|
873
1002
|
return [declarationEntry(declaration)];
|
|
874
1003
|
}
|
|
875
1004
|
return specifiers.filter((specifier) => specifier.exportKind !== "type").map((specifier) => ({
|
|
876
1005
|
node: specifier,
|
|
877
|
-
name: specifier.exported.type ===
|
|
1006
|
+
name: specifier.exported.type === AST_NODE_TYPES17.Identifier ? specifier.exported.name : specifier.exported.value
|
|
878
1007
|
}));
|
|
879
1008
|
};
|
|
880
1009
|
var exportEntries = (statement) => {
|
|
881
|
-
if (statement.type ===
|
|
882
|
-
if (statement.type ===
|
|
883
|
-
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" }];
|
|
884
1013
|
return [];
|
|
885
1014
|
};
|
|
886
|
-
var oneExportPerFile =
|
|
1015
|
+
var oneExportPerFile = ESLintUtils4.RuleCreator.withoutDocs({
|
|
887
1016
|
meta: {
|
|
888
1017
|
type: "suggestion",
|
|
889
1018
|
docs: {
|
|
@@ -912,7 +1041,7 @@ var oneExportPerFile = ESLintUtils3.RuleCreator.withoutDocs({
|
|
|
912
1041
|
});
|
|
913
1042
|
|
|
914
1043
|
// oneLineComments.ts
|
|
915
|
-
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";
|
|
916
1045
|
var isBare = (comment) => comment.type === AST_TOKEN_TYPES3.Line && comment.value.trim() === "";
|
|
917
1046
|
var collapse = (text) => text.replace(/\s+/gu, " ").trim();
|
|
918
1047
|
var asLine = (body) => body ? `// ${body}` : null;
|
|
@@ -948,7 +1077,7 @@ var isJsDoc = (comment, after) => {
|
|
|
948
1077
|
if (!isComment(after)) return true;
|
|
949
1078
|
return isDirective(after) || isDocShaped(after) && /^\*+\s*@/u.test(comment.value);
|
|
950
1079
|
};
|
|
951
|
-
var oneLineComments =
|
|
1080
|
+
var oneLineComments = ESLintUtils5.RuleCreator.withoutDocs({
|
|
952
1081
|
meta: {
|
|
953
1082
|
type: "layout",
|
|
954
1083
|
docs: {
|
|
@@ -1051,15 +1180,15 @@ var oneLineComments = ESLintUtils4.RuleCreator.withoutDocs({
|
|
|
1051
1180
|
});
|
|
1052
1181
|
|
|
1053
1182
|
// staticJsxInClient.ts
|
|
1054
|
-
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";
|
|
1055
1184
|
var DISABLE_KEYWORDS = ["eslint-disable-next-line", "eslint-disable-line", "eslint-disable"];
|
|
1056
|
-
var isJsx = (node) => node.type ===
|
|
1185
|
+
var isJsx = (node) => node.type === AST_NODE_TYPES18.JSXElement || node.type === AST_NODE_TYPES18.JSXFragment;
|
|
1057
1186
|
var isRenderedByComponent = (node) => {
|
|
1058
1187
|
let current = node.parent;
|
|
1059
1188
|
while (current && !isFunctionNode(current)) current = current.parent;
|
|
1060
1189
|
return !current || isComponentFunction(current);
|
|
1061
1190
|
};
|
|
1062
|
-
var staticJsxInClient =
|
|
1191
|
+
var staticJsxInClient = ESLintUtils6.RuleCreator.withoutDocs({
|
|
1063
1192
|
meta: {
|
|
1064
1193
|
type: "suggestion",
|
|
1065
1194
|
docs: {
|
|
@@ -1102,14 +1231,14 @@ var staticJsxInClient = ESLintUtils5.RuleCreator.withoutDocs({
|
|
|
1102
1231
|
return verdict.data && verdict.stable;
|
|
1103
1232
|
};
|
|
1104
1233
|
const isStaticAttribute = (attribute, position) => {
|
|
1105
|
-
if (attribute.type !==
|
|
1106
|
-
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 : "";
|
|
1107
1236
|
if (isFunctionAttribute(key)) return false;
|
|
1108
1237
|
const { value } = attribute;
|
|
1109
|
-
if (!value || value.type ===
|
|
1110
|
-
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);
|
|
1111
1240
|
};
|
|
1112
|
-
const childPosition = (node) => node.type ===
|
|
1241
|
+
const childPosition = (node) => node.type === AST_NODE_TYPES18.JSXElement ? positionOf(node.openingElement) : "text";
|
|
1113
1242
|
const verdicts2 = /* @__PURE__ */ new Map();
|
|
1114
1243
|
const judge = (node) => {
|
|
1115
1244
|
const cached = verdicts2.get(node);
|
|
@@ -1117,7 +1246,7 @@ var staticJsxInClient = ESLintUtils5.RuleCreator.withoutDocs({
|
|
|
1117
1246
|
const position = childPosition(node);
|
|
1118
1247
|
let isStaticNode = true;
|
|
1119
1248
|
let count = 0;
|
|
1120
|
-
if (node.type ===
|
|
1249
|
+
if (node.type === AST_NODE_TYPES18.JSXElement) {
|
|
1121
1250
|
const { openingElement } = node;
|
|
1122
1251
|
const tag = classifyTag(openingElement);
|
|
1123
1252
|
isStaticNode = tag.data && tag.stable && openingElement.attributes.every((attribute) => isStaticAttribute(attribute, position));
|
|
@@ -1128,9 +1257,9 @@ var staticJsxInClient = ESLintUtils5.RuleCreator.withoutDocs({
|
|
|
1128
1257
|
const verdict2 = judge(child);
|
|
1129
1258
|
isStaticNode &&= verdict2.isStatic;
|
|
1130
1259
|
count += verdict2.count;
|
|
1131
|
-
} else if (child.type ===
|
|
1260
|
+
} else if (child.type === AST_NODE_TYPES18.JSXExpressionContainer)
|
|
1132
1261
|
isStaticNode &&= isStatic(child.expression, position);
|
|
1133
|
-
else if (child.type !==
|
|
1262
|
+
else if (child.type !== AST_NODE_TYPES18.JSXText) isStaticNode = false;
|
|
1134
1263
|
}
|
|
1135
1264
|
const verdict = { isStatic: isStaticNode, count };
|
|
1136
1265
|
verdicts2.set(node, verdict);
|
|
@@ -1159,9 +1288,9 @@ var staticJsxInClient = ESLintUtils5.RuleCreator.withoutDocs({
|
|
|
1159
1288
|
else if (isJsx(child)) {
|
|
1160
1289
|
flush();
|
|
1161
1290
|
visit(child);
|
|
1162
|
-
} else if (child.type ===
|
|
1291
|
+
} else if (child.type === AST_NODE_TYPES18.JSXExpressionContainer && !isStatic(child.expression, position))
|
|
1163
1292
|
flush();
|
|
1164
|
-
else if (child.type ===
|
|
1293
|
+
else if (child.type === AST_NODE_TYPES18.JSXSpreadChild) flush();
|
|
1165
1294
|
}
|
|
1166
1295
|
flush();
|
|
1167
1296
|
};
|
|
@@ -1180,7 +1309,8 @@ var plugin = {
|
|
|
1180
1309
|
"no-comments": noComments,
|
|
1181
1310
|
"no-needless-use-client": needlessUseClient,
|
|
1182
1311
|
"no-static-jsx-in-client": staticJsxInClient,
|
|
1183
|
-
"one-export-per-file": oneExportPerFile
|
|
1312
|
+
"one-export-per-file": oneExportPerFile,
|
|
1313
|
+
"one-component-per-client-file": oneComponentPerClientFile
|
|
1184
1314
|
}
|
|
1185
1315
|
};
|
|
1186
1316
|
var soujvnunesPlugin = plugin;
|
|
@@ -1463,7 +1593,8 @@ var buildConfig = ({
|
|
|
1463
1593
|
plugins: { soujvnunes: soujvnunesPlugin },
|
|
1464
1594
|
rules: {
|
|
1465
1595
|
"soujvnunes/no-needless-use-client": "error",
|
|
1466
|
-
"soujvnunes/no-static-jsx-in-client": "error"
|
|
1596
|
+
"soujvnunes/no-static-jsx-in-client": "error",
|
|
1597
|
+
"soujvnunes/one-component-per-client-file": "error"
|
|
1467
1598
|
}
|
|
1468
1599
|
};
|
|
1469
1600
|
const programBanRule = (message) => restrictedSyntaxRule(ALL_SELECTOR_KEYS, [
|