deslop/duplicate-import
Merge multiple import statements from the same module specifier into one.
- Category: Architecture
- Severity: warn
- Source:
deslop-js - Framework: global
- Enabled when: react-doctor deadCode analysis enabled (default true); whole-project scan only — skipped in --diff/--staged modes
- Documentation: https://github.com/millionco/deslop-js
Validation prompt
Use this to decide whether a fired diagnostic is real or a false positive.
Fires from deslop's detectDuplicateImports when the same module specifier appears in two or more static import statements in one file, emitting reason '"<specifier>" is imported N times in this file as imports — merge into a single statement' (the word "type-only" is inserted when all the same-specifier occurrences are type imports); the finding lists each occurrence's line, column, and importedNames (a namespace binding is shown as "* as alias"). The detector already skips side-effect imports (zero bindings, e.g. import "./styles.css"), dynamic import() calls, glob imports, and .d.ts declaration files entirely, and it groups type-only separately from value imports — so a bare side-effect import alongside a named import, an import type kept apart from a value import, or duplicate imports inside a declaration file will NOT trigger this and need no suppression. False positive to suppress: two value imports from the same specifier that the team deliberately keeps split, e.g. a generated/codegen import block adjacent to hand-written imports, or two imports separated to keep an eslint-disable or ts-expect-error scoped to just one of them.
Fix prompt
Use this once validation confirms the diagnostic is real.
Collapse the duplicate statements into a single import from that specifier, merging the default binding and the named bindings while preserving each original local alias: turn import Foo from "x"; import { a } from "x"; import { b } from "x"; into import Foo, { a, b } from "x";, deleting the now-empty redundant lines. A * as ns namespace import cannot share a statement with named bindings (import * as ns, { a } from "x" is a syntax error), so if a namespace import duplicates the specifier, either fold it onto a default (import Foo, * as ns from "x") or leave it as its own line and merge only the named/default imports. If all occurrences are import type, merge them into a single import type { a, b } from "x"; never merge a type-only import into a value import unless you convert it with the inline type modifier (import { value, type T } from "x"). One statement per module makes the dependency surface obvious and avoids drift when bindings change. See https://github.com/millionco/deslop-js