Skip to content

Commit 89b7ca9

Browse files
authored
fix(linter/no-duplicate-imports): only check aggregated exports (#20178)
skip checking `export { ... };` in eslint/no-duplicate-imports when includeExports is enabled, matching ESLint behavior. close #20176.
1 parent 0bbbf69 commit 89b7ca9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

crates/oxc_linter/src/rules/eslint/no_duplicate_imports.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,16 @@ impl Rule for NoDuplicateImports {
278278
}
279279

280280
for entry in &module_record.indirect_export_entries {
281+
// Skip checking `export { ... };` without `from` clause, matching ESLint behavior.
282+
//
283+
// In an export list, `entry.statement_span` points to the **import** statement,
284+
// while `entry.span` points to the exported item, so they won't overlap.
285+
// This is unlike in aggregated export (`export { ... } from '...'`) in which
286+
// `entry.statement_span` points to the **export** statement.
287+
if !entry.statement_span.contains_inclusive(entry.span) {
288+
continue;
289+
}
290+
281291
let Some(module_request) = &entry.module_request else {
282292
continue;
283293
};
@@ -678,6 +688,16 @@ fn test() {
678688
export type { Something } from "os";"#,
679689
Some(serde_json::json!([{ "includeExports": true }])),
680690
),
691+
(
692+
r#"import { M, MC } from "./types.ts";
693+
export { M, MC };"#,
694+
Some(serde_json::json!([{ "includeExports": true }])),
695+
),
696+
(
697+
r#"import type { M, MC } from "./types.ts";
698+
export type { M, MC };"#,
699+
Some(serde_json::json!([{ "includeExports": true }])),
700+
),
681701
(
682702
r#"export type { Something } from "os";
683703
export * from "os";"#,

0 commit comments

Comments
 (0)