Skip to content

Commit

Permalink
refactor(linter): simplify skipping JSX elements in `unicorn/consiste…
Browse files Browse the repository at this point in the history
…nt_function_scoping` (#5351)

Follow-on after #5223. We're trying to ignore JSX identifiers, so there's no point walking downwards from `JSXElementName`, as all we'll find is JSX identifiers that we want to ignore.
  • Loading branch information
overlookmotel committed Aug 30, 2024
1 parent 381d9fe commit fe62687
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use oxc_ast::{visit::walk, AstKind, Visit};
use oxc_ast::{AstKind, Visit};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_semantic::ReferenceId;
Expand Down Expand Up @@ -260,19 +260,9 @@ impl<'a> Visit<'a> for ReferencesFinder {
self.references.push(it.reference_id().unwrap());
}

fn visit_jsx_element_name(&mut self, it: &oxc_ast::ast::JSXElementName<'a>) {
if !matches!(it, oxc_ast::ast::JSXElementName::IdentifierReference(_)) {
walk::walk_jsx_element_name(self, it);
}
}

fn visit_jsx_member_expression_object(
&mut self,
it: &oxc_ast::ast::JSXMemberExpressionObject<'a>,
) {
if !matches!(it, oxc_ast::ast::JSXMemberExpressionObject::IdentifierReference(_)) {
walk::walk_jsx_member_expression_object(self, it);
}
fn visit_jsx_element_name(&mut self, _it: &oxc_ast::ast::JSXElementName<'a>) {
// Ignore references in JSX elements e.g. `Foo` in `<Foo>`.
// No need to walk children as only references they may contain are also JSX identifiers.
}

fn visit_this_expression(&mut self, _: &oxc_ast::ast::ThisExpression) {
Expand Down

0 comments on commit fe62687

Please sign in to comment.