-
-
Notifications
You must be signed in to change notification settings - Fork 496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(linter): eslint-plugin-next/no-duplicate-head #2438
feat(linter): eslint-plugin-next/no-duplicate-head #2438
Conversation
CodSpeed Performance ReportMerging #2438 will not alter performanceComparing Summary
|
1cc84d6
to
9523a61
Compare
use crate::{context::LintContext, rule::Rule}; | ||
|
||
#[derive(Debug, Error, Diagnostic)] | ||
#[error("eslint-plugin-next(no-duplicate-head):")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a error message here.
let nodes = ctx.semantic().nodes(); | ||
for node in nodes.iter() { | ||
match node.kind() { | ||
oxc_ast::AstKind::ImportDeclaration(decl) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we can use AstKind:ImportDefaultSpecifier
instead, the parent kind of the AstKind:ImportDefaultSpecifier
is AstKind::ImportDeclaration
oxc_ast::AstKind::ReturnStatement(stmt) => { | ||
let document_class_id = nodes.ancestors(node.id()).find(|node_id| { | ||
matches!(nodes.get_node(*node_id).kind(), | ||
AstKind::Class(class) | ||
if class | ||
.super_class | ||
.as_ref() | ||
.and_then(|sc| sc.as_identifier()) | ||
.map(|id| &id.name) | ||
== document_import_name.as_ref()) | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can have a simpler way to find the class, for example via ctx.semantic.classes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this would be faster, you still need to figure out if the class is the ancestor of current ReturnStatement
Wait ... can't we just find all the read references of |
Yes! Sounds reasonable. |
Good idea, however, you still need to extract the console.log("what ever")
test
Document
import Document, {test} from './test' So iterating the |
Yeah, the import part is still needed. |
You can find the |
But you don't know if it's imported from next or renamed :-( |
implement @next/next/no-typos, part of #1929
Ref
Code
https://github.com/vercel/next.js/blob/canary/packages/eslint-plugin-next/src/rules/no-duplicate-head.ts