perf(linter): Check file path after checking node kind for nextjs/no-head-element (#5868)

This commit is contained in:
Cam McHenry 2024-09-18 18:31:18 -04:00 committed by GitHub
parent 0c8733df23
commit 3148d4b654
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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));
}
}
}