Skip to content

import/no-duplicates Style

What it does

Reports if a resolved path is imported more than once in the same module. This helps avoid unnecessary duplicate imports and keeps the code clean.

Why is this bad?

Importing the same module multiple times can lead to redundancy and unnecessary complexity. It also affects maintainability, as it might confuse developers and result in inconsistent usage of imports across the code.

Examples

Examples of incorrect code for this rule:

javascript
import { foo } from "./module";
import { bar } from "./module";

import a from "./module";
import { b } from "./module";

Examples of correct code for this rule:

typescript
import { bar, foo } from "./module";

import * as a from "foo"; // separate statements for namespace imports
import { b } from "foo";

import { c } from "foo"; // separate type imports, unless
import type { d } from "foo"; // `preferInline` is true

Configuration

This rule accepts a configuration object with the following properties:

preferInline

type: boolean

default: false

When set to true, prefer inline type imports instead of separate type import statements for TypeScript code.

Examples of correct code with this option set to true:

typescript
import { type Bar, Foo } from "./module";

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny import/no-duplicates --import-plugin
json
{
  "plugins": ["import"],
  "rules": {
    "import/no-duplicates": "error"
  }
}

References

Released under the MIT License.