Skip to content

Commit

Permalink
perf(linter): Check file path after checking node kind for `nextjs/no…
Browse files Browse the repository at this point in the history
…-head-element` (#5868)
  • Loading branch information
camchenry authored Sep 18, 2024
1 parent 0c8733d commit 3148d4b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions crates/oxc_linter/src/rules/nextjs/no_head_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ declare_oxc_lint!(

impl Rule for NoHeadElement {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
let Some(full_file_path) = ctx.file_path().to_str() else {
return;
};
if is_in_app_dir(full_file_path) {
return;
}
if let AstKind::JSXOpeningElement(elem) = node.kind() {
let JSXElementName::Identifier(id) = &elem.name else {
return;
};
if id.name == "head" {
ctx.diagnostic(no_head_element_diagnostic(elem.span));
if id.name != "head" {
return;
}
let Some(full_file_path) = ctx.file_path().to_str() else {
return;
};
if is_in_app_dir(full_file_path) {
return;
}
ctx.diagnostic(no_head_element_diagnostic(elem.span));
}
}
}
Expand Down

0 comments on commit 3148d4b

Please sign in to comment.