no-duplicate-imports

禁止重复的模块导入

每个模块使用单个 import 语句将使代码更清晰,因为您可以在一行中看到从该模块导入的所有内容。

在以下示例中,第 1 行的 module 导入在第 3 行重复。这些可以结合起来使进口清单更加简洁。

import { merge } from 'module';
import something from 'another-module';
import { find } from 'module';

规则详情

此规则要求来自单个模块的所有可以合并的导入都存在于单个 import 语句中。

此规则的错误代码示例:

/*eslint no-duplicate-imports: "error"*/

import { merge } from 'module';
import something from 'another-module';
import { find } from 'module';

FphvHt5MK/G5o4JKMpo8wFZScNX7kGyQzE3xqEeYlFcVQkbgr+qufrIGgDR/9BRp

/*eslint no-duplicate-imports: "error"*/

import { merge, find } from 'module';
import something from 'another-module';

FphvHt5MK/G5o4JKMpo8wFZScNX7kGyQzE3xqEeYlFcVQkbgr+qufrIGgDR/9BRp

/*eslint no-duplicate-imports: "error"*/

// not mergeable
import { merge } from 'module';
import * as something from 'module';

选项

33Vaz9A/DaOnyGHibdQF4B5SOsvt2KWxQqnE9GDkFsTseMXZk73emtmxuAFmQaHzjf8ScZQlsabj4cQOYYvaQJyN8YRVQjJAKXaU97T5kO94OqhSMdMeJzFdz40TryS60be54msSyiogE6J/RuZsHTb7Bx9BP8e+edQugJprZt6r9s3TQ9Ahht2DYCr/Lh7JxoGGdnPHcOT6EoqBpiv8vg==

DrzStDiLcg3fE+QiNufATvgUSnHhogybtmU3I4xkSLrldL8aSqa8Iuw0kmcLUSDC58nMfU4sd7H29G/g22mWE8dcEqPtKwzhEX6XjK1MzgtrztTnENMV5djT3nb9no9PmaCA9mWXORk70WhO7tuYGbUkAThyLUOM3Lz4g2i/ab1r35M4108ZSx6GK+9WAtY3dcGhd9Kb8RIgkIYCF3bNDiDwinWktpUUEbYTk8tf7zQ=

NSbpfabEcDXeZZ6HG41LXERFTErSI1uh8cZWUjEXNV1XWtHDh6i8GiXTNxrKTXk6Ju+9QGGIBnqEuanVZ236fzXWq0W6ebGi6HDUxEuhJjRd9rppFl88FNOZ4dLwrRMN

/*eslint no-duplicate-imports: ["error", { "includeExports": true }]*/

import { merge } from 'module';

export { find } from 'module';

nQP82WYZJTVvhOZX4UTE6HQ5m94y7aQA5+11LN9NNoQ0BYNUiVLpye/alI7q9rs/dOx228cejIWZ9QBsXKQwuw0Z91fKyx5NmtWheEcSwG+cZsMXCO3Jcexq2BNRmHxH

/*eslint no-duplicate-imports: ["error", { "includeExports": true }]*/

import { merge, find } from 'module';

export { find };

nQP82WYZJTVvhOZX4UTE6HQ5m94y7aQA5+11LN9NNoQ0BYNUiVLpye/alI7q9rs/dOx228cejIWZ9QBsXKQwuw0Z91fKyx5NmtWheEcSwG+cZsMXCO3Jcexq2BNRmHxH

/*eslint no-duplicate-imports: ["error", { "includeExports": true }]*/

import { merge, find } from 'module';

// cannot be merged with the above import
export * as something from 'module';

// cannot be written differently
export * from 'module';