Repository: un-ts/eslint-plugin-import-x
Pull request #162 (2024-09-28 03:42:41)

Fix incorrect no-duplicates prefer-inline default type import handling
I ran into this issue in one of my repositories with Koa:

```typescript
import { type Middleware } from 'koa';
import type Koa from 'koa';
```

The rule was rewriting it to invalid syntax:

```typescript
import Koa, type { Middleware } from 'koa';
```

One approach could be just to allow it to:

```typescript
import Koa, { type Middleware } from 'koa';
```

However, I don't think this plugin should be changing type imports into value imports in this scenario.
Therefore, after this change, it leaves the imports alone. I hope this should be not too controversial given it was previously producing invalid syntax. 

I am of course not an expert in this code :) but the change seems suspiciously simple. Are there any additional test cases I can add to help verify this? 

changeset-bot[bot]: ###  🦋  Changeset detected

Latest commit: abf7e3a56965cfc2631e6133b64f092b65be6d47

**The changes in this PR will be included in the next version bump.**

<details><summary>This PR includes changesets to release 1 package</summary>

  | Name                   | Type  |
| ---------------------- | ----- |
| eslint-plugin-import-x | Patch |

</details>

Not sure what this means? [Click here  to learn what changesets are](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/AaronMoat/eslint-plugin-import/new/default-type-import-prefer-inline?filename=.changeset/honest-spies-appear.md&value=---%0A%22eslint-plugin-import-x%22%3A%20patch%0A---%0A%0AFix%20incorrect%20no-duplicates%20prefer-inline%20default%20type%20import%20handling%0A)


codesandbox-ci[bot]: This pull request is automatically built and testable in [CodeSandbox](https://codesandbox.io).

  To see build info of the built libraries, click [here](https://ci.codesandbox.io/status/un-ts/eslint-plugin-import-x/pr/162/builds/545874) or the icon next to each commit SHA.
SukkaW: LGTM, I have approved the CI!

Patch:
diff --git a/.changeset/mighty-ladybugs-agree.md b/.changeset/mighty-ladybugs-agree.md
new file mode 100644
index 00000000..552ec821
--- /dev/null
+++ b/.changeset/mighty-ladybugs-agree.md
@@ -0,0 +1,5 @@
+---
+'eslint-plugin-import-x': patch
+---
+
+Fix issue where `no-duplicates` rule with `prefer-inline` incorrectly marks default type and named type imports as duplicates
diff --git a/src/rules/no-duplicates.ts b/src/rules/no-duplicates.ts
index b706541a..334b2071 100644
--- a/src/rules/no-duplicates.ts
+++ b/src/rules/no-duplicates.ts
@@ -463,12 +463,19 @@ export = createRule<[Options?], MessageId>({
         moduleMaps.set(parent, map)
       }
 
-      if (!preferInline && n.importKind === 'type') {
-        return n.specifiers.length > 0 &&
+      if (n.importKind === 'type') {
+        if (
+          n.specifiers.length > 0 &&
           n.specifiers[0].type === 'ImportDefaultSpecifier'
-          ? map.defaultTypesImported
-          : map.namedTypesImported
+        ) {
+          return map.defaultTypesImported
+        }
+
+        if (!preferInline) {
+          return map.namedTypesImported
+        }
       }
+
       if (
         !preferInline &&
         n.specifiers.some(


Test patch:
diff --git a/test/rules/no-duplicates.spec.ts b/test/rules/no-duplicates.spec.ts
index 3be9b76d..1fb645d5 100644
--- a/test/rules/no-duplicates.spec.ts
+++ b/test/rules/no-duplicates.spec.ts
@@ -682,6 +682,21 @@ describe('TypeScript', () => {
             ...parserConfig,
           }),
         ]),
+    test({
+      code: "import type { A } from 'foo';import type B from 'foo';",
+      ...parserConfig,
+      options: [{ 'prefer-inline': true }],
+    }),
+    test({
+      code: "import { type A } from 'foo';import type B from 'foo';",
+      ...parserConfig,
+      options: [{ 'prefer-inline': true }],
+    }),
+    test({
+      code: "import type A from 'foo';import { B } from 'foo';",
+      ...parserConfig,
+      options: [{ 'prefer-inline': true }],
+    }),
   ]
 
   const invalid = [