Skip to content

Commit 13421a4

Browse files
connorsheaclaude
andcommitted
fix(linter): Address review feedback for no-multi-comp rule
- Use reference system instead of root scope lookup for aliased imports - Handle sequence expressions returning null (e.g., `const Foo = (0, () => null)`) - Document limitation about destructured aliased imports Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent f9b5d2d commit 13421a4

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

crates/oxc_linter/src/rules/react/no_multi_comp.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,10 @@ fn detect_variable_component(
271271
return Some(DetectedComponent { name, span: decl.span, is_stateless: true });
272272
}
273273

274-
// Sequence expression: const Foo = (0, () => <div/>)
274+
// Sequence expression: const Foo = (0, () => <div/>) or const Foo = (0, () => null)
275275
if let Expression::SequenceExpression(seq) = init
276276
&& let Some(last) = seq.expressions.last()
277-
&& expression_contains_jsx(last)
277+
&& (expression_contains_jsx(last) || is_function_returning_null(last))
278278
{
279279
return Some(DetectedComponent { name, span: decl.span, is_stateless: true });
280280
}
@@ -311,12 +311,14 @@ fn get_hoc_callee_name(call: &CallExpression, ctx: &LintContext) -> Option<Strin
311311
}
312312

313313
// Check for aliased imports: const myMemo = React.memo
314+
// Note: This does not handle destructured aliased imports like `const {memo: myMemo} = React`
314315
let Expression::Identifier(ident) = &call.callee else {
315316
return None;
316317
};
317318

318319
let scoping = ctx.scoping();
319-
let symbol_id = scoping.get_binding(scoping.root_scope_id(), &ident.name)?;
320+
let reference = scoping.get_reference(ident.reference_id());
321+
let symbol_id = reference.symbol_id()?;
320322
let decl_node = ctx.nodes().get_node(scoping.symbol_declaration(symbol_id));
321323
let AstKind::VariableDeclarator(var_decl) = decl_node.kind() else {
322324
return None;

0 commit comments

Comments
 (0)