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

fix(linter): correct false positive in no-duplicates #6748

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 8 additions & 1 deletion crates/oxc_linter/src/rules/import/no_duplicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ impl Rule for NoDuplicates {
.collect::<Vec<_>>();
if imports.is_empty() {
import_entries_maps.entry(0).or_default().push(requested_module);
continue;
}
let mut flags = [true; 4];
for imports in imports {
let key = if imports.is_type {
match imports.import_name {
Expand All @@ -131,7 +133,11 @@ impl Rule for NoDuplicates {
_ => 0,
}
};
import_entries_maps.entry(key).or_default().push(requested_module);

if flags[key as usize] {
flags[key as usize] = false;
shulaoda marked this conversation as resolved.
Show resolved Hide resolved
import_entries_maps.entry(key).or_default().push(requested_module);
}
}
}

Expand Down Expand Up @@ -206,6 +212,7 @@ fn test() {
(r"import type * as something from './foo'; import { y } from './foo';", None),
(r"import y from './foo'; import type * as something from './foo';", None),
(r"import { y } from './foo'; import type * as something from './foo';", None),
(r"import { RouterModule, Routes } from '@angular/router';", None),
];

let fail = vec![
Expand Down
12 changes: 2 additions & 10 deletions crates/oxc_linter/src/snapshots/no_duplicates.snap
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ source: crates/oxc_linter/src/tester.rs
⚠ eslint-plugin-import(no-duplicates): Module './foo' is imported more than once in this file
╭─[index.ts:1:8]
1 │ import './foo'; import def, {x} from './foo'
· ───┬─── ───────
· ───┬─── ───────
· ╰── It is first imported here
╰────
help: Merge these imports into a single import statement
Expand Down Expand Up @@ -249,7 +249,7 @@ source: crates/oxc_linter/src/tester.rs
⚠ eslint-plugin-import(no-duplicates): Module './foo' is imported more than once in this file
╭─[index.ts:1:17]
1 │ import {x} from './foo'; import def, {y} from './foo'
· ───┬─── ───────
· ───┬─── ───────
· ╰── It is first imported here
╰────
help: Merge these imports into a single import statement
Expand Down Expand Up @@ -540,14 +540,6 @@ source: crates/oxc_linter/src/tester.rs
╰────
help: Merge these imports into a single import statement

⚠ eslint-plugin-import(no-duplicates): Module './foo' is imported more than once in this file
╭─[index.ts:1:38]
1 │ import {AValue, type x, BValue} from './foo'; import {type y} from './foo'
DonIsaac marked this conversation as resolved.
Show resolved Hide resolved
· ───┬────
· ╰── It is first imported here
╰────
help: Merge these imports into a single import statement

⚠ eslint-plugin-import(no-duplicates): Module './foo' is imported more than once in this file
╭─[index.ts:1:38]
1 │ import {AValue, type x, BValue} from './foo'; import {type y} from './foo'
Expand Down
Loading