Skip to content

Commit

Permalink
feat(linter): add fast path
Browse files Browse the repository at this point in the history
  • Loading branch information
mysteryven committed Dec 10, 2023
1 parent 3cfea85 commit ddecad8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions crates/oxc_linter/src/rules/react/react_in_jsx_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use oxc_diagnostics::{
thiserror::Error,
};
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use oxc_span::{Atom, Span};

use crate::{context::LintContext, rule::Rule, AstNode};

Expand Down Expand Up @@ -46,12 +46,15 @@ impl Rule for ReactInJsxScope {
AstKind::JSXFragment(v) => v.span,
_ => return,
};

let scope = ctx.scopes();
let react_name: &Atom = &Atom::from("React");
if scope.get_binding(scope.root_scope_id(), react_name).is_some() {
return;
}

if !scope
.ancestors(node.scope_id())
.any(|v| scope.get_bindings(v).iter().any(|(k, _)| k.as_str() == "React"))
.any(|v| scope.get_bindings(v).iter().any(|(k, _)| k == react_name))
{
ctx.diagnostic(ReactInJsxScopeDiagnostic(node_span));
}
Expand Down

0 comments on commit ddecad8

Please sign in to comment.