@eslint-react/core 5.28.7 → 5.30.0-beta.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/dist/index.d.ts +14 -46
- package/dist/index.js +28 -61
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { TSESTreeClass, TSESTreeDirective, TSESTreeFunction, TSESTreeMethodOrPropertyDefinition } from "@eslint-react/ast";
|
|
2
|
+
import { RuleContext } from "@eslint-react/eslint";
|
|
2
3
|
import { TSESTree } from "@typescript-eslint/types";
|
|
3
4
|
import { RegExpLike } from "@eslint-react/shared";
|
|
4
5
|
import ts from "typescript";
|
|
5
|
-
import { RuleContext } from "@eslint-react/eslint";
|
|
6
6
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
7
|
-
//#region src/api.d.ts
|
|
8
7
|
export declare namespace isAPI {
|
|
9
8
|
/** The dual-signature predicate type returned by {@link isAPI}. */
|
|
10
9
|
type ReturnType = {
|
|
@@ -165,16 +164,12 @@ export declare const isUseStateCall: isAPICall.ReturnType;
|
|
|
165
164
|
export declare const isUseSyncExternalStoreCall: isAPICall.ReturnType;
|
|
166
165
|
/** Check if the node is a call expression to the React `useTransition` API. */
|
|
167
166
|
export declare const isUseTransitionCall: isAPICall.ReturnType;
|
|
168
|
-
//#endregion
|
|
169
|
-
//#region src/class.d.ts
|
|
170
167
|
/**
|
|
171
168
|
* Get the class identifier of a class node.
|
|
172
169
|
* @param node The class node to get the identifier from.
|
|
173
170
|
* @returns The class identifier or `null` if not found.
|
|
174
171
|
*/
|
|
175
172
|
export declare function getClassId(node: TSESTreeClass): TSESTree.BindingName | null;
|
|
176
|
-
//#endregion
|
|
177
|
-
//#region src/semantic.d.ts
|
|
178
173
|
/**
|
|
179
174
|
* Represents a semantic node in the AST.
|
|
180
175
|
* This is the base interface for all semantic nodes in the React semantic analysis.
|
|
@@ -217,8 +212,6 @@ export interface SemanticFunc extends SemanticNode {
|
|
|
217
212
|
/** The type parameters of the function. */
|
|
218
213
|
typeParameters: TSESTree.TSTypeParameterDeclaration | null;
|
|
219
214
|
}
|
|
220
|
-
//#endregion
|
|
221
|
-
//#region src/class-component.d.ts
|
|
222
215
|
/**
|
|
223
216
|
* @deprecated Class components are legacy. This type exists only to support legacy rules.
|
|
224
217
|
*/
|
|
@@ -250,7 +243,7 @@ export declare function isClassComponent(node: TSESTree.Node): node is TSESTreeC
|
|
|
250
243
|
* @returns `true` if the node is a pure component.
|
|
251
244
|
* @deprecated Class components are legacy. This function exists only to support legacy rules.
|
|
252
245
|
*/
|
|
253
|
-
export declare function isPureComponent(node:
|
|
246
|
+
export declare function isPureComponent(node: TSESTreeClass): boolean;
|
|
254
247
|
/** @deprecated Class components are legacy. */
|
|
255
248
|
export declare const isRender: (node: TSESTree.Node) => node is TSESTreeMethodOrPropertyDefinition;
|
|
256
249
|
/** @deprecated Class components are legacy. */
|
|
@@ -315,8 +308,6 @@ export declare function isRenderMethodCallback(node: TSESTreeFunction): boolean;
|
|
|
315
308
|
* @deprecated Class components are legacy. This function exists only to support legacy rules.
|
|
316
309
|
*/
|
|
317
310
|
export declare function isThisSetStateCall(node: TSESTree.CallExpression): boolean;
|
|
318
|
-
//#endregion
|
|
319
|
-
//#region src/class-component-collector.d.ts
|
|
320
311
|
/**
|
|
321
312
|
* @deprecated Class components are legacy. This namespace exists only to support legacy rules.
|
|
322
313
|
*/
|
|
@@ -335,8 +326,6 @@ export declare namespace getClassComponentCollector {
|
|
|
335
326
|
* @deprecated Class components are legacy. This function exists only to support legacy rules.
|
|
336
327
|
*/
|
|
337
328
|
export declare function getClassComponentCollector(context: RuleContext): getClassComponentCollector.ReturnType;
|
|
338
|
-
//#endregion
|
|
339
|
-
//#region src/create-element.d.ts
|
|
340
329
|
/**
|
|
341
330
|
* Get the type argument (the first argument) of a `createElement` call.
|
|
342
331
|
* @param context The ESLint rule context.
|
|
@@ -398,8 +387,6 @@ export declare function isCreateElementChildrenArgument(context: RuleContext, no
|
|
|
398
387
|
* @returns `true` if the node is directly inside `createElement`'s props object.
|
|
399
388
|
*/
|
|
400
389
|
export declare function isInsideCreateElementProps(context: RuleContext, node: TSESTree.Node): boolean;
|
|
401
|
-
//#endregion
|
|
402
|
-
//#region src/function.d.ts
|
|
403
390
|
/** The return type of {@link getFunctionId}. */
|
|
404
391
|
export type FunctionID = ReturnType<typeof getFunctionId>;
|
|
405
392
|
/**
|
|
@@ -443,7 +430,7 @@ export type FunctionSemanticNode = ClientFunctionSemanticNode | ServerFunctionSe
|
|
|
443
430
|
* @param node The function node to analyze.
|
|
444
431
|
* @returns The identifier node if found, `null` otherwise.
|
|
445
432
|
*/
|
|
446
|
-
export declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.
|
|
433
|
+
export declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.ClassExpression | TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.CallExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.TemplateLiteral | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSTypeAssertion | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.ChainExpression | TSESTree.ConditionalExpression | TSESTree.ImportExpression | TSESTree.LogicalExpression | TSESTree.NewExpression | TSESTree.PrivateIdentifier | TSESTree.TSInstantiationExpression | TSESTree.TSSatisfiesExpression | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldNoStarExpression | TSESTree.YieldStarExpression | null;
|
|
447
434
|
/**
|
|
448
435
|
* Get the initialization path of a function node in the AST.
|
|
449
436
|
*
|
|
@@ -499,8 +486,6 @@ export type FunctionDisplayNameAssignment = TSESTree.AssignmentExpression & {
|
|
|
499
486
|
};
|
|
500
487
|
/** The esquery selector matching `displayName` assignment expressions with a statically determinable property name. */
|
|
501
488
|
export declare const SEL_FUNCTION_DISPLAY_NAME_ASSIGNMENT: string;
|
|
502
|
-
//#endregion
|
|
503
|
-
//#region src/hook.d.ts
|
|
504
489
|
/**
|
|
505
490
|
* Represents a semantic hook node in the AST.
|
|
506
491
|
*/
|
|
@@ -538,54 +523,52 @@ export declare function isHookId(id: TSESTree.Node): id is TSESTree.Identifier |
|
|
|
538
523
|
* @param tag The expression node to check.
|
|
539
524
|
* @returns `true` if the expression is a hook identifier or member expression with hook name, `false` otherwise.
|
|
540
525
|
*/
|
|
541
|
-
export declare function isHookTag(tag: TSESTree.Node
|
|
526
|
+
export declare function isHookTag(tag: TSESTree.Node): boolean;
|
|
542
527
|
/**
|
|
543
528
|
* Check if the function node is a hook definition based on its name.
|
|
544
529
|
* @param node The function node to check.
|
|
545
530
|
* @returns `true` if the function is a hook definition.
|
|
546
531
|
*/
|
|
547
|
-
export declare function isHookDefinition(node: TSESTreeFunction
|
|
532
|
+
export declare function isHookDefinition(node: TSESTreeFunction): boolean;
|
|
548
533
|
/**
|
|
549
534
|
* Check if the node is a React Hook call by its name.
|
|
550
535
|
* @param node The node to check.
|
|
551
536
|
* @returns `true` if the node is a React Hook call, `false` otherwise.
|
|
552
537
|
*/
|
|
553
|
-
export declare function isHookCall(node: TSESTree.
|
|
538
|
+
export declare function isHookCall(node: TSESTree.CallExpression): boolean;
|
|
554
539
|
/**
|
|
555
540
|
* Check if the node is a useRef-like call (ex: `useRef` or a custom ref hook).
|
|
556
541
|
* @param node The AST node to check.
|
|
557
542
|
* @param additionalRefHooks Regex pattern matching custom hooks that should be treated as ref hooks.
|
|
558
543
|
* @returns `true` if the node is a useRef-like call.
|
|
559
544
|
*/
|
|
560
|
-
export declare function isUseRefLikeCall(node: TSESTree.
|
|
545
|
+
export declare function isUseRefLikeCall(node: TSESTree.CallExpression, additionalRefHooks?: RegExpLike): boolean;
|
|
561
546
|
/**
|
|
562
547
|
* Check if the node is a useState-like call (ex: `useState` or a custom state hook).
|
|
563
548
|
* @param node The AST node to check.
|
|
564
549
|
* @param additionalStateHooks Regex pattern matching custom hooks that should be treated as state hooks.
|
|
565
550
|
* @returns `true` if the node is a useState-like call.
|
|
566
551
|
*/
|
|
567
|
-
export declare function isUseStateLikeCall(node: TSESTree.
|
|
552
|
+
export declare function isUseStateLikeCall(node: TSESTree.CallExpression, additionalStateHooks?: RegExpLike): boolean;
|
|
568
553
|
/**
|
|
569
554
|
* Check if the node is a useEffect-like call (ex: `useEffect`, `useLayoutEffect`, or a custom effect hook).
|
|
570
555
|
* @param node The AST node to check.
|
|
571
556
|
* @param additionalEffectHooks Regex pattern matching custom hooks that should be treated as effect hooks.
|
|
572
557
|
* @returns `true` if the node is a useEffect-like call.
|
|
573
558
|
*/
|
|
574
|
-
export declare function isUseEffectLikeCall(node: TSESTree.
|
|
559
|
+
export declare function isUseEffectLikeCall(node: TSESTree.CallExpression, additionalEffectHooks?: RegExpLike): boolean;
|
|
575
560
|
/**
|
|
576
561
|
* Check if the node is the setup callback passed to a useEffect-like call.
|
|
577
562
|
* @param node The AST node to check.
|
|
578
563
|
* @returns `true` if the node is a useEffect setup callback.
|
|
579
564
|
*/
|
|
580
|
-
export declare function isUseEffectSetupCallback(node: TSESTree.Node
|
|
565
|
+
export declare function isUseEffectSetupCallback(node: TSESTree.Node): boolean;
|
|
581
566
|
/**
|
|
582
567
|
* Check if the node is the cleanup callback returned by a useEffect-like setup callback.
|
|
583
568
|
* @param node The AST node to check.
|
|
584
569
|
* @returns `true` if the node is a useEffect cleanup callback.
|
|
585
570
|
*/
|
|
586
|
-
export declare function isUseEffectCleanupCallback(node: TSESTree.Node
|
|
587
|
-
//#endregion
|
|
588
|
-
//#region src/function-component.d.ts
|
|
571
|
+
export declare function isUseEffectCleanupCallback(node: TSESTree.Node): boolean;
|
|
589
572
|
/**
|
|
590
573
|
* Represents a React Function Component.
|
|
591
574
|
*/
|
|
@@ -649,14 +632,14 @@ export declare function getFunctionComponentFlagFromInitPath(initPath: FunctionC
|
|
|
649
632
|
* @param node The node to check.
|
|
650
633
|
* @returns `true` if the node is a call expression for a component wrapper.
|
|
651
634
|
*/
|
|
652
|
-
export declare function isFunctionComponentWrapperCall(context: RuleContext, node: TSESTree.
|
|
635
|
+
export declare function isFunctionComponentWrapperCall(context: RuleContext, node: TSESTree.CallExpression): boolean;
|
|
653
636
|
/**
|
|
654
637
|
* Check if the node is a callback function passed to a component wrapper.
|
|
655
638
|
* @param context The ESLint rule context.
|
|
656
639
|
* @param node The node to check.
|
|
657
640
|
* @returns `true` if the node is a callback function passed to a component wrapper.
|
|
658
641
|
*/
|
|
659
|
-
export declare function isFunctionComponentWrapperCallback(context: RuleContext, node:
|
|
642
|
+
export declare function isFunctionComponentWrapperCallback(context: RuleContext, node: TSESTreeFunction): boolean;
|
|
660
643
|
/**
|
|
661
644
|
* Get function component identifier from `const Component = memo(() => {});`.
|
|
662
645
|
* @param context The rule context.
|
|
@@ -732,8 +715,6 @@ export declare const DEFAULT_COMPONENT_DETECTION_HINT: bigint;
|
|
|
732
715
|
* @returns `true` if the node is considered a component definition.
|
|
733
716
|
*/
|
|
734
717
|
export declare function isFunctionComponentDefinition(context: RuleContext, node: TSESTreeFunction, hint: bigint): boolean;
|
|
735
|
-
//#endregion
|
|
736
|
-
//#region src/function-component-collector.d.ts
|
|
737
718
|
export declare namespace getFunctionComponentCollector {
|
|
738
719
|
/** The options for {@link getFunctionComponentCollector}. */
|
|
739
720
|
type Options = {
|
|
@@ -755,8 +736,6 @@ export declare namespace getFunctionComponentCollector {
|
|
|
755
736
|
* @returns The api and visitor of the collector.
|
|
756
737
|
*/
|
|
757
738
|
export declare function getFunctionComponentCollector(context: RuleContext, options?: getFunctionComponentCollector.Options): getFunctionComponentCollector.ReturnType;
|
|
758
|
-
//#endregion
|
|
759
|
-
//#region src/hook-collector.d.ts
|
|
760
739
|
export declare namespace getHookCollector {
|
|
761
740
|
/** The api and visitor pair returned by {@link getHookCollector}. */
|
|
762
741
|
type ReturnType = {
|
|
@@ -772,8 +751,6 @@ export declare namespace getHookCollector {
|
|
|
772
751
|
* @returns The api and visitor of the collector.
|
|
773
752
|
*/
|
|
774
753
|
export declare function getHookCollector(context: RuleContext): getHookCollector.ReturnType;
|
|
775
|
-
//#endregion
|
|
776
|
-
//#region src/jsx.d.ts
|
|
777
754
|
/**
|
|
778
755
|
* BitFlags for configuring JSX detection behavior.
|
|
779
756
|
*
|
|
@@ -846,8 +823,6 @@ export declare const DEFAULT_JSX_DETECTION_HINT: JSXDetectionHint;
|
|
|
846
823
|
* ```
|
|
847
824
|
*/
|
|
848
825
|
export declare function isJSXLike(context: RuleContext, node: TSESTree.Node | null, hint?: JSXDetectionHint): boolean;
|
|
849
|
-
//#endregion
|
|
850
|
-
//#region src/jsx-config.d.ts
|
|
851
826
|
/**
|
|
852
827
|
* Resolved JSX configuration derived from compiler options and / or pragma
|
|
853
828
|
* annotations found in the source file.
|
|
@@ -896,8 +871,6 @@ export declare function getJSXConfigFromAnnotation(context: RuleContext): JSXCon
|
|
|
896
871
|
* @returns Fully‑populated, merged `JSXConfig`.
|
|
897
872
|
*/
|
|
898
873
|
export declare function getJSXConfig(context: RuleContext): Required<JSXConfig>;
|
|
899
|
-
//#endregion
|
|
900
|
-
//#region src/type-is.d.ts
|
|
901
874
|
/**
|
|
902
875
|
* Check if the type is a boolean literal type.
|
|
903
876
|
* @param type The type to check.
|
|
@@ -1063,8 +1036,6 @@ export declare const isTruthyStringType: (type: ts.Type) => boolean;
|
|
|
1063
1036
|
* @internal
|
|
1064
1037
|
*/
|
|
1065
1038
|
export declare const isUnknownType: (type: ts.Type) => boolean;
|
|
1066
|
-
//#endregion
|
|
1067
|
-
//#region src/type-name.d.ts
|
|
1068
1039
|
/**
|
|
1069
1040
|
* Get the fully qualified name of a symbol, handling cases that `ts.TypeChecker.getFullyQualifiedName` does not handle (ex: `export as namespace preact`).
|
|
1070
1041
|
* @param checker The TypeScript type checker.
|
|
@@ -1072,8 +1043,6 @@ export declare const isUnknownType: (type: ts.Type) => boolean;
|
|
|
1072
1043
|
* @returns The fully qualified name of the symbol.
|
|
1073
1044
|
*/
|
|
1074
1045
|
export declare function getFullyQualifiedNameEx(checker: ts.TypeChecker, symbol: ts.Symbol): string;
|
|
1075
|
-
//#endregion
|
|
1076
|
-
//#region src/type-variant.d.ts
|
|
1077
1046
|
/** Represents the variant of a type for boolean expression analysis. */
|
|
1078
1047
|
export type TypeVariant = "any" | "bigint" | "boolean" | "enum" | "never" | "nullish" | "number" | "object" | "string" | "unknown" | "falsy bigint" | "falsy boolean" | "falsy number" | "falsy string" | "truthy bigint" | "truthy boolean" | "truthy number" | "truthy string";
|
|
1079
1048
|
/**
|
|
@@ -1083,5 +1052,4 @@ export type TypeVariant = "any" | "bigint" | "boolean" | "enum" | "never" | "nul
|
|
|
1083
1052
|
* @remarks Ported from https://github.com/typescript-eslint/typescript-eslint/blob/eb736bbfc22554694400e6a4f97051d845d32e0b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts#L826 with some enhancements.
|
|
1084
1053
|
* @internal
|
|
1085
1054
|
*/
|
|
1086
|
-
export declare function getTypeVariants(types: ts.Type[]): Set<TypeVariant>;
|
|
1087
|
-
//#endregion
|
|
1055
|
+
export declare function getTypeVariants(types: ts.Type[]): Set<TypeVariant>;
|
package/dist/index.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import { Check, Extract, Traverse } from "@eslint-react/ast";
|
|
2
|
+
import { getText } from "@eslint-react/eslint";
|
|
2
3
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
3
4
|
import { RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE } from "@eslint-react/shared";
|
|
4
5
|
import { resolve } from "@eslint-react/var";
|
|
5
6
|
import { findVariable } from "@typescript-eslint/utils/ast-utils";
|
|
6
7
|
import { P, isMatching, match } from "ts-pattern";
|
|
7
8
|
import ts from "typescript";
|
|
8
|
-
|
|
9
|
+
// src/api.ts
|
|
9
10
|
function isAPI(api) {
|
|
10
|
-
|
|
11
|
+
function impl(context, node) {
|
|
11
12
|
if (node == null) return false;
|
|
12
13
|
const expr = Extract.unwrap(node);
|
|
13
|
-
const
|
|
14
|
-
const name = Extract.getFullyQualifiedName(expr, getText);
|
|
14
|
+
const name = Extract.getFullyQualifiedName(expr, getText(context));
|
|
15
15
|
return name === api || name.endsWith(`.${api}`);
|
|
16
|
-
}
|
|
16
|
+
}
|
|
17
17
|
function dual(context, ...rest) {
|
|
18
|
-
return rest.length === 1 ?
|
|
18
|
+
return rest.length === 1 ? impl(context, rest[0]) : (node) => impl(context, node);
|
|
19
19
|
}
|
|
20
20
|
return dual;
|
|
21
21
|
}
|
|
22
22
|
function isAPICall(api) {
|
|
23
|
-
|
|
23
|
+
function impl(context, node) {
|
|
24
24
|
if (node == null) return false;
|
|
25
25
|
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
26
26
|
return isAPI(api)(context, Extract.unwrap(node.callee));
|
|
27
|
-
}
|
|
27
|
+
}
|
|
28
28
|
function dual(context, ...rest) {
|
|
29
|
-
return rest.length === 1 ?
|
|
29
|
+
return rest.length === 1 ? impl(context, rest[0]) : (node) => impl(context, node);
|
|
30
30
|
}
|
|
31
31
|
return dual;
|
|
32
32
|
}
|
|
@@ -94,15 +94,13 @@ const isUseRefCall = isAPICall("useRef");
|
|
|
94
94
|
const isUseStateCall = isAPICall("useState");
|
|
95
95
|
const isUseSyncExternalStoreCall = isAPICall("useSyncExternalStore");
|
|
96
96
|
const isUseTransitionCall = isAPICall("useTransition");
|
|
97
|
-
|
|
98
|
-
//#region src/class.ts
|
|
97
|
+
// src/class.ts
|
|
99
98
|
function getClassId(node) {
|
|
100
99
|
if (node.id != null) return node.id;
|
|
101
100
|
if (node.parent.type === AST_NODE_TYPES.VariableDeclarator) return node.parent.id;
|
|
102
101
|
return null;
|
|
103
102
|
}
|
|
104
|
-
|
|
105
|
-
//#region ../../.pkgs/eff/dist/index.js
|
|
103
|
+
// ../../.pkgs/eff/dist/index.js
|
|
106
104
|
const pipeArguments = (self, args) => {
|
|
107
105
|
switch (args.length) {
|
|
108
106
|
case 0: return self;
|
|
@@ -201,8 +199,7 @@ dual(2, (self, predicate) => {
|
|
|
201
199
|
while (idx < len && predicate(input[idx], idx)) idx++;
|
|
202
200
|
return input.slice(0, idx);
|
|
203
201
|
});
|
|
204
|
-
|
|
205
|
-
//#region src/class-component.ts
|
|
202
|
+
// src/class-component.ts
|
|
206
203
|
function getStaticKeyName(key, computed) {
|
|
207
204
|
if (!computed && Check.isIdentifier(key)) return key.name;
|
|
208
205
|
if (key.type === AST_NODE_TYPES.Literal && isString(key.value)) return key.value;
|
|
@@ -222,7 +219,7 @@ function isClassComponent(node) {
|
|
|
222
219
|
return false;
|
|
223
220
|
}
|
|
224
221
|
function isPureComponent(node) {
|
|
225
|
-
if (
|
|
222
|
+
if (node.superClass != null) {
|
|
226
223
|
const re = /^PureComponent$/u;
|
|
227
224
|
switch (true) {
|
|
228
225
|
case Check.isIdentifier(node.superClass): return re.test(node.superClass.name);
|
|
@@ -269,16 +266,14 @@ function isThisSetStateCall(node) {
|
|
|
269
266
|
const callee = Extract.unwrap(node.callee);
|
|
270
267
|
return callee.type === AST_NODE_TYPES.MemberExpression && Extract.unwrap(callee.object).type === AST_NODE_TYPES.ThisExpression && Extract.getCalleeName(node) === "setState";
|
|
271
268
|
}
|
|
272
|
-
|
|
273
|
-
//#region src/class-component-collector.ts
|
|
269
|
+
// src/class-component-collector.ts
|
|
274
270
|
function getClassComponentCollector(context) {
|
|
275
271
|
const components = /* @__PURE__ */ new Map();
|
|
276
|
-
const getText = (n) => context.sourceCode.getText(n);
|
|
277
272
|
const collect = (node) => {
|
|
278
273
|
if (!isClassComponent(node)) return;
|
|
279
274
|
const id = getClassId(node);
|
|
280
275
|
const key = node.range[0];
|
|
281
|
-
const name = id == null ? null : Extract.getFullyQualifiedName(id, getText);
|
|
276
|
+
const name = id == null ? null : Extract.getFullyQualifiedName(id, getText(context));
|
|
282
277
|
components.set(key, {
|
|
283
278
|
id,
|
|
284
279
|
key,
|
|
@@ -301,8 +296,7 @@ function getClassComponentCollector(context) {
|
|
|
301
296
|
}
|
|
302
297
|
};
|
|
303
298
|
}
|
|
304
|
-
|
|
305
|
-
//#region src/create-element.ts
|
|
299
|
+
// src/create-element.ts
|
|
306
300
|
function getCreateElementTypeArgument(context, node) {
|
|
307
301
|
if (!isCreateElementCall(context, node)) return null;
|
|
308
302
|
return node.arguments[0] ?? null;
|
|
@@ -338,8 +332,7 @@ function isInsideCreateElementProps(context, node) {
|
|
|
338
332
|
if (propsArg == null) return false;
|
|
339
333
|
return prop === Extract.unwrap(propsArg);
|
|
340
334
|
}
|
|
341
|
-
|
|
342
|
-
//#region src/function.ts
|
|
335
|
+
// src/function.ts
|
|
343
336
|
function getFunctionId(node) {
|
|
344
337
|
switch (true) {
|
|
345
338
|
case hasProperty(node, "id") && node.id != null: return node.id;
|
|
@@ -439,8 +432,7 @@ const SEL_FUNCTION_DISPLAY_NAME_ASSIGNMENT = [
|
|
|
439
432
|
"[left.computed=true][left.property.type='Literal'][left.property.value='displayName']",
|
|
440
433
|
")"
|
|
441
434
|
].join("");
|
|
442
|
-
|
|
443
|
-
//#region src/jsx.ts
|
|
435
|
+
// src/jsx.ts
|
|
444
436
|
const JSXDetectionHint = {
|
|
445
437
|
None: 0n,
|
|
446
438
|
DoNotIncludeJSXWithNullValue: 1n << 0n,
|
|
@@ -495,8 +487,7 @@ function isJSXLike(context, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
|
495
487
|
}
|
|
496
488
|
return visit(node);
|
|
497
489
|
}
|
|
498
|
-
|
|
499
|
-
//#region src/function-component.ts
|
|
490
|
+
// src/function-component.ts
|
|
500
491
|
const FunctionComponentFlag = {
|
|
501
492
|
None: 0n,
|
|
502
493
|
PureComponent: 1n << 0n,
|
|
@@ -511,11 +502,9 @@ function getFunctionComponentFlagFromInitPath(initPath) {
|
|
|
511
502
|
return flag;
|
|
512
503
|
}
|
|
513
504
|
function isFunctionComponentWrapperCall(context, node) {
|
|
514
|
-
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
515
505
|
return isMemoCall(context, node) || isForwardRefCall(context, node);
|
|
516
506
|
}
|
|
517
507
|
function isFunctionComponentWrapperCallback(context, node) {
|
|
518
|
-
if (!Check.isFunction(node)) return false;
|
|
519
508
|
let argument = node;
|
|
520
509
|
let parent = node.parent;
|
|
521
510
|
while (Check.isTypeExpression(parent)) {
|
|
@@ -603,8 +592,7 @@ function isFunctionComponentDefinition(context, node, hint) {
|
|
|
603
592
|
if (significantParent == null) return true;
|
|
604
593
|
return significantParent.type !== AST_NODE_TYPES.JSXExpressionContainer;
|
|
605
594
|
}
|
|
606
|
-
|
|
607
|
-
//#region src/hook.ts
|
|
595
|
+
// src/hook.ts
|
|
608
596
|
function isHookName(name) {
|
|
609
597
|
return name === "use" || /^use[A-Z0-9]/.test(name);
|
|
610
598
|
}
|
|
@@ -616,11 +604,9 @@ function isHookId(id) {
|
|
|
616
604
|
}
|
|
617
605
|
}
|
|
618
606
|
function isHookTag(tag) {
|
|
619
|
-
if (tag == null) return false;
|
|
620
607
|
return isHookId(Extract.unwrap(tag));
|
|
621
608
|
}
|
|
622
609
|
function isHookDefinition(node) {
|
|
623
|
-
if (node == null) return false;
|
|
624
610
|
const id = getFunctionId(node);
|
|
625
611
|
switch (id?.type) {
|
|
626
612
|
case AST_NODE_TYPES.Identifier: return isHookName(id.name);
|
|
@@ -629,35 +615,26 @@ function isHookDefinition(node) {
|
|
|
629
615
|
}
|
|
630
616
|
}
|
|
631
617
|
function isHookCall(node) {
|
|
632
|
-
if (node == null) return false;
|
|
633
|
-
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
634
618
|
const name = Extract.getCalleeName(node);
|
|
635
619
|
if (name == null) return false;
|
|
636
620
|
return isHookName(name);
|
|
637
621
|
}
|
|
638
622
|
function isUseRefLikeCall(node, additionalRefHooks = { test: constFalse }) {
|
|
639
|
-
if (node == null) return false;
|
|
640
|
-
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
641
623
|
const name = Extract.getCalleeName(node);
|
|
642
624
|
if (name == null) return false;
|
|
643
625
|
return name === "useRef" || additionalRefHooks.test(name);
|
|
644
626
|
}
|
|
645
627
|
function isUseStateLikeCall(node, additionalStateHooks = { test: constFalse }) {
|
|
646
|
-
if (node == null) return false;
|
|
647
|
-
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
648
628
|
const name = Extract.getCalleeName(node);
|
|
649
629
|
if (name == null) return false;
|
|
650
630
|
return name === "useState" || additionalStateHooks.test(name);
|
|
651
631
|
}
|
|
652
632
|
function isUseEffectLikeCall(node, additionalEffectHooks = { test: constFalse }) {
|
|
653
|
-
if (node == null) return false;
|
|
654
|
-
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
655
633
|
const name = Extract.getCalleeName(node);
|
|
656
634
|
if (name == null) return false;
|
|
657
635
|
return /^use\w*Effect$/u.test(name) || additionalEffectHooks.test(name);
|
|
658
636
|
}
|
|
659
637
|
function isUseEffectSetupCallback(node) {
|
|
660
|
-
if (node == null) return false;
|
|
661
638
|
const expr = Extract.unwrap(node);
|
|
662
639
|
const call = Traverse.findParent(expr, not(Check.isTypeOrChainExpression));
|
|
663
640
|
if (call?.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
@@ -666,7 +643,6 @@ function isUseEffectSetupCallback(node) {
|
|
|
666
643
|
return Extract.unwrap(arg0) === expr && isUseEffectLikeCall(call);
|
|
667
644
|
}
|
|
668
645
|
function isUseEffectCleanupCallback(node) {
|
|
669
|
-
if (node == null) return false;
|
|
670
646
|
const expr = Extract.unwrap(node);
|
|
671
647
|
const func = Traverse.findParent(expr, Check.isFunction);
|
|
672
648
|
if (func == null || !isUseEffectSetupCallback(func)) return false;
|
|
@@ -674,13 +650,11 @@ function isUseEffectCleanupCallback(node) {
|
|
|
674
650
|
if (stat != null) return stat.argument != null && Extract.unwrap(stat.argument) === expr;
|
|
675
651
|
return Check.isFunction(expr) && func.type === AST_NODE_TYPES.ArrowFunctionExpression && Extract.unwrap(func.body) === expr;
|
|
676
652
|
}
|
|
677
|
-
|
|
678
|
-
//#region src/function-component-collector.ts
|
|
653
|
+
// src/function-component-collector.ts
|
|
679
654
|
function getFunctionComponentCollector(context, options = {}) {
|
|
680
655
|
const { collectDisplayName = false, hint = DEFAULT_COMPONENT_DETECTION_HINT } = options;
|
|
681
656
|
const functionEntries = [];
|
|
682
657
|
const components = /* @__PURE__ */ new Map();
|
|
683
|
-
const getText = (n) => context.sourceCode.getText(n);
|
|
684
658
|
const getCurrentEntry = () => functionEntries.at(-1) ?? null;
|
|
685
659
|
const onFunctionEnter = (node) => {
|
|
686
660
|
const key = node.range[0];
|
|
@@ -688,7 +662,7 @@ function getFunctionComponentCollector(context, options = {}) {
|
|
|
688
662
|
const isExportDefault = exp != null;
|
|
689
663
|
const isExportDefaultDeclaration = exp != null && Extract.unwrap(exp.declaration) === node;
|
|
690
664
|
const id = getFunctionComponentId(context, node);
|
|
691
|
-
const name = id == null ? null : Extract.getFullyQualifiedName(id, getText);
|
|
665
|
+
const name = id == null ? null : Extract.getFullyQualifiedName(id, getText(context));
|
|
692
666
|
const initPath = getFunctionInitPath(node);
|
|
693
667
|
const directives = getFunctionDirectives(node);
|
|
694
668
|
const entry = {
|
|
@@ -767,12 +741,10 @@ function getFunctionComponentCollector(context, options = {}) {
|
|
|
767
741
|
}
|
|
768
742
|
};
|
|
769
743
|
}
|
|
770
|
-
|
|
771
|
-
//#region src/hook-collector.ts
|
|
744
|
+
// src/hook-collector.ts
|
|
772
745
|
function getHookCollector(context) {
|
|
773
746
|
const functionEntries = [];
|
|
774
747
|
const hooks = /* @__PURE__ */ new Map();
|
|
775
|
-
const getText = (n) => context.sourceCode.getText(n);
|
|
776
748
|
const getCurrentEntry = () => functionEntries.at(-1) ?? null;
|
|
777
749
|
const getCurrentHookEntry = () => functionEntries.findLast((entry) => entry.isHookDefinition) ?? null;
|
|
778
750
|
const onFunctionEnter = (node) => {
|
|
@@ -781,7 +753,7 @@ function getHookCollector(context) {
|
|
|
781
753
|
id,
|
|
782
754
|
key: node.range[0],
|
|
783
755
|
kind: "hook",
|
|
784
|
-
name: id == null ? null : Extract.getFullyQualifiedName(id, getText),
|
|
756
|
+
name: id == null ? null : Extract.getFullyQualifiedName(id, getText(context)),
|
|
785
757
|
directives: getFunctionDirectives(node),
|
|
786
758
|
flag: 0n,
|
|
787
759
|
hint: 0n,
|
|
@@ -831,8 +803,7 @@ function getHookCollector(context) {
|
|
|
831
803
|
}
|
|
832
804
|
};
|
|
833
805
|
}
|
|
834
|
-
|
|
835
|
-
//#region src/jsx-config.ts
|
|
806
|
+
// src/jsx-config.ts
|
|
836
807
|
const annotationCache = /* @__PURE__ */ new WeakMap();
|
|
837
808
|
const mergedCache = /* @__PURE__ */ new WeakMap();
|
|
838
809
|
function getJSXConfigFromCompilerOptions(context) {
|
|
@@ -878,8 +849,7 @@ function getJSXConfig(context) {
|
|
|
878
849
|
mergedCache.set(context.sourceCode, merged);
|
|
879
850
|
return merged;
|
|
880
851
|
}
|
|
881
|
-
|
|
882
|
-
//#region src/type-is.ts
|
|
852
|
+
// src/type-is.ts
|
|
883
853
|
function isFlagSet(allFlags, flag) {
|
|
884
854
|
return (allFlags & flag) !== 0;
|
|
885
855
|
}
|
|
@@ -906,8 +876,7 @@ const isTruthyBigIntType = (type) => type.isLiteral() && isMatching({ value: { b
|
|
|
906
876
|
const isTruthyNumberType = (type) => type.isNumberLiteral() && type.value !== 0;
|
|
907
877
|
const isTruthyStringType = (type) => type.isStringLiteral() && type.value !== "";
|
|
908
878
|
const isUnknownType = (type) => isTypeFlagSet(type, ts.TypeFlags.Unknown);
|
|
909
|
-
|
|
910
|
-
//#region src/type-name.ts
|
|
879
|
+
// src/type-name.ts
|
|
911
880
|
function getFullyQualifiedNameEx(checker, symbol) {
|
|
912
881
|
let name = symbol.name;
|
|
913
882
|
let parent = symbol.declarations?.at(0)?.parent;
|
|
@@ -951,8 +920,7 @@ function getFullyQualifiedNameEx(checker, symbol) {
|
|
|
951
920
|
if (name.startsWith(`${namespace}.`)) return name;
|
|
952
921
|
return `${namespace}.${name}`;
|
|
953
922
|
}
|
|
954
|
-
|
|
955
|
-
//#region src/type-variant.ts
|
|
923
|
+
// src/type-variant.ts
|
|
956
924
|
function getTypeVariants(types) {
|
|
957
925
|
const variants = /* @__PURE__ */ new Set();
|
|
958
926
|
if (types.some(isUnknownType)) {
|
|
@@ -988,5 +956,4 @@ function getTypeVariants(types) {
|
|
|
988
956
|
if (types.some(isNeverType)) variants.add("never");
|
|
989
957
|
return variants;
|
|
990
958
|
}
|
|
991
|
-
//#endregion
|
|
992
959
|
export { DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FunctionComponentDetectionHint, FunctionComponentFlag, JSXDetectionHint, SEL_FUNCTION_DISPLAY_NAME_ASSIGNMENT, getClassComponentCollector, getClassId, getCreateElementChildrenArguments, getCreateElementProp, getCreateElementPropsObject, getCreateElementTypeArgument, getFullyQualifiedNameEx, getFunctionComponentCollector, getFunctionComponentFlagFromInitPath, getFunctionComponentId, getFunctionDirectives, getFunctionId, getFunctionInitPath, getHookCollector, getJSXConfig, getJSXConfigFromAnnotation, getJSXConfigFromCompilerOptions, getTypeVariants, isAPI, isAPICall, isAnyType, isBigIntType, isBooleanLiteralType, isBooleanType, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateElementChildrenArgument, isCreateRef, isCreateRefCall, isEnumType, isFalseLiteralType, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isForwardRef, isForwardRefCall, isFunctionComponentDefinition, isFunctionComponentName, isFunctionComponentNameLoose, isFunctionComponentWrapperCall, isFunctionComponentWrapperCallback, isFunctionEmpty, isFunctionHasCallInInitPath, isFunctionHasDirective, isFunctionWithLooseComponentName, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHookCall, isHookDefinition, isHookId, isHookName, isHookTag, isInsideCreateElementProps, isJSXLike, isLazy, isLazyCall, isMemo, isMemoCall, isNeverType, isNullishType, isNumberType, isObjectType, isPureComponent, isRender, isRenderMethodCallback, isRenderMethodLike, isShouldComponentUpdate, isStringType, isThisSetStateCall, isTrueLiteralType, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUse, isUseActionState, isUseActionStateCall, isUseCall, isUseCallback, isUseCallbackCall, isUseContext, isUseContextCall, isUseDebugValue, isUseDebugValueCall, isUseDeferredValue, isUseDeferredValueCall, isUseEffect, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatus, isUseFormStatusCall, isUseId, isUseIdCall, isUseImperativeHandle, isUseImperativeHandleCall, isUseInsertionEffect, isUseInsertionEffectCall, isUseLayoutEffect, isUseLayoutEffectCall, isUseMemo, isUseMemoCall, isUseOptimistic, isUseOptimisticCall, isUseReducer, isUseReducerCall, isUseRef, isUseRefCall, isUseRefLikeCall, isUseState, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStore, isUseSyncExternalStoreCall, isUseTransition, isUseTransitionCall };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.30.0-beta.0",
|
|
4
4
|
"description": "ESLint React's ESLint utility module for static analysis of React core APIs and patterns.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@eslint-react/ast": "5.
|
|
33
|
-
"@eslint-react/eslint": "5.
|
|
34
|
-
"@eslint-react/shared": "5.
|
|
35
|
-
"@eslint-react/var": "5.
|
|
32
|
+
"@eslint-react/ast": "5.30.0-beta.0",
|
|
33
|
+
"@eslint-react/eslint": "5.30.0-beta.0",
|
|
34
|
+
"@eslint-react/shared": "5.30.0-beta.0",
|
|
35
|
+
"@eslint-react/var": "5.30.0-beta.0",
|
|
36
36
|
"@typescript-eslint/types": "^8.72.0",
|
|
37
37
|
"@typescript-eslint/utils": "^8.72.0",
|
|
38
38
|
"ts-pattern": "^5.9.2"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@typescript-eslint/typescript-estree": "^8.72.0",
|
|
47
47
|
"dedent": "^1.7.2",
|
|
48
48
|
"eslint": "^10.13.0",
|
|
49
|
-
"tsdown": "^0.23.
|
|
49
|
+
"tsdown": "^0.23.2",
|
|
50
50
|
"typescript": "6.0.3",
|
|
51
51
|
"vitest": "^5.0.5"
|
|
52
52
|
},
|