diff --git a/crates/oxc_linter/src/rules/eslint/no_duplicate_imports.rs b/crates/oxc_linter/src/rules/eslint/no_duplicate_imports.rs index a9f0e7fe818be..5397aa0b71165 100644 --- a/crates/oxc_linter/src/rules/eslint/no_duplicate_imports.rs +++ b/crates/oxc_linter/src/rules/eslint/no_duplicate_imports.rs @@ -272,7 +272,11 @@ impl Rule for NoDuplicateImports { continue; } - if existing.iter().any(|(t, _, module_type)| { + if existing.iter().any(|(t, import_span, module_type)| { + // import { a } from 'foo'; export { a as t }; + if matches!(t, ImportType::Named) && module_request.span != *import_span { + return true; + } (matches!( t, ImportType::Named | ImportType::SideEffect | ImportType::Default @@ -429,9 +433,23 @@ fn test() { export * from "os";"#, Some(serde_json::json!([{ "includeExports": true }])), ), + ( + " + import { a } from 'f'; + export { b as r }; + ", + Some(serde_json::json!([{ "includeExports": true }])), + ), ]; let fail = vec![ + ( + " + export { a } from 'foo'; + import { f } from 'foo'; + ", + Some(serde_json::json!([{ "includeExports": true }])), + ), ( r#"import "fs"; import "fs""#, diff --git a/crates/oxc_linter/src/snapshots/eslint_no_duplicate_imports.snap b/crates/oxc_linter/src/snapshots/eslint_no_duplicate_imports.snap index 2e9de18e62d3d..0c3e7193f91ef 100644 --- a/crates/oxc_linter/src/snapshots/eslint_no_duplicate_imports.snap +++ b/crates/oxc_linter/src/snapshots/eslint_no_duplicate_imports.snap @@ -1,6 +1,19 @@ --- source: crates/oxc_linter/src/tester.rs --- + ⚠ eslint(no-duplicate-imports): 'foo' export is duplicated + ╭─[no_duplicate_imports.tsx:2:26] + 1 │ + 2 │ export { a } from 'foo'; + · ┬ + · ╰── This export is duplicated + 3 │ import { f } from 'foo'; + · ──┬── + · ╰── Can be merged with this + 4 │ + ╰──── + help: Merge the duplicated exports into a single export statement + ⚠ eslint(no-duplicate-imports): 'fs' import is duplicated ╭─[no_duplicate_imports.tsx:1:8] 1 │ import "fs";