@eslint-react/var 5.9.5 → 5.10.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 CHANGED
@@ -61,6 +61,28 @@ declare function getRequireExpressionArguments(node: TSESTree.Node): TSESTree.Ca
61
61
  */
62
62
  declare function isAssignmentTargetEqual(context: RuleContext, a: TSESTree.Node, b: TSESTree.Node): boolean;
63
63
  //#endregion
64
+ //#region src/is-initialized-from-react.d.ts
65
+ /**
66
+ * Check if a variable is initialized from React import
67
+ * @internal
68
+ * @param name The variable name
69
+ * @param initialScope The initial scope
70
+ * @param importSource Alternative import source of React (ex: "preact/compat")
71
+ * @returns True if the variable is initialized or derived from React import
72
+ */
73
+ declare function isInitializedFromReact(name: string, initialScope: Scope, importSource?: string): boolean;
74
+ //#endregion
75
+ //#region src/is-initialized-from-react-native.d.ts
76
+ /**
77
+ * if a variable is initialized from React Native import
78
+ * @internal
79
+ * @param name The variable name
80
+ * @param initialScope The initial scope
81
+ * @param importSource Alternative import source of React Native (ex: "react-native-web")
82
+ * @returns True if the variable is initialized from React Native import
83
+ */
84
+ declare function isInitializedFromReactNative(name: string, initialScope: Scope, importSource?: string): boolean;
85
+ //#endregion
64
86
  //#region src/is-value-equal.d.ts
65
87
  /**
66
88
  * Determine whether node value equals to another node value
@@ -123,4 +145,4 @@ type AssignmentTarget = ReturnType<typeof resolveEnclosingAssignmentTarget>;
123
145
  //#region src/resolve-import-source.d.ts
124
146
  declare function resolveImportSource(name: string, initialScope: Scope, visited?: Set<string>): string | null;
125
147
  //#endregion
126
- export { AssignmentTarget, ObjectType, computeObjectType, getRequireExpressionArguments, isAssignmentTargetEqual, isValueEqual, resolve, resolveEnclosingAssignmentTarget, resolveImportSource };
148
+ export { AssignmentTarget, ObjectType, computeObjectType, getRequireExpressionArguments, isAssignmentTargetEqual, isInitializedFromReact, isInitializedFromReactNative, isValueEqual, resolve, resolveEnclosingAssignmentTarget, resolveImportSource };
package/dist/index.js CHANGED
@@ -274,25 +274,6 @@ function isAssignmentTargetEqual(context, a, b) {
274
274
  return Compare.isEqual(a, b) || isValueEqual(context, a, b);
275
275
  }
276
276
 
277
- //#endregion
278
- //#region src/resolve-enclosing-assignment-target.ts
279
- /**
280
- * Finds the enclosing assignment target (variable, property, etc.) for a given node
281
- *
282
- * @param node The starting node
283
- * @returns The enclosing assignment target node, or null if not found
284
- */
285
- function resolveEnclosingAssignmentTarget(node) {
286
- switch (true) {
287
- case node.type === AST_NODE_TYPES.VariableDeclarator: return node.id;
288
- case node.type === AST_NODE_TYPES.AssignmentExpression: return node.left;
289
- case node.type === AST_NODE_TYPES.PropertyDefinition: return node.key;
290
- case node.type === AST_NODE_TYPES.ExportDefaultDeclaration: return node.declaration;
291
- case node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program: return null;
292
- default: return resolveEnclosingAssignmentTarget(node.parent);
293
- }
294
- }
295
-
296
277
  //#endregion
297
278
  //#region src/resolve-import-source.ts
298
279
  function resolveImportSource(name, initialScope, visited = /* @__PURE__ */ new Set()) {
@@ -314,4 +295,55 @@ function resolveImportSource(name, initialScope, visited = /* @__PURE__ */ new S
314
295
  }
315
296
 
316
297
  //#endregion
317
- export { computeObjectType, getRequireExpressionArguments, isAssignmentTargetEqual, isValueEqual, resolve, resolveEnclosingAssignmentTarget, resolveImportSource };
298
+ //#region src/is-initialized-from-react.ts
299
+ /**
300
+ * Check if a variable is initialized from React import
301
+ * @internal
302
+ * @param name The variable name
303
+ * @param initialScope The initial scope
304
+ * @param importSource Alternative import source of React (ex: "preact/compat")
305
+ * @returns True if the variable is initialized or derived from React import
306
+ */
307
+ function isInitializedFromReact(name, initialScope, importSource = "react") {
308
+ return name.toLowerCase() === "react" || Boolean(resolveImportSource(name, initialScope)?.startsWith(importSource));
309
+ }
310
+
311
+ //#endregion
312
+ //#region src/is-initialized-from-react-native.ts
313
+ /**
314
+ * if a variable is initialized from React Native import
315
+ * @internal
316
+ * @param name The variable name
317
+ * @param initialScope The initial scope
318
+ * @param importSource Alternative import source of React Native (ex: "react-native-web")
319
+ * @returns True if the variable is initialized from React Native import
320
+ */
321
+ function isInitializedFromReactNative(name, initialScope, importSource = "react-native") {
322
+ return [
323
+ "react_native",
324
+ "reactnative",
325
+ "rn"
326
+ ].includes(name.toLowerCase()) || Boolean(resolveImportSource(name, initialScope)?.startsWith(importSource));
327
+ }
328
+
329
+ //#endregion
330
+ //#region src/resolve-enclosing-assignment-target.ts
331
+ /**
332
+ * Finds the enclosing assignment target (variable, property, etc.) for a given node
333
+ *
334
+ * @param node The starting node
335
+ * @returns The enclosing assignment target node, or null if not found
336
+ */
337
+ function resolveEnclosingAssignmentTarget(node) {
338
+ switch (true) {
339
+ case node.type === AST_NODE_TYPES.VariableDeclarator: return node.id;
340
+ case node.type === AST_NODE_TYPES.AssignmentExpression: return node.left;
341
+ case node.type === AST_NODE_TYPES.PropertyDefinition: return node.key;
342
+ case node.type === AST_NODE_TYPES.ExportDefaultDeclaration: return node.declaration;
343
+ case node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program: return null;
344
+ default: return resolveEnclosingAssignmentTarget(node.parent);
345
+ }
346
+ }
347
+
348
+ //#endregion
349
+ export { computeObjectType, getRequireExpressionArguments, isAssignmentTargetEqual, isInitializedFromReact, isInitializedFromReactNative, isValueEqual, resolve, resolveEnclosingAssignmentTarget, resolveImportSource };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/var",
3
- "version": "5.9.5",
3
+ "version": "5.10.0",
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": {
@@ -33,13 +33,13 @@
33
33
  "@typescript-eslint/types": "^8.62.0",
34
34
  "@typescript-eslint/utils": "^8.62.0",
35
35
  "ts-pattern": "^5.9.0",
36
- "@eslint-react/eslint": "5.9.5",
37
- "@eslint-react/ast": "5.9.5"
36
+ "@eslint-react/ast": "5.10.0",
37
+ "@eslint-react/eslint": "5.10.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@typescript-eslint/parser": "^8.62.0",
41
41
  "@typescript-eslint/typescript-estree": "^8.62.0",
42
- "eslint": "^10.5.0",
42
+ "eslint": "^10.6.0",
43
43
  "tsdown": "^0.22.3",
44
44
  "typescript": "6.0.3",
45
45
  "vitest": "^4.1.9",