Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/oxc_linter/src/generated/rule_runner_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1714,8 +1714,9 @@ impl RuleRunner for crate::rules::nextjs::no_document_import_in_page::NoDocument
}

impl RuleRunner for crate::rules::nextjs::no_duplicate_head::NoDuplicateHead {
const NODE_TYPES: Option<&AstTypesBitset> = None;
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::RunOnSymbol;
const NODE_TYPES: Option<&AstTypesBitset> =
Some(&AstTypesBitset::from_types(&[AstType::ImportDeclaration]));
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
}

impl RuleRunner for crate::rules::nextjs::no_head_element::NoHeadElement {
Expand Down
32 changes: 19 additions & 13 deletions crates/oxc_linter/src/rules/nextjs/no_duplicate_head.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use oxc_ast::AstKind;
use oxc_diagnostics::{LabeledSpan, OxcDiagnostic};
use oxc_macros::declare_oxc_lint;
use oxc_semantic::AstNode;
use oxc_span::GetSpan;

use crate::{context::LintContext, rule::Rule};
Expand Down Expand Up @@ -72,20 +73,27 @@ declare_oxc_lint!(
);

impl Rule for NoDuplicateHead {
fn run_on_symbol(&self, symbol_id: oxc_semantic::SymbolId, ctx: &LintContext<'_>) {
let symbols = ctx.scoping();
let name = symbols.symbol_name(symbol_id);
if name != "Head" {
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
let AstKind::ImportDeclaration(import_decl) = node.kind() else {
return;
}
};
let Some(specifiers) = &import_decl.specifiers else {
return;
};
let Some(head_specifier) = specifiers.iter().find(|s| s.name() == "Head") else {
return;
};

let scoping = ctx.scoping();
let symbol_id = head_specifier.local().symbol_id();

let flags = symbols.symbol_flags(symbol_id);
let flags = scoping.symbol_flags(symbol_id);
if !flags.is_import() {
return;
}

let scope_id = symbols.symbol_scope_id(symbol_id);
if scope_id != ctx.scoping().root_scope_id() {
let scope_id = scoping.symbol_scope_id(symbol_id);
if scope_id != scoping.root_scope_id() {
return;
}

Expand All @@ -100,7 +108,7 @@ impl Rule for NoDuplicateHead {
LabeledSpan::underline(span)
};

for reference in symbols.get_resolved_references(symbol_id) {
for reference in scoping.get_resolved_references(symbol_id) {
if !reference.is_read() {
continue;
}
Expand All @@ -125,11 +133,9 @@ impl Rule for NoDuplicateHead {
}

// `labels` is empty if 0 or 1 `<Head>` found
if labels.is_empty() {
return;
if !labels.is_empty() {
ctx.diagnostic(no_duplicate_head(labels));
}

ctx.diagnostic(no_duplicate_head(labels));
}
}

Expand Down
Loading