@eslint-react/var 2.8.2-next.5 → 2.8.3-next.7

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
@@ -27,12 +27,29 @@ type AssignmentTarget = ReturnType<typeof findEnclosingAssignmentTarget>;
27
27
  declare function findImportSource(name: string, initialScope: Scope): string | undefined;
28
28
  //#endregion
29
29
  //#region src/find-property.d.ts
30
+ /**
31
+ * Find a property by name in an array of properties
32
+ * Handles spread elements by recursively resolving the referenced object
33
+ * @param name The property name to find
34
+ * @param properties The array of properties to search
35
+ * @param initialScope The scope to use for variable resolution
36
+ * @param seen Set of already seen variable names to prevent circular references
37
+ * @returns The found property or unit if not found
38
+ */
30
39
  declare function findProperty(name: string, properties: (TSESTree.Property | TSESTree.RestElement | TSESTree.SpreadElement)[], initialScope: Scope, seen?: Set<string>): (typeof properties)[number] | unit;
31
40
  //#endregion
32
41
  //#region src/get-child-scopes.d.ts
42
+ /**
43
+ * Get all child scopes recursively from a given scope
44
+ * @param scope The scope to get child scopes from
45
+ * @returns Array of all child scopes including the input scope
46
+ */
33
47
  declare function getChildScopes(scope: Scope): readonly Scope[];
34
48
  //#endregion
35
49
  //#region src/get-object-type.d.ts
50
+ /**
51
+ * Represents the type classification of an object node
52
+ */
36
53
  type ObjectType = {
37
54
  kind: "jsx";
38
55
  node: TSESTree.JSXElement | TSESTree.JSXFragment;
@@ -68,7 +85,20 @@ type ObjectType = {
68
85
  declare function getObjectType(node: TSESTree.Node | unit, initialScope: Scope): ObjectType | unit;
69
86
  //#endregion
70
87
  //#region src/get-variable-definition-node.d.ts
88
+ /**
89
+ * Get the definition node of a variable at a specific definition index
90
+ * @param variable The variable to get the definition node from
91
+ * @param at The index of the definition to retrieve (negative index supported)
92
+ * @returns The definition node or unit if not found
93
+ */
71
94
  declare function getVariableDefinitionNode(variable: Variable | unit, at: number): unit | TSESTree.ClassDeclaration | TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.Expression | TSESTree.FunctionDeclaration | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName;
95
+ /**
96
+ * Get the definition node of a variable at a specific definition index (loose version)
97
+ * Also returns the function node if the definition is a parameter
98
+ * @param variable The variable to get the definition node from
99
+ * @param at The index of the definition to retrieve
100
+ * @returns The definition node or unit if not found
101
+ */
72
102
  declare function getVariableDefinitionNodeLoose(variable: Variable | unit, at: number): unit | TSESTree.ClassDeclaration | TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.Expression | TSESTree.FunctionDeclaration | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName;
73
103
  //#endregion
74
104
  //#region src/get-variables-from-scope.d.ts
@@ -78,13 +108,30 @@ declare function getVariableDefinitionNodeLoose(variable: Variable | unit, at: n
78
108
  * @returns All variables from the given scope up to the global scope
79
109
  */
80
110
  declare function getVariables(initialScope: Scope): Variable[];
111
+ /**
112
+ * Find a variable by name or identifier node in the scope chain
113
+ * @param initialScope The scope to start searching from
114
+ * @returns The found variable or unit if not found
115
+ * @overload
116
+ * @param nameOrNode The variable name or identifier node to find
117
+ * @param initialScope The scope to start searching from
118
+ * @returns The found variable or unit if not found
119
+ */
81
120
  declare const findVariable: {
82
121
  (initialScope: Scope): (nameOrNode: string | TSESTree.Identifier | unit) => Variable | unit;
83
122
  (nameOrNode: string | TSESTree.Identifier | unit, initialScope: Scope): Variable | unit;
84
123
  };
85
124
  //#endregion
86
125
  //#region src/is-assignment-target-equal.d.ts
87
- /** @internal */
126
+ /**
127
+ * Check if two assignment targets are equal
128
+ * Compares nodes directly or by their values
129
+ * @param context The rule context
130
+ * @param a The first node to compare
131
+ * @param b The second node to compare
132
+ * @returns True if the assignment targets are equal
133
+ * @internal
134
+ */
88
135
  declare function isAssignmentTargetEqual(context: RuleContext, a: TSESTree.Node, b: TSESTree.Node): boolean;
89
136
  //#endregion
90
137
  //#region src/is-node-value-equal.d.ts
package/dist/index.js CHANGED
@@ -41,6 +41,15 @@ function getVariables(initialScope) {
41
41
  }
42
42
  return variables.reverse();
43
43
  }
44
+ /**
45
+ * Find a variable by name or identifier node in the scope chain
46
+ * @param initialScope The scope to start searching from
47
+ * @returns The found variable or unit if not found
48
+ * @overload
49
+ * @param nameOrNode The variable name or identifier node to find
50
+ * @param initialScope The scope to start searching from
51
+ * @returns The found variable or unit if not found
52
+ */
44
53
  const findVariable = dual(2, (nameOrNode, initialScope) => {
45
54
  if (nameOrNode == null) return unit;
46
55
  return astUtils.findVariable(initialScope, nameOrNode) ?? unit;
@@ -90,6 +99,12 @@ function findImportSource(name, initialScope) {
90
99
 
91
100
  //#endregion
92
101
  //#region src/get-variable-definition-node.ts
102
+ /**
103
+ * Get the definition node of a variable at a specific definition index
104
+ * @param variable The variable to get the definition node from
105
+ * @param at The index of the definition to retrieve (negative index supported)
106
+ * @returns The definition node or unit if not found
107
+ */
93
108
  function getVariableDefinitionNode(variable, at) {
94
109
  if (variable == null) return unit;
95
110
  const def = variable.defs.at(at);
@@ -101,6 +116,13 @@ function getVariableDefinitionNode(variable, at) {
101
116
  default: return unit;
102
117
  }
103
118
  }
119
+ /**
120
+ * Get the definition node of a variable at a specific definition index (loose version)
121
+ * Also returns the function node if the definition is a parameter
122
+ * @param variable The variable to get the definition node from
123
+ * @param at The index of the definition to retrieve
124
+ * @returns The definition node or unit if not found
125
+ */
104
126
  function getVariableDefinitionNodeLoose(variable, at) {
105
127
  if (variable == null) return unit;
106
128
  const node = getVariableDefinitionNode(variable, at);
@@ -112,6 +134,15 @@ function getVariableDefinitionNodeLoose(variable, at) {
112
134
 
113
135
  //#endregion
114
136
  //#region src/find-property.ts
137
+ /**
138
+ * Find a property by name in an array of properties
139
+ * Handles spread elements by recursively resolving the referenced object
140
+ * @param name The property name to find
141
+ * @param properties The array of properties to search
142
+ * @param initialScope The scope to use for variable resolution
143
+ * @param seen Set of already seen variable names to prevent circular references
144
+ * @returns The found property or unit if not found
145
+ */
115
146
  function findProperty(name, properties, initialScope, seen = /* @__PURE__ */ new Set()) {
116
147
  return properties.findLast((prop) => {
117
148
  if (prop.type === AST_NODE_TYPES.Property) return "name" in prop.key && prop.key.name === name;
@@ -134,6 +165,11 @@ function findProperty(name, properties, initialScope, seen = /* @__PURE__ */ new
134
165
 
135
166
  //#endregion
136
167
  //#region src/get-child-scopes.ts
168
+ /**
169
+ * Get all child scopes recursively from a given scope
170
+ * @param scope The scope to get child scopes from
171
+ * @returns Array of all child scopes including the input scope
172
+ */
137
173
  function getChildScopes(scope) {
138
174
  const scopes = [scope];
139
175
  for (const childScope of scope.childScopes) scopes.push(...getChildScopes(childScope));
@@ -279,7 +315,15 @@ function isNodeValueEqual(a, b, initialScopes) {
279
315
 
280
316
  //#endregion
281
317
  //#region src/is-assignment-target-equal.ts
282
- /** @internal */
318
+ /**
319
+ * Check if two assignment targets are equal
320
+ * Compares nodes directly or by their values
321
+ * @param context The rule context
322
+ * @param a The first node to compare
323
+ * @param b The second node to compare
324
+ * @returns True if the assignment targets are equal
325
+ * @internal
326
+ */
283
327
  function isAssignmentTargetEqual(context, a, b) {
284
328
  return ast.isNodeEqual(a, b) || isNodeValueEqual(a, b, [context.sourceCode.getScope(a), context.sourceCode.getScope(b)]);
285
329
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/var",
3
- "version": "2.8.2-next.5",
3
+ "version": "2.8.3-next.7",
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": {
@@ -34,9 +34,9 @@
34
34
  "@typescript-eslint/types": "^8.54.0",
35
35
  "@typescript-eslint/utils": "^8.54.0",
36
36
  "ts-pattern": "^5.9.0",
37
- "@eslint-react/ast": "2.8.2-next.5",
38
- "@eslint-react/eff": "2.8.2-next.5",
39
- "@eslint-react/shared": "2.8.2-next.5"
37
+ "@eslint-react/ast": "2.8.3-next.7",
38
+ "@eslint-react/eff": "2.8.3-next.7",
39
+ "@eslint-react/shared": "2.8.3-next.7"
40
40
  },
41
41
  "devDependencies": {
42
42
  "tsdown": "^0.20.1",