Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@eslint-react/var

Package Overview
Dependencies
Maintainers
1
Versions
2299
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eslint-react/var - npm Package Compare versions

Comparing version
3.0.0-beta.63
to
3.0.0-beta.64
+36
-6
dist/index.d.ts

@@ -1,2 +0,1 @@

import { unit } from "@eslint-react/eff";
import { Scope } from "@typescript-eslint/scope-manager";

@@ -39,6 +38,5 @@ import { TSESTree } from "@typescript-eslint/types";

* @param node The node to check
* @param initialScope The initial scope to check for variable declarations
* @returns The ObjectType of the node, or undefined if not detected
*/
declare function computeObjectType(node: TSESTree.Node | unit, initialScope: Scope): ObjectType | unit;
declare function computeObjectType(context: RuleContext, node: TSESTree.Node | null): ObjectType | null;
//#endregion

@@ -51,5 +49,5 @@ //#region src/find-enclosing-assignment-target.d.ts

* @param node The starting node
* @returns The enclosing assignment target node, or undefined if not found
* @returns The enclosing assignment target node, or null if not found
*/
declare function findEnclosingAssignmentTarget(node: TSESTree.Node): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | 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.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldExpression | undefined;
declare function findEnclosingAssignmentTarget(node: TSESTree.Node): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | 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.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldExpression | null;
/**

@@ -82,2 +80,34 @@ * Type representing the possible assignment targets returned by `findEnclosingAssignmentTarget`

//#endregion
export { AssignmentTarget, ObjectType, computeObjectType, findEnclosingAssignmentTarget, isAssignmentTargetEqual, isValueEqual };
//#region src/resolve.d.ts
/**
* Resolves an identifier to the AST node that represents its value,
* suitable for use in ESLint rule analysis.
*
* The resolution follows these rules per definition type:
*
* | Definition type | `def.node` | Returns |
* |--------------------------|----------------------------------------------|------------------------------------|
* | `Variable` | `VariableDeclarator` | `def.node.init` (or `null`) |
* | `FunctionName` | `FunctionDeclaration` / `FunctionExpression` | `def.node` |
* | `ClassName` | `ClassDeclaration` / `ClassExpression` | `def.node` |
* | `Parameter` | containing function node | `def.node` (if a real function) |
* | `TSEnumName` | `TSEnumDeclaration` | `def.node` |
* | `TSEnumMember` | `TSEnumMember` | `def.node.initializer` (or `null`) |
* | `ImportBinding` | import specifier | `null` |
* | `CatchClause` | `CatchClause` | `null` |
* | `TSModuleName` | `TSModuleDeclaration` | `null` |
* | `Type` | type alias node | `null` |
* | `ImplicitGlobalVariable` | any node | `null` |
*
* @param context The ESLint rule context used for scope lookup.
* @param node The identifier to resolve.
* @param at Which definition to use when multiple exist (default: `0`; pass `-1` for the last).
* @param localOnly When `true`, look up the variable only in the node's own scope (faster, but
* will miss variables declared in an outer scope). When `false` (default), traverse the scope
* chain upward via `findVariable` so that references to outer-scope bindings are resolved
* correctly.
* @returns The resolved node, or `null` if the identifier cannot be resolved to a value node.
*/
declare function resolve(context: RuleContext, node: TSESTree.Identifier, at?: number, localOnly?: boolean): TSESTree.Node | null;
//#endregion
export { AssignmentTarget, ObjectType, computeObjectType, findEnclosingAssignmentTarget, isAssignmentTargetEqual, isValueEqual, resolve };
+80
-32

@@ -1,2 +0,1 @@

import { unit } from "@eslint-react/eff";
import { DefinitionType } from "@typescript-eslint/scope-manager";

@@ -7,2 +6,60 @@ import { AST_NODE_TYPES } from "@typescript-eslint/types";

//#region src/resolve.ts
/**
* Resolves an identifier to the AST node that represents its value,
* suitable for use in ESLint rule analysis.
*
* The resolution follows these rules per definition type:
*
* | Definition type | `def.node` | Returns |
* |--------------------------|----------------------------------------------|------------------------------------|
* | `Variable` | `VariableDeclarator` | `def.node.init` (or `null`) |
* | `FunctionName` | `FunctionDeclaration` / `FunctionExpression` | `def.node` |
* | `ClassName` | `ClassDeclaration` / `ClassExpression` | `def.node` |
* | `Parameter` | containing function node | `def.node` (if a real function) |
* | `TSEnumName` | `TSEnumDeclaration` | `def.node` |
* | `TSEnumMember` | `TSEnumMember` | `def.node.initializer` (or `null`) |
* | `ImportBinding` | import specifier | `null` |
* | `CatchClause` | `CatchClause` | `null` |
* | `TSModuleName` | `TSModuleDeclaration` | `null` |
* | `Type` | type alias node | `null` |
* | `ImplicitGlobalVariable` | any node | `null` |
*
* @param context The ESLint rule context used for scope lookup.
* @param node The identifier to resolve.
* @param at Which definition to use when multiple exist (default: `0`; pass `-1` for the last).
* @param localOnly When `true`, look up the variable only in the node's own scope (faster, but
* will miss variables declared in an outer scope). When `false` (default), traverse the scope
* chain upward via `findVariable` so that references to outer-scope bindings are resolved
* correctly.
* @returns The resolved node, or `null` if the identifier cannot be resolved to a value node.
*/
function resolve(context, node, at = 0, localOnly = false) {
const scope = context.sourceCode.getScope(node);
const variable = localOnly ? scope.set.get(node.name) : findVariable(scope, node);
if (variable == null) return null;
const def = variable.defs.at(at);
if (def == null) return null;
switch (def.type) {
case DefinitionType.FunctionName: return def.node;
case DefinitionType.ClassName: return def.node;
case DefinitionType.Variable: {
const { init } = def.node;
if (init == null) return null;
if ("declarations" in init) return null;
return init;
}
case DefinitionType.Parameter: return ast.isFunction(def.node) ? def.node : null;
case DefinitionType.TSEnumName: return def.node;
case DefinitionType.TSEnumMember: return def.node.initializer ?? null;
case DefinitionType.ImportBinding: return null;
case DefinitionType.CatchClause: return null;
case DefinitionType.TSModuleName: return null;
case DefinitionType.Type: return null;
case DefinitionType.ImplicitGlobalVariable: return null;
default: return null;
}
}
//#endregion
//#region src/compute-object-type.ts

@@ -12,7 +69,6 @@ /**

* @param node The node to check
* @param initialScope The initial scope to check for variable declarations
* @returns The ObjectType of the node, or undefined if not detected
*/
function computeObjectType(node, initialScope) {
if (node == null) return unit;
function computeObjectType(context, node) {
if (node == null) return null;
switch (node.type) {

@@ -52,20 +108,21 @@ case AST_NODE_TYPES.JSXElement:

};
return unit;
return null;
case AST_NODE_TYPES.Identifier: {
const initNode = resolve(initialScope.set.get(node.name));
if (initNode == null) return unit;
return computeObjectType(initNode, initialScope);
if ((context.sourceCode.getScope(node).set.get(node.name)?.defs.at(-1))?.type === DefinitionType.Parameter) return null;
const initNode = resolve(context, node, -1, true);
if (initNode == null) return null;
return computeObjectType(context, initNode);
}
case AST_NODE_TYPES.MemberExpression:
if (!("object" in node)) return unit;
return computeObjectType(node.object, initialScope);
if (!("object" in node)) return null;
return computeObjectType(context, node.object);
case AST_NODE_TYPES.AssignmentExpression:
case AST_NODE_TYPES.AssignmentPattern:
if (!("right" in node)) return unit;
return computeObjectType(node.right, initialScope);
case AST_NODE_TYPES.LogicalExpression: return computeObjectType(node.right, initialScope);
case AST_NODE_TYPES.ConditionalExpression: return computeObjectType(node.consequent, initialScope) ?? computeObjectType(node.alternate, initialScope);
if (!("right" in node)) return null;
return computeObjectType(context, node.right);
case AST_NODE_TYPES.LogicalExpression: return computeObjectType(context, node.right);
case AST_NODE_TYPES.ConditionalExpression: return computeObjectType(context, node.consequent) ?? computeObjectType(context, node.alternate);
case AST_NODE_TYPES.SequenceExpression:
if (node.expressions.length === 0) return unit;
return computeObjectType(node.expressions[node.expressions.length - 1], initialScope);
if (node.expressions.length === 0) return null;
return computeObjectType(context, node.expressions[node.expressions.length - 1] ?? null);
case AST_NODE_TYPES.CallExpression: return {

@@ -77,15 +134,6 @@ kind: "unknown",

default:
if (!("expression" in node) || typeof node.expression !== "object") return unit;
return computeObjectType(node.expression, initialScope);
if (!("expression" in node) || typeof node.expression !== "object") return null;
return computeObjectType(context, node.expression);
}
}
function resolve(v) {
if (v == null) return unit;
const def = v.defs.at(-1);
if (def == null) return unit;
if (def.type === DefinitionType.Variable) return def.node.init;
if (def.type === DefinitionType.Parameter) return unit;
if (def.type === DefinitionType.ImportBinding) return unit;
return def.node;
}

@@ -99,3 +147,3 @@ //#endregion

* @param node The starting node
* @returns The enclosing assignment target node, or undefined if not found
* @returns The enclosing assignment target node, or null if not found
*/

@@ -107,3 +155,3 @@ function findEnclosingAssignmentTarget(node) {

case node.type === AST_NODE_TYPES.PropertyDefinition: return node.key;
case node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program || node.parent === node: return unit;
case node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program || node.parent === node: return null;
default: return findEnclosingAssignmentTarget(node.parent);

@@ -140,3 +188,3 @@ }

const resolve = (variable) => {
if (variable == null) return unit;
if (variable == null) return null;
const def = variable.defs.at(0);

@@ -149,3 +197,3 @@ if (def != null) switch (true) {

if (def?.type === DefinitionType.Parameter && ast.isFunction(def.node)) return def.node;
return unit;
return null;
};

@@ -208,2 +256,2 @@ const aVarInit = resolve(aVar);

//#endregion
export { computeObjectType, findEnclosingAssignmentTarget, isAssignmentTargetEqual, isValueEqual };
export { computeObjectType, findEnclosingAssignmentTarget, isAssignmentTargetEqual, isValueEqual, resolve };
{
"name": "@eslint-react/var",
"version": "3.0.0-beta.63",
"version": "3.0.0-beta.64",
"description": "ESLint React's TSESTree AST utility module for static analysis of variables.",

@@ -37,7 +37,8 @@ "homepage": "https://github.com/Rel1cx/eslint-react",

"ts-pattern": "^5.9.0",
"@eslint-react/ast": "3.0.0-beta.63",
"@eslint-react/eff": "3.0.0-beta.63",
"@eslint-react/shared": "3.0.0-beta.63"
"@eslint-react/ast": "3.0.0-beta.64",
"@eslint-react/eff": "3.0.0-beta.64",
"@eslint-react/shared": "3.0.0-beta.64"
},
"devDependencies": {
"@typescript-eslint/typescript-estree": "canary",
"tsdown": "^0.21.0-beta.2",

@@ -44,0 +45,0 @@ "@local/configs": "0.0.0"