Skip to content

Commit d26d8cd

Browse files
committed
fix: fixed potential false negatives in no-leaked-conditional-rendering when logical expressions are wrapped by type expressions
1 parent f20f87a commit d26d8cd

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

packages/plugins/eslint-plugin-react-x/src/rules/no-leaked-conditional-rendering.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,18 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
213213
] as const satisfies VariantType[];
214214

215215
const services = ESLintUtils.getParserServices(context, false);
216-
function getReportDescriptor(node: TSESTree.Expression | _): ReportDescriptor<MessageID> | _ {
216+
function getReportDescriptor(
217+
node:
218+
| _
219+
| TSESTree.Expression
220+
| TSESTree.JSXExpressionContainer
221+
| TSESTree.JSXExpressionContainer["expression"],
222+
): ReportDescriptor<MessageID> | _ {
217223
if (node == null) return _;
224+
if (AST.is(T.JSXExpressionContainer)(node)) return getReportDescriptor(node.expression);
225+
if (AST.isJSX(node)) return _;
226+
if (AST.isTypeExpression(node)) return getReportDescriptor(node.expression);
218227
return match<typeof node, ReportDescriptor<MessageID> | _>(node)
219-
.when(AST.isJSX, () => _)
220228
.with({ type: T.LogicalExpression, operator: "&&" }, ({ left, right }) => {
221229
const isLeftUnaryNot = left.type === T.UnaryExpression && left.operator === "!";
222230
if (isLeftUnaryNot) {
@@ -260,10 +268,8 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
260268
})
261269
.otherwise(() => _);
262270
}
263-
const visitorFunction = flow(getReportDescriptor, Report.make(context).send);
264271
return {
265-
"JSXExpressionContainer > ConditionalExpression": visitorFunction,
266-
"JSXExpressionContainer > LogicalExpression": visitorFunction,
272+
JSXExpressionContainer: flow(getReportDescriptor, Report.make(context).send),
267273
};
268274
}
269275

0 commit comments

Comments
 (0)