Skip to content

Commit 4045eed

Browse files
committed
fix
1 parent 01c9eb0 commit 4045eed

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/rules/no-duplicates.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,20 @@ function getFix(first, rest, sourceCode, context) {
261261

262262
/** @type {(imported: Map<string, import('estree').ImportDeclaration[]>, context: import('eslint').Rule.RuleContext) => void} */
263263
function checkImports(imported, context) {
264+
const preferInline = context.options[0] && context.options[0]['prefer-inline'];
265+
264266
for (const [module, nodes] of imported.entries()) {
265267
if (nodes.length > 1) {
268+
if (preferInline) {
269+
const typeImports = nodes.filter((node) => node.importKind === 'type');
270+
const sideEffectImports = nodes.filter((node) => node.specifiers.length === 0);
271+
const valueImports = nodes.filter((node) => !typeImports.includes(node) && !sideEffectImports.includes(node));
272+
273+
if (typeImports.length > 0 && sideEffectImports.length > 0 && valueImports.length === 0) {
274+
continue;
275+
}
276+
}
277+
266278
const message = `'${module}' imported multiple times.`;
267279
const [first, ...rest] = nodes;
268280
const sourceCode = getSourceCode(context);

tests/src/rules/no-duplicates.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,14 @@ context('TypeScript', function () {
552552
code: "import { type x } from './foo'; import type y from 'foo'",
553553
...parserConfig,
554554
}),
555+
test({
556+
code: `
557+
import type { A } from 'a';
558+
import 'a';
559+
`,
560+
options: [{ 'prefer-inline': true }],
561+
...parserConfig,
562+
}),
555563
]);
556564

557565
const invalid = [

0 commit comments

Comments
 (0)