From a0c9350f8d4b88707d2b239c288887c68e86befa Mon Sep 17 00:00:00 2001 From: steved Date: Thu, 13 Feb 2025 16:01:55 -0500 Subject: [PATCH 1/3] no-duplicates: fix false positive --- src/rules/no-duplicates.ts | 3 ++- test/rules/no-duplicates.spec.ts | 34 ++++++++++++++++---------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/rules/no-duplicates.ts b/src/rules/no-duplicates.ts index 2a5d5893..cec3e6a8 100644 --- a/src/rules/no-duplicates.ts +++ b/src/rules/no-duplicates.ts @@ -489,7 +489,8 @@ export = createRule<[Options?], MessageId>({ if ( !preferInline && - n.specifiers.some( + n.specifiers.length > 0 && + n.specifiers.every( spec => 'importKind' in spec && spec.importKind === 'type', ) ) { diff --git a/test/rules/no-duplicates.spec.ts b/test/rules/no-duplicates.spec.ts index e9636fdc..47084364 100644 --- a/test/rules/no-duplicates.spec.ts +++ b/test/rules/no-duplicates.spec.ts @@ -565,6 +565,23 @@ describe('TypeScript', () => { code: "import type x from './foo'; import type {y} from './foo'", ...parserConfig, }), + tValid({ + code: ` + import { + type bar, + buzz, + } from 'foo'; + import type {bizz} from 'foo'; + `, + ...parserConfig, + }), + tValid({ + code: ` +import {AValue, type x, BValue} from './foo'; +import {type y} from './foo' + `, + ...parserConfig, + }), tValid({ code: ` import type {} from './module'; @@ -782,23 +799,6 @@ describe('TypeScript', () => { }, ], }), - tInvalid({ - code: "import {AValue, type x, BValue} from './foo'; import {type y} from './foo'", - ...parserConfig, - output: `import {AValue, type x, BValue,type y} from './foo'; `, - errors: [ - { - ...createDuplicatedError('./foo'), - line: 1, - column: 38, - }, - { - ...createDuplicatedError('./foo'), - line: 1, - column: 68, - }, - ], - }), // #2834 Detect duplicates across type and regular imports tInvalid({ code: "import {AValue} from './foo'; import type {AType} from './foo'", From c2091cc904bffd160dc3ca2aa14d4ca368287d66 Mon Sep 17 00:00:00 2001 From: steved Date: Wed, 26 Feb 2025 09:44:34 -0800 Subject: [PATCH 2/3] wip: update test cases --- test/rules/no-duplicates.spec.ts | 57 ++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/test/rules/no-duplicates.spec.ts b/test/rules/no-duplicates.spec.ts index 47084364..1ddf98eb 100644 --- a/test/rules/no-duplicates.spec.ts +++ b/test/rules/no-duplicates.spec.ts @@ -565,23 +565,6 @@ describe('TypeScript', () => { code: "import type x from './foo'; import type {y} from './foo'", ...parserConfig, }), - tValid({ - code: ` - import { - type bar, - buzz, - } from 'foo'; - import type {bizz} from 'foo'; - `, - ...parserConfig, - }), - tValid({ - code: ` -import {AValue, type x, BValue} from './foo'; -import {type y} from './foo' - `, - ...parserConfig, - }), tValid({ code: ` import type {} from './module'; @@ -799,6 +782,46 @@ import {type y} from './foo' }, ], }), + tInvalid({ + code: ` + import { + type bar, + buzz, + } from 'foo'; + import type {bizz} from 'foo'; + `, + ...parserConfig, + output: `import {type bar, buzz, type bizz} from 'foo'; `, + errors: [ + { + ...createDuplicatedError('foo'), + line: 1, + column: 38, + }, + { + ...createDuplicatedError('foo'), + line: 1, + column: 68, + }, + ], + }), + tInvalid({ + code: "import {AValue, type x, BValue} from './foo'; import {type y} from './foo'", + ...parserConfig, + output: `import {AValue, type x, BValue,type y} from './foo'; `, + errors: [ + { + ...createDuplicatedError('./foo'), + line: 1, + column: 38, + }, + { + ...createDuplicatedError('./foo'), + line: 1, + column: 68, + }, + ], + }), // #2834 Detect duplicates across type and regular imports tInvalid({ code: "import {AValue} from './foo'; import type {AType} from './foo'", From 098ee4ceb984fc3f89137182af59314c001f9681 Mon Sep 17 00:00:00 2001 From: steved Date: Wed, 26 Feb 2025 09:46:52 -0800 Subject: [PATCH 3/3] undo changes to rule --- src/rules/no-duplicates.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rules/no-duplicates.ts b/src/rules/no-duplicates.ts index cec3e6a8..2a5d5893 100644 --- a/src/rules/no-duplicates.ts +++ b/src/rules/no-duplicates.ts @@ -489,8 +489,7 @@ export = createRule<[Options?], MessageId>({ if ( !preferInline && - n.specifiers.length > 0 && - n.specifiers.every( + n.specifiers.some( spec => 'importKind' in spec && spec.importKind === 'type', ) ) {