From 3148d4b654eace1ac9677fcef7342e891ec9c47f Mon Sep 17 00:00:00 2001 From: Cam McHenry Date: Wed, 18 Sep 2024 18:31:18 -0400 Subject: [PATCH] perf(linter): Check file path after checking node kind for `nextjs/no-head-element` (#5868) --- .../src/rules/nextjs/no_head_element.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/oxc_linter/src/rules/nextjs/no_head_element.rs b/crates/oxc_linter/src/rules/nextjs/no_head_element.rs index 0df102a6e..1e982df56 100644 --- a/crates/oxc_linter/src/rules/nextjs/no_head_element.rs +++ b/crates/oxc_linter/src/rules/nextjs/no_head_element.rs @@ -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)); } } }