Skip to content

Commit e7231fe

Browse files
committed
Move isConditional to ast package
1 parent a0ede83 commit e7231fe

File tree

4 files changed

+19
-22
lines changed

4 files changed

+19
-22
lines changed

packages/plugins/eslint-plugin-react-web-api/src/rules/no-leaked-resize-observer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type { RuleListener } from "@typescript-eslint/utils/ts-eslint";
1616
import { P, isMatching, match } from "ts-pattern";
1717

1818
import type { ObserverEntry, ObserverMethod } from "../types";
19-
import { createRule, isConditional } from "../utils";
19+
import { createRule } from "../utils";
2020

2121
// #region Rule Metadata
2222

@@ -216,7 +216,7 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
216216
}
217217
const oentries = oEntries.filter((e) => isInstanceIdEqual(context, e.observer, id));
218218
const uentries = uEntries.filter((e) => isInstanceIdEqual(context, e.observer, id));
219-
const isDynamic = (node: TSESTree.Node | unit) => node?.type === T.CallExpression || isConditional(node);
219+
const isDynamic = (node: TSESTree.Node | unit) => node?.type === T.CallExpression || AST.isConditional(node);
220220
const isPhaseNode = (node: TSESTree.Node | unit) => node === phaseNode;
221221
const hasDynamicallyAdded = oentries
222222
.some((e) => !isPhaseNode(AST.findParentNode(e.node, or(isDynamic, isPhaseNode))));
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export * from "./create-rule";
2-
export * from "./is-conditional";

packages/plugins/eslint-plugin-react-web-api/src/utils/is-conditional.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/utilities/ast/src/node-is.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { or } from "@eslint-react/eff";
12
import type { TSESTree } from "@typescript-eslint/types"; // eslint-disable-line @typescript-eslint/no-unused-vars
23
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
34
import { ASTUtils } from "@typescript-eslint/utils";
@@ -74,6 +75,22 @@ export const isLoop = isOneOf([
7475
T.WhileStatement,
7576
]);
7677

78+
export const isControlFlow = or(
79+
isLoop,
80+
isOneOf([
81+
T.IfStatement,
82+
T.SwitchStatement,
83+
]),
84+
);
85+
86+
export const isConditional = or(
87+
isControlFlow,
88+
isOneOf([
89+
T.LogicalExpression,
90+
T.ConditionalExpression,
91+
]),
92+
);
93+
7794
export const isTypeExpression = isOneOf([
7895
T.TSAsExpression,
7996
T.TSTypeAssertion,

0 commit comments

Comments
 (0)