Skip to content

Commit 79c37cf

Browse files
committed
refactor: replace 'findParentNodeGuard' with 'findParentNode' across multiple files
1 parent e565ca6 commit 79c37cf

18 files changed

+60
-64
lines changed

packages/core/src/effect/is.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export function isSetupFunction(node: TSESTree.Node | _) {
1515
}
1616

1717
export function isCleanupFunction(node: TSESTree.Node) {
18-
const nearReturn = AST.findParentNodeGuard(node, AST.is(T.ReturnStatement));
19-
const nearFunction = AST.findParentNodeGuard(node, AST.isFunction);
20-
const nearFunctionOfReturn = AST.findParentNodeGuard(nearReturn, AST.isFunction);
18+
const nearReturn = AST.findParentNode(node, AST.is(T.ReturnStatement));
19+
const nearFunction = AST.findParentNode(node, AST.isFunction);
20+
const nearFunctionOfReturn = AST.findParentNode(nearReturn, AST.isFunction);
2121
return nearFunction === nearFunctionOfReturn && isSetupFunction(nearFunction);
2222
}

packages/core/src/element/hierarchy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export function isInsideCreateElementProps(
1515
node: TSESTree.Node,
1616
context: RuleContext,
1717
) {
18-
const call = AST.findParentNodeGuard(node, isCreateElementCall(context));
18+
const call = AST.findParentNode(node, isCreateElementCall(context));
1919
if (call == null) return false;
20-
const prop = AST.findParentNodeGuard(node, AST.is(T.ObjectExpression));
20+
const prop = AST.findParentNode(node, AST.is(T.ObjectExpression));
2121
if (prop == null) return false;
2222
return prop === call.arguments[1];
2323
}

packages/core/src/hook/hierarchy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import type { TSESTree } from "@typescript-eslint/types";
44
import { isReactHook } from "./is";
55

66
export function isInsideReactHook(node: TSESTree.Node) {
7-
return isReactHook(AST.findParentNodeGuard(node, AST.isFunction));
7+
return isReactHook(AST.findParentNode(node, AST.isFunction));
88
}

packages/core/src/render-prop/hierarchy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function isDeclaredInRenderPropLoose(node: TSESTree.Node) {
3838
if (isDirectValueOfRenderPropertyLoose(node)) {
3939
return true;
4040
}
41-
const parent = AST.findParentNodeGuard(node, AST.is(T.JSXExpressionContainer))?.parent;
41+
const parent = AST.findParentNode(node, AST.is(T.JSXExpressionContainer))?.parent;
4242
if (parent?.type !== T.JSXAttribute) {
4343
return false;
4444
}

packages/plugins/eslint-plugin-react-hooks-extra/src/rules/no-direct-set-state-in-use-effect.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export default createRule<[], MessageID>({
132132
return;
133133
}
134134
default: {
135-
const variableDeclarator = AST.findParentNodeGuard(node, isVariableDeclaratorFromHookCall);
135+
const variableDeclarator = AST.findParentNode(node, isVariableDeclaratorFromHookCall);
136136
if (variableDeclarator == null) {
137137
const calls = indSetStateCalls.get(pEntry.node) ?? [];
138138
indSetStateCalls.set(pEntry.node, [...calls, node]);
@@ -177,7 +177,7 @@ export default createRule<[], MessageID>({
177177
if (!isUseMemoCall(parent)) {
178178
break;
179179
}
180-
const variableDeclarator = AST.findParentNodeGuard(parent, isVariableDeclaratorFromHookCall);
180+
const variableDeclarator = AST.findParentNode(parent, isVariableDeclaratorFromHookCall);
181181
if (variableDeclarator == null) {
182182
break;
183183
}
@@ -193,7 +193,7 @@ export default createRule<[], MessageID>({
193193
// const set = useCallback(setState, []);
194194
// useEffect(set, []);
195195
if (isUseCallbackCall(node.parent)) {
196-
const variableDeclarator = AST.findParentNodeGuard(node.parent, isVariableDeclaratorFromHookCall);
196+
const variableDeclarator = AST.findParentNode(node.parent, isVariableDeclaratorFromHookCall);
197197
if (variableDeclarator == null) {
198198
break;
199199
}

packages/plugins/eslint-plugin-react-hooks-extra/src/rules/no-direct-set-state-in-use-layout-effect.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export default createRule<[], MessageID>({
137137
return;
138138
}
139139
default: {
140-
const variableDeclarator = AST.findParentNodeGuard(node, isVariableDeclaratorFromHookCall);
140+
const variableDeclarator = AST.findParentNode(node, isVariableDeclaratorFromHookCall);
141141
if (variableDeclarator == null) {
142142
const calls = indSetStateCalls.get(pEntry.node) ?? [];
143143
indSetStateCalls.set(pEntry.node, [...calls, node]);
@@ -182,7 +182,7 @@ export default createRule<[], MessageID>({
182182
if (!isUseMemoCall(parent)) {
183183
break;
184184
}
185-
const variableDeclarator = AST.findParentNodeGuard(parent, isVariableDeclaratorFromHookCall);
185+
const variableDeclarator = AST.findParentNode(parent, isVariableDeclaratorFromHookCall);
186186
if (variableDeclarator == null) {
187187
break;
188188
}
@@ -198,7 +198,7 @@ export default createRule<[], MessageID>({
198198
// const set = useCallback(setState, []);
199199
// useLayoutEffect(set, []);
200200
if (isUseCallbackCall(node.parent)) {
201-
const variableDeclarator = AST.findParentNodeGuard(node.parent, isVariableDeclaratorFromHookCall);
201+
const variableDeclarator = AST.findParentNode(node.parent, isVariableDeclaratorFromHookCall);
202202
if (variableDeclarator == null) {
203203
break;
204204
}

packages/plugins/eslint-plugin-react-x/src/rules/no-direct-mutation-state.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default createRule<[], MessageID>({
7171
if (!isAssignmentToThisState(node)) {
7272
return;
7373
}
74-
const parentClass = AST.findParentNodeGuard(
74+
const parentClass = AST.findParentNode(
7575
node,
7676
AST.isOneOf([
7777
T.ClassDeclaration,
@@ -81,7 +81,7 @@ export default createRule<[], MessageID>({
8181
if (parentClass == null) return;
8282
if (
8383
isClassComponent(parentClass)
84-
&& context.sourceCode.getScope(node).block !== AST.findParentNodeGuard(node, isConstructorFunction)
84+
&& context.sourceCode.getScope(node).block !== AST.findParentNode(node, isConstructorFunction)
8585
) {
8686
context.report({
8787
messageId: "noDirectMutationState",

packages/plugins/eslint-plugin-react-x/src/rules/no-duplicate-key.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export default createRule<[], MessageID>({
6666
break;
6767
}
6868
default: {
69-
const call = AST.findParentNodeGuard(jsxElement, AST.isMapCallLoose);
69+
const call = AST.findParentNode(jsxElement, AST.isMapCallLoose);
7070
const iter = AST.findParentNode(jsxElement, (n) => n === call || AST.isFunction(n));
7171
if (!AST.isFunction(iter)) return;
7272
const arg0 = call?.arguments[0];

packages/plugins/eslint-plugin-react-x/src/rules/no-nested-components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export default createRule<[], MessageID>({
114114

115115
continue;
116116
}
117-
const parentComponent = AST.findParentNodeGuard(component, isFunctionComponent);
117+
const parentComponent = AST.findParentNode(component, isFunctionComponent);
118118
const isParnetComponentNotDirectValueOfRenderProperty = parentComponent != null
119119
&& !isDirectValueOfRenderPropertyLoose(parentComponent);
120120
if (isParnetComponentNotDirectValueOfRenderProperty) {

packages/plugins/eslint-plugin-react-x/src/rules/no-set-state-in-component-did-mount.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default createRule<[], MessageID>({
4444
if (!isThisSetState(node)) {
4545
return;
4646
}
47-
const clazz = AST.findParentNodeGuard(node, isClassComponent);
47+
const clazz = AST.findParentNode(node, isClassComponent);
4848
const method = AST.findParentNode(node, (n) => n === clazz || isComponentDidMount(n));
4949
if (clazz == null || method == null || method === clazz) return;
5050
const methodScope = context.sourceCode.getScope(method);

0 commit comments

Comments
 (0)