@eslint-react/var 5.19.1 → 5.20.1

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 CHANGED
@@ -4,8 +4,8 @@ import { RuleContext } from "@eslint-react/eslint";
4
4
  //#region src/get-require-expression-arguments.d.ts
5
5
  /**
6
6
  * Get the arguments of a require expression.
7
- * @param node The node to match.
8
- * @returns The require expression arguments or `null` if the node is not a require expression.
7
+ * @param node The node to check.
8
+ * @returns The require expression arguments, or `null` when the node is not a require expression.
9
9
  * @internal
10
10
  */
11
11
  export declare function getRequireExpressionArguments(node: TSESTree.Node): TSESTree.CallExpressionArgument[] | null;
@@ -13,7 +13,7 @@ export declare function getRequireExpressionArguments(node: TSESTree.Node): TSES
13
13
  //#region src/is-assignment-target-equal.d.ts
14
14
  /**
15
15
  * Check if two assignment targets are equal, either directly or by their values.
16
- * @param context The rule context.
16
+ * @param context The ESLint rule context.
17
17
  * @param a The first node to compare.
18
18
  * @param b The second node to compare.
19
19
  * @returns `true` if the assignment targets are equal.
@@ -38,18 +38,18 @@ export declare function isInitializedFromReact(name: string, initialScope: Scope
38
38
  * @param name The variable name.
39
39
  * @param initialScope The initial scope.
40
40
  * @param importSource Alternative import source of React Native (ex: "react-native-web").
41
- * @returns `true` if the variable is initialized from a React Native import.
41
+ * @returns `true` if the variable is initialized or derived from a React Native import.
42
42
  * @internal
43
43
  */
44
44
  export declare function isInitializedFromReactNative(name: string, initialScope: Scope, importSource?: string): boolean;
45
45
  //#endregion
46
46
  //#region src/is-value-equal.d.ts
47
47
  /**
48
- * Check if the value of a node equals the value of another node.
49
- * @param context The rule context.
48
+ * Check if two nodes have equal values.
49
+ * @param context The ESLint rule context.
50
50
  * @param a The first node to compare.
51
51
  * @param b The second node to compare.
52
- * @returns `true` if the node values are equal.
52
+ * @returns `true` if the two nodes have equal values.
53
53
  */
54
54
  export declare function isValueEqual(context: RuleContext, a: TSESTree.Node, b: TSESTree.Node): boolean;
55
55
  //#endregion
@@ -74,13 +74,13 @@ export declare function isValueEqual(context: RuleContext, a: TSESTree.Node, b:
74
74
  * | `Type` | type alias node | `null` |
75
75
  * | `ImplicitGlobalVariable` | any node | `null` |
76
76
  *
77
- * @param context The ESLint rule context used for scope lookup.
77
+ * @param context The ESLint rule context.
78
78
  * @param node The identifier to resolve.
79
79
  * @param options Optional settings:
80
80
  * - `at`: Index of the definition to resolve (default: `0` for the first definition).
81
81
  * - `localOnly`: If `true`, only consider variables declared in the same scope as the identifier
82
- * will miss variables declared in an outer scope). When `false` (default), traverse the scope
83
- * chain upward via `findVariable` so that references to outer-scope bindings are resolved
82
+ * (this will miss variables declared in an outer scope). When `false` (default), traverse the
83
+ * scope chain upward via `findVariable` so that references to outer-scope bindings are resolved
84
84
  * correctly.
85
85
  * @returns The resolved node, or `null` if the identifier cannot be resolved to a value node.
86
86
  */
@@ -90,15 +90,14 @@ export declare function resolve(context: RuleContext, node: TSESTree.Identifier,
90
90
  }>): TSESTree.Node | null;
91
91
  //#endregion
92
92
  //#region src/resolve-enclosing-assignment-target.d.ts
93
+ /** The possible assignment targets returned by {@link resolveEnclosingAssignmentTarget}. */
94
+ export type AssignmentTarget = ReturnType<typeof resolveEnclosingAssignmentTarget>;
93
95
  /**
94
- * Resolve the enclosing assignment target (variable, property, etc.) of a node.
95
- *
96
- * @param node The starting node.
97
- * @returns The enclosing assignment target node, or `null` if not found.
96
+ * Resolve the enclosing assignment target (variable, property, etc.) of the node.
97
+ * @param node The starting node for the upward search.
98
+ * @returns The enclosing assignment target node, or `null` when not found.
98
99
  */
99
100
  export declare function resolveEnclosingAssignmentTarget(node: TSESTree.Node): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.PrivateIdentifier | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSEnumDeclaration | TSESTree.TSInstantiationExpression | TSESTree.TSInterfaceDeclaration | TSESTree.TSModuleDeclarationGlobal | TSESTree.TSModuleDeclarationModuleWithIdentifierId | TSESTree.TSModuleDeclarationModuleWithStringIdDeclared | TSESTree.TSModuleDeclarationModuleWithStringIdNotDeclared | TSESTree.TSModuleDeclarationNamespace | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAliasDeclaration | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.ConstDeclaration | TSESTree.LetOrVarDeclaredDeclaration | TSESTree.LetOrVarNonDeclaredDeclaration | TSESTree.UsingInForOfDeclaration | TSESTree.UsingInNormalContextDeclaration | TSESTree.YieldNoStarExpression | TSESTree.YieldStarExpression | null;
100
- /** The possible assignment targets returned by {@link resolveEnclosingAssignmentTarget}. */
101
- export type AssignmentTarget = ReturnType<typeof resolveEnclosingAssignmentTarget>;
102
101
  //#endregion
103
102
  //#region src/resolve-import-source.d.ts
104
103
  /**
@@ -106,7 +105,7 @@ export type AssignmentTarget = ReturnType<typeof resolveEnclosingAssignmentTarge
106
105
  * @param name The variable name.
107
106
  * @param initialScope The initial scope.
108
107
  * @param seen The set of already visited variable names (for cycle detection).
109
- * @returns The import source, or `null` if it cannot be resolved.
108
+ * @returns The import source, or `null` when it cannot be resolved.
110
109
  */
111
110
  export declare function resolveImportSource(name: string, initialScope: Scope, seen?: Set<string>): string | null;
112
111
  //#endregion
@@ -141,10 +140,10 @@ export type ObjectType = {
141
140
  reason?: string;
142
141
  };
143
142
  /**
144
- * Resolve the object type of the given node.
145
- * @param context The rule context.
143
+ * Resolve the object type of the node.
144
+ * @param context The ESLint rule context.
146
145
  * @param node The node to resolve.
147
- * @returns The object type of the node, or `null` if it cannot be resolved.
146
+ * @returns The object type of the node, or `null` when it cannot be resolved.
148
147
  */
149
148
  export declare function resolveObjectType(context: RuleContext, node: TSESTree.Node | null): ObjectType | null;
150
149
  //#endregion
package/dist/index.js CHANGED
@@ -7,8 +7,8 @@ import { P, isMatching } from "ts-pattern";
7
7
  //#region src/get-require-expression-arguments.ts
8
8
  /**
9
9
  * Get the arguments of a require expression.
10
- * @param node The node to match.
11
- * @returns The require expression arguments or `null` if the node is not a require expression.
10
+ * @param node The node to check.
11
+ * @returns The require expression arguments, or `null` when the node is not a require expression.
12
12
  * @internal
13
13
  */
14
14
  function getRequireExpressionArguments(node) {
@@ -16,6 +16,7 @@ function getRequireExpressionArguments(node) {
16
16
  if (unwrapped.type === AST_NODE_TYPES.CallExpression) {
17
17
  const callee = Extract.unwrap(unwrapped.callee);
18
18
  if (Check.isIdentifier(callee, "require")) return unwrapped.arguments;
19
+ return null;
19
20
  }
20
21
  if (unwrapped.type === AST_NODE_TYPES.MemberExpression) return getRequireExpressionArguments(unwrapped.object);
21
22
  return null;
@@ -43,13 +44,13 @@ function getRequireExpressionArguments(node) {
43
44
  * | `Type` | type alias node | `null` |
44
45
  * | `ImplicitGlobalVariable` | any node | `null` |
45
46
  *
46
- * @param context The ESLint rule context used for scope lookup.
47
+ * @param context The ESLint rule context.
47
48
  * @param node The identifier to resolve.
48
49
  * @param options Optional settings:
49
50
  * - `at`: Index of the definition to resolve (default: `0` for the first definition).
50
51
  * - `localOnly`: If `true`, only consider variables declared in the same scope as the identifier
51
- * will miss variables declared in an outer scope). When `false` (default), traverse the scope
52
- * chain upward via `findVariable` so that references to outer-scope bindings are resolved
52
+ * (this will miss variables declared in an outer scope). When `false` (default), traverse the
53
+ * scope chain upward via `findVariable` so that references to outer-scope bindings are resolved
53
54
  * correctly.
54
55
  * @returns The resolved node, or `null` if the identifier cannot be resolved to a value node.
55
56
  */
@@ -90,11 +91,11 @@ const thisBlockTypes = [
90
91
  AST_NODE_TYPES.Program
91
92
  ];
92
93
  /**
93
- * Check if the value of a node equals the value of another node.
94
- * @param context The rule context.
94
+ * Check if two nodes have equal values.
95
+ * @param context The ESLint rule context.
95
96
  * @param a The first node to compare.
96
97
  * @param b The second node to compare.
97
- * @returns `true` if the node values are equal.
98
+ * @returns `true` if the two nodes have equal values.
98
99
  */
99
100
  function isValueEqual(context, a, b) {
100
101
  a = Check.isTypeExpression(a) ? Extract.unwrap(a) : a;
@@ -153,7 +154,7 @@ function isValueEqual(context, a, b) {
153
154
  //#region src/is-assignment-target-equal.ts
154
155
  /**
155
156
  * Check if two assignment targets are equal, either directly or by their values.
156
- * @param context The rule context.
157
+ * @param context The ESLint rule context.
157
158
  * @param a The first node to compare.
158
159
  * @param b The second node to compare.
159
160
  * @returns `true` if the assignment targets are equal.
@@ -170,7 +171,7 @@ function isAssignmentTargetEqual(context, a, b) {
170
171
  * @param name The variable name.
171
172
  * @param initialScope The initial scope.
172
173
  * @param seen The set of already visited variable names (for cycle detection).
173
- * @returns The import source, or `null` if it cannot be resolved.
174
+ * @returns The import source, or `null` when it cannot be resolved.
174
175
  */
175
176
  function resolveImportSource(name, initialScope, seen = /* @__PURE__ */ new Set()) {
176
177
  if (seen.has(name)) return null;
@@ -214,7 +215,7 @@ function isInitializedFromReact(name, initialScope, importSource = "react") {
214
215
  * @param name The variable name.
215
216
  * @param initialScope The initial scope.
216
217
  * @param importSource Alternative import source of React Native (ex: "react-native-web").
217
- * @returns `true` if the variable is initialized from a React Native import.
218
+ * @returns `true` if the variable is initialized or derived from a React Native import.
218
219
  * @internal
219
220
  */
220
221
  function isInitializedFromReactNative(name, initialScope, importSource = "react-native") {
@@ -228,18 +229,18 @@ function isInitializedFromReactNative(name, initialScope, importSource = "react-
228
229
  //#endregion
229
230
  //#region src/resolve-enclosing-assignment-target.ts
230
231
  /**
231
- * Resolve the enclosing assignment target (variable, property, etc.) of a node.
232
- *
233
- * @param node The starting node.
234
- * @returns The enclosing assignment target node, or `null` if not found.
232
+ * Resolve the enclosing assignment target (variable, property, etc.) of the node.
233
+ * @param node The starting node for the upward search.
234
+ * @returns The enclosing assignment target node, or `null` when not found.
235
235
  */
236
236
  function resolveEnclosingAssignmentTarget(node) {
237
- switch (true) {
238
- case node.type === AST_NODE_TYPES.VariableDeclarator: return node.id;
239
- case node.type === AST_NODE_TYPES.AssignmentExpression: return node.left;
240
- case node.type === AST_NODE_TYPES.PropertyDefinition: return node.key;
241
- case node.type === AST_NODE_TYPES.ExportDefaultDeclaration: return node.declaration;
242
- case node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program: return null;
237
+ switch (node.type) {
238
+ case AST_NODE_TYPES.VariableDeclarator: return node.id;
239
+ case AST_NODE_TYPES.AssignmentExpression: return node.left;
240
+ case AST_NODE_TYPES.PropertyDefinition: return node.key;
241
+ case AST_NODE_TYPES.ExportDefaultDeclaration: return node.declaration;
242
+ case AST_NODE_TYPES.BlockStatement:
243
+ case AST_NODE_TYPES.Program: return null;
243
244
  default: return resolveEnclosingAssignmentTarget(node.parent);
244
245
  }
245
246
  }
@@ -247,10 +248,10 @@ function resolveEnclosingAssignmentTarget(node) {
247
248
  //#endregion
248
249
  //#region src/resolve-object-type.ts
249
250
  /**
250
- * Resolve the object type of the given node.
251
- * @param context The rule context.
251
+ * Resolve the object type of the node.
252
+ * @param context The ESLint rule context.
252
253
  * @param node The node to resolve.
253
- * @returns The object type of the node, or `null` if it cannot be resolved.
254
+ * @returns The object type of the node, or `null` when it cannot be resolved.
254
255
  */
255
256
  function resolveObjectType(context, node) {
256
257
  if (node == null) return null;
@@ -305,7 +306,7 @@ function resolveObjectType(context, node) {
305
306
  case AST_NODE_TYPES.ConditionalExpression: return resolveObjectType(context, node.consequent) ?? resolveObjectType(context, node.alternate);
306
307
  case AST_NODE_TYPES.SequenceExpression:
307
308
  if (node.expressions.length === 0) return null;
308
- return resolveObjectType(context, node.expressions[node.expressions.length - 1] ?? null);
309
+ return resolveObjectType(context, node.expressions.at(-1) ?? null);
309
310
  case AST_NODE_TYPES.CallExpression: {
310
311
  const callee = Extract.unwrap(node.callee);
311
312
  switch (true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/var",
3
- "version": "5.19.1",
3
+ "version": "5.20.1",
4
4
  "description": "ESLint React's TSESTree AST utility module for static analysis of variables.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -29,8 +29,8 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@eslint-react/ast": "5.19.1",
33
- "@eslint-react/eslint": "5.19.1",
32
+ "@eslint-react/ast": "5.20.1",
33
+ "@eslint-react/eslint": "5.20.1",
34
34
  "@typescript-eslint/scope-manager": "^8.70.0",
35
35
  "@typescript-eslint/types": "^8.70.0",
36
36
  "@typescript-eslint/utils": "^8.70.0",
@@ -42,10 +42,10 @@
42
42
  "@local/testkit": "0.0.0",
43
43
  "@typescript-eslint/parser": "^8.70.0",
44
44
  "@typescript-eslint/typescript-estree": "^8.70.0",
45
- "eslint": "^10.10.0",
45
+ "eslint": "^10.11.0",
46
46
  "tsdown": "^0.23.0",
47
47
  "typescript": "6.0.3",
48
- "vitest": "^5.0.0"
48
+ "vitest": "^5.0.1"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "eslint": "*",