Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pkgs/eslint-plugin-local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
"devDependencies": {
"@local/configs": "workspace:*",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"tsdown": "^0.14.2"
},
Expand Down
2 changes: 1 addition & 1 deletion apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@types/hast": "^3.0.4",
"@types/mdx": "^2.0.13",
"@types/node": "^24.3.0",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"autoprefixer": "^10.4.21",
"dedent": "^1.6.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/lynx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@lynx-js/types": "^3.3.0",
"@rsbuild/plugin-sass": "^1.4.0",
"@rsbuild/plugin-type-check": "^1.2.4",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-x": "workspace:*"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@tsconfig/node22": "^22.0.2",
"@tsconfig/strictest": "^2.0.5",
"@types/node": "^24.3.0",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"eslint": "^9.34.0",
"eslint-config-flat-gitignore": "^2.1.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react-dom-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@eslint-react/eslint-plugin": "workspace:*",
"@eslint/config-inspector": "^1.2.0",
"@eslint/js": "^9.34.0",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"@vitejs/plugin-react": "^5.0.1",
"eslint": "^9.34.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react-dom-v1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@tsconfig/node22": "^22.0.2",
"@tsconfig/strictest": "^2.0.5",
"@tsconfig/vite-react": "^7.0.0",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"@vitejs/plugin-react": "^5.0.1",
"eslint": "^9.34.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@tsconfig/node22": "^22.0.2",
"@tsconfig/strictest": "^2.0.5",
"@tsconfig/vite-react": "^7.0.0",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"@vitejs/plugin-react": "^5.0.1",
"eslint": "^9.34.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/with-babel-eslint-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@eslint/js": "^9.34.0",
"@types/babel__core": "~7.20.5",
"@types/babel__preset-env": "~7.10.0",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"@vitejs/plugin-react": "^5.0.1",
"eslint": "^9.34.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/with-ts-blank-eslint-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@tsconfig/node22": "^22.0.2",
"@tsconfig/strictest": "^2.0.5",
"@tsconfig/vite-react": "^7.0.0",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"@vitejs/plugin-react": "^5.0.1",
"eslint": "^9.34.0",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"@tsconfig/node22": "^22.0.2",
"@tsconfig/strictest": "^2.0.5",
"@types/node": "^24.3.0",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"@typescript-eslint/parser": "^8.41.0",
"@typescript-eslint/rule-tester": "^8.41.0",
Expand Down Expand Up @@ -117,7 +117,7 @@
],
"overrides": {
"@eslint/plugin-kit": ">=0.3.5",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"cross-spawn": "^7.0.6",
"esbuild": "^0.25.9",
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/jsx/jsx-attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export function getAttribute(
// Case 2: Spread from variable (e.g., {...props})
case T.Identifier: {
const variable = VAR.findVariable(attr.argument.name, initialScope);
const variableNode = VAR.getVariableInitNode(variable, 0);
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
if (variableNode?.type === T.ObjectExpression) {
return VAR.findPropertyInProperties(name, variableNode.properties, initialScope) != null;
return VAR.findProperty(name, variableNode.properties, initialScope) != null;
}
return false;
}
// Case 3: Spread from object literal (e.g., {{...{prop: value}}})
case T.ObjectExpression:
return VAR.findPropertyInProperties(name, attr.argument.properties, initialScope) != null;
return VAR.findProperty(name, attr.argument.properties, initialScope) != null;
}
return false;
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/jsx/jsx-detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export function isJsxLike(
// Resolve variables to their values and check if they're JSX-like
const variable = VAR.findVariable(name, code.getScope(node));
const variableNode = variable
&& VAR.getVariableInitNode(variable, 0);
&& VAR.getVariableDefinitionNode(variable, 0);
return !!variableNode
&& isJsxLike(code, variableNode, hint);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/eslint-plugin-react-debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"devDependencies": {
"@local/configs": "workspace:*",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"tsdown": "^0.14.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/eslint-plugin-react-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"devDependencies": {
"@local/configs": "workspace:*",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"tsdown": "^0.14.2"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"devDependencies": {
"@local/configs": "workspace:*",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"tsdown": "^0.14.2"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function useNoDirectSetStateInUseEffect<Ctx extends RuleContext>(

function isIdFromUseStateCall(topLevelId: TSESTree.Identifier, at?: number) {
const variable = VAR.findVariable(topLevelId, context.sourceCode.getScope(topLevelId));
const variableNode = VAR.getVariableInitNode(variable, 0);
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
if (variableNode == null) return false;
if (variableNode.type !== T.CallExpression) return false;
if (!ER.isReactHookCallWithNameAlias(context, "useState", hooks.useState)(variableNode)) return false;
Expand Down Expand Up @@ -278,7 +278,7 @@ export function useNoDirectSetStateInUseEffect<Ctx extends RuleContext>(
id: string | TSESTree.Identifier,
initialScope: Scope.Scope,
): TSESTree.CallExpression[] | TSESTree.Identifier[] => {
const node = VAR.getVariableInitNode(VAR.findVariable(id, initialScope), 0);
const node = VAR.getVariableDefinitionNode(VAR.findVariable(id, initialScope), 0);
switch (node?.type) {
case T.ArrowFunctionExpression:
case T.FunctionDeclaration:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
.with({ type: T.ArrayExpression }, (n) => n.elements.length === 0)
.with({ type: T.Identifier }, (n) => {
const variable = VAR.findVariable(n.name, initialScope);
const variableNode = VAR.getVariableInitNode(variable, 0);
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
if (variableNode?.type !== T.ArrayExpression) {
return false;
}
Expand All @@ -112,7 +112,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
.with({ type: T.FunctionExpression }, identity)
.with({ type: T.Identifier }, (n) => {
const variable = VAR.findVariable(n.name, initialScope);
const variableNode = VAR.getVariableInitNode(variable, 0);
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
if (variableNode?.type !== T.ArrowFunctionExpression && variableNode?.type !== T.FunctionExpression) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
.with({ type: T.ArrayExpression }, (n) => n.elements.length === 0)
.with({ type: T.Identifier }, (n) => {
const variable = VAR.findVariable(n.name, initialScope);
const variableNode = VAR.getVariableInitNode(variable, 0);
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
if (variableNode?.type !== T.ArrayExpression) {
return false;
}
Expand All @@ -117,7 +117,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
.with({ type: T.FunctionExpression }, identity)
.with({ type: T.Identifier }, (n) => {
const variable = VAR.findVariable(n.name, initialScope);
const variableNode = VAR.getVariableInitNode(variable, 0);
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
if (variableNode?.type !== T.ArrowFunctionExpression && variableNode?.type !== T.FunctionExpression) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
continue;
}
// Skip empty functions
if (AST.isEmptyFunction(node)) {
if (AST.isFunctionEmpty(node)) {
continue;
}
// Skip useful hooks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
"devDependencies": {
"@local/configs": "workspace:*",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"tsdown": "^0.14.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/eslint-plugin-react-web-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
},
"devDependencies": {
"@local/configs": "workspace:*",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"tsdown": "^0.14.2"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ function getSignalValueExpression(node: TSESTree.Node | unit, initialScope: Scop
if (node == null) return unit;
switch (node.type) {
case T.Identifier: {
return getSignalValueExpression(VAR.getVariableInitNode(VAR.findVariable(node, initialScope), 0), initialScope);
return getSignalValueExpression(
VAR.getVariableDefinitionNode(VAR.findVariable(node, initialScope), 0),
initialScope,
);
}
case T.MemberExpression:
return node;
Expand All @@ -84,7 +87,7 @@ function getSignalValueExpression(node: TSESTree.Node | unit, initialScope: Scop

function getOptions(node: TSESTree.CallExpressionArgument, initialScope: Scope): typeof defaultOptions {
function findProp(properties: TSESTree.ObjectExpression["properties"], propName: string) {
return VAR.findPropertyInProperties(propName, properties, initialScope);
return VAR.findProperty(propName, properties, initialScope);
}
function getPropValue<A>(
prop: TSESTree.Property | TSESTree.RestElement | TSESTree.SpreadElement | unit,
Expand All @@ -109,7 +112,7 @@ function getOptions(node: TSESTree.CallExpressionArgument, initialScope: Scope):
switch (node.type) {
case T.Identifier: {
const variable = VAR.findVariable(node, initialScope);
const variableNode = VAR.getVariableInitNode(variable, 0);
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
if (variableNode?.type === T.ObjectExpression) {
return getOpts(variableNode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
if (!ER.ComponentPhaseRelevance.has(fEntry.kind)) {
break;
}
const intervalIdNode = VAR.getVariableDeclaratorId(node);
const intervalIdNode = VAR.findAssignmentTarget(node);
if (intervalIdNode == null) {
context.report({
messageId: "expectedIntervalId",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function isFromObserver(context: RuleContext, node: TSESTree.Expression): boolea
switch (true) {
case node.type === T.Identifier: {
const initialScope = context.sourceCode.getScope(node);
const object = VAR.getVariableInitNode(VAR.findVariable(node, initialScope), 0);
const object = VAR.getVariableDefinitionNode(VAR.findVariable(node, initialScope), 0);
return isNewResizeObserver(object);
}
case node.type === T.MemberExpression:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
}
switch (getCallKind(node)) {
case "setTimeout": {
const timeoutIdNode = VAR.getVariableDeclaratorId(node);
const timeoutIdNode = VAR.findAssignmentTarget(node);
if (timeoutIdNode == null) {
context.report({
messageId: "expectedTimeoutId",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/eslint-plugin-react-x/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"devDependencies": {
"@local/configs": "workspace:*",
"@types/react": "^19.1.11",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.8",
"ts-api-utils": "^2.1.0",
"tsdown": "^0.14.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
return;
}
const variable = VAR.findVariable(object.name, context.sourceCode.getScope(node));
const variableNode = VAR.getVariableInitNode(variable, 0);
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
if (variableNode == null) return;
if (!AST.isFunction(variableNode)) return;
context.report({ messageId: "noDefaultProps", node: property });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
if (!AST.isFunction(iter)) return;
const arg0 = call?.arguments[0];
if (call == null || arg0 == null) return;
if (AST.getJSExpression(arg0) !== iter) {
if (AST.getUnderlyingExpression(arg0) !== iter) {
return;
}
keyedEntries.set(call, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
return;
}
const variable = VAR.findVariable(object.name, context.sourceCode.getScope(node));
const variableNode = VAR.getVariableInitNode(variable, 0);
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
if (variableNode != null && (AST.isFunction(variableNode) || ER.isClassComponent(variableNode))) {
context.report({ messageId: "noPropTypes", node: property });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
function isMapCallback(node: TSESTree.Node) {
if (node.parent == null) return false;
if (!AST.isArrayMapCall(node.parent)) return false;
return AST.isOneOf([T.ArrowFunctionExpression, T.FunctionExpression])(AST.getJSExpression(node));
return AST.isOneOf([T.ArrowFunctionExpression, T.FunctionExpression])(AST.getUnderlyingExpression(node));
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
.with({ type: T.ArrayExpression }, (n) => n.elements.length === 0)
.with({ type: T.Identifier }, (n) => {
const variable = VAR.findVariable(n.name, initialScope);
const variableNode = VAR.getVariableInitNode(variable, 0);
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
if (variableNode?.type !== T.ArrayExpression) {
return false;
}
Expand All @@ -85,7 +85,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
.with({ type: T.FunctionExpression }, identity)
.with({ type: T.Identifier }, (n) => {
const variable = VAR.findVariable(n.name, initialScope);
const variableNode = VAR.getVariableInitNode(variable, 0);
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
if (variableNode?.type !== T.ArrowFunctionExpression && variableNode?.type !== T.FunctionExpression) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
.with({ type: T.ArrayExpression }, (n) => n.elements.length === 0)
.with({ type: T.Identifier }, (n) => {
const variable = VAR.findVariable(n.name, initialScope);
const variableNode = VAR.getVariableInitNode(variable, 0);
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
if (variableNode?.type !== T.ArrayExpression) {
return false;
}
Expand All @@ -90,7 +90,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
.with({ type: T.FunctionExpression }, identity)
.with({ type: T.Identifier }, (n) => {
const variable = VAR.findVariable(n.name, initialScope);
const variableNode = VAR.getVariableInitNode(variable, 0);
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
if (variableNode?.type !== T.ArrowFunctionExpression && variableNode?.type !== T.FunctionExpression) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
continue;
}
// Skip empty functions
if (AST.isEmptyFunction(node)) {
if (AST.isFunctionEmpty(node)) {
continue;
}
// Skip well-known hooks
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/eslint-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ export default tseslint.config({

Contributions are welcome!

Please follow our [contributing guidelines](https://github.com/Rel1cx/eslint-react/tree/2.0.0/.github/CONTRIBUTING.md).
Please follow our [contributing guidelines](https://github.com/Rel1cx/eslint-react/tree/refactor/ast-utilities-reorganization/.github/CONTRIBUTING.md).

## License

This project is licensed under the MIT License - see the [LICENSE](https://github.com/Rel1cx/eslint-react/tree/2.0.0/LICENSE) file for details.
This project is licensed under the MIT License - see the [LICENSE](https://github.com/Rel1cx/eslint-react/tree/refactor/ast-utilities-reorganization/LICENSE) file for details.
Loading
Loading