Skip to content
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): add the eslint/no_duplicate_imports rule #7309

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Spoutnik97
Copy link

Create the rule
Almost all cases are implemented. Already usable

Copy link

graphite-app bot commented Nov 16, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@github-actions github-actions bot added the A-linter Area - Linter label Nov 16, 2024
@Spoutnik97 Spoutnik97 changed the title Linter/no duplicate imports feat(linter): add the eslint/no_duplicate_imports rule Nov 16, 2024
@github-actions github-actions bot added the C-enhancement Category - New feature or request label Nov 16, 2024
Comment on lines +13 to +25
fn no_duplicate_imports_diagnostic(module_name: &str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("'{}' import is duplicated", module_name))
.with_help("Merge the duplicated import into a single import statement")
.with_label(span)
}

fn no_duplicate_exports_diagnostic(module_name: &str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("'{}' export is duplicated", module_name))
.with_help("Merge the duplicated exports into a single export statement")
.with_label(span)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's probably worth useing with_labels and proving an array of spans so that we can highlight both of the import stmts


let mut modules: HashMap<String, Vec<ModuleEntry>> = HashMap::new();

for node in nodes {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than looping over all nodes here, is it possible to use ctx.module_record().import_entries?

it has a vec of ImportEntry which includes both the span of the module specifier and it's name

Copy link

codspeed-hq bot commented Nov 18, 2024

CodSpeed Performance Report

Merging #7309 will not alter performance

Comparing Spoutnik97:linter/no_duplicate_imports (3cdc7fb) with main (44fd962)

Summary

✅ 30 untouched benchmarks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants