Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] no-duplicates: Removing duplicates breaks in TypeScript #3033

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

yesl-kim
Copy link
Contributor

@yesl-kim yesl-kim commented Aug 11, 2024

This PR addresses the issue where multiple import type statements from the same module are not properly combined when the prefer-inline option is enabled. Specifically, the problem arises when importing types with separate import type statements, which should be consolidated into a single import statement with inline type specifiers.

Fixes #3016, fixes #2792.

Given the following code:

import type { x } from 'foo';
import { type y } from 'foo';

as-is:

import type { x, type y } from 'foo';

to-be:

import { type x, type y } from 'foo';

Copy link

codecov bot commented Aug 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.91%. Comparing base (09476d7) to head (eb8882d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3033      +/-   ##
==========================================
- Coverage   96.02%   95.91%   -0.12%     
==========================================
  Files          78       78              
  Lines        3299     3305       +6     
  Branches     1160     1162       +2     
==========================================
+ Hits         3168     3170       +2     
- Misses        131      135       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ljharb ljharb force-pushed the fix/3016-no-duplicate-in-typescript branch from eb8882d to 4bdf61a Compare August 29, 2024 04:53
@ljharb ljharb changed the title fix: Removing duplicates breaks in TypeScript [Fix] no-duplicates: Removing duplicates breaks in TypeScript Aug 29, 2024
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@ljharb ljharb merged commit 4bdf61a into import-js:main Aug 29, 2024
309 checks passed
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Sep 4, 2024
| datasource | package              | from   | to     |
| ---------- | -------------------- | ------ | ------ |
| npm        | eslint-plugin-import | 2.29.1 | 2.30.0 |


## [v2.30.0](https://github.com/import-js/eslint-plugin-import/blob/HEAD/CHANGELOG.md#2300---2024-09-02)

##### Added

-   \[`dynamic-import-chunkname`]: add `allowEmpty` option to allow empty leading comments (\[[#2942](import-js/eslint-plugin-import#2942)], thanks \[[@JiangWeixian](https://github.com/JiangWeixian)])
-   \[`dynamic-import-chunkname`]: Allow empty chunk name when webpackMode: 'eager' is set; add suggestions to remove name in eager mode (\[[#3004](import-js/eslint-plugin-import#3004)], thanks \[[@amsardesai](https://github.com/amsardesai)])
-   \[`no-unused-modules`]: Add `ignoreUnusedTypeExports` option (\[[#3011](import-js/eslint-plugin-import#3011)], thanks \[[@silverwind](https://github.com/silverwind)])
-   add support for Flat Config (\[[#3018](import-js/eslint-plugin-import#3018)], thanks \[[@michaelfaith](https://github.com/michaelfaith)])

##### Fixed

-   \[`no-extraneous-dependencies`]: allow wrong path (\[[#3012](import-js/eslint-plugin-import#3012)], thanks \[[@chabb](https://github.com/chabb)])
-   \[`no-cycle`]: use scc algorithm to optimize (\[[#2998](import-js/eslint-plugin-import#2998)], thanks \[[@soryy708](https://github.com/soryy708)])
-   \[`no-duplicates`]: Removing duplicates breaks in TypeScript (\[[#3033](import-js/eslint-plugin-import#3033)], thanks \[[@yesl-kim](https://github.com/yesl-kim)])
-   \[`newline-after-import`]: fix considerComments option when require (\[[#2952](import-js/eslint-plugin-import#2952)], thanks \[[@developer-bandi](https://github.com/developer-bandi)])
-   \[`order`]: do not compare first path segment for relative paths (\[[#2682](import-js/eslint-plugin-import#2682)]) (\[[#2885](import-js/eslint-plugin-import#2885)], thanks \[[@mihkeleidast](https://github.com/mihkeleidast)])

##### Changed

-   \[Docs] `no-extraneous-dependencies`: Make glob pattern description more explicit (\[[#2944](import-js/eslint-plugin-import#2944)], thanks \[[@mulztob](https://github.com/mulztob)])
-   \[`no-unused-modules`]: add console message to help debug \[[#2866](import-js/eslint-plugin-import#2866)]
-   \[Refactor] `ExportMap`: make procedures static instead of monkeypatching exportmap (\[[#2982](import-js/eslint-plugin-import#2982)], thanks \[[@soryy708](https://github.com/soryy708)])
-   \[Refactor] `ExportMap`: separate ExportMap instance from its builder logic (\[[#2985](import-js/eslint-plugin-import#2985)], thanks \[[@soryy708](https://github.com/soryy708)])
-   \[Docs] `order`: Add a quick note on how unbound imports and --fix (\[[#2640](import-js/eslint-plugin-import#2640)], thanks \[[@MinervaBot](https://github.com/minervabot)])
-   \[Tests] appveyor -> GHA (run tests on Windows in both pwsh and WSL + Ubuntu) (\[[#2987](import-js/eslint-plugin-import#2987)], thanks \[[@joeyguerra](https://github.com/joeyguerra)])
-   \[actions] migrate OSX tests to GHA (\[[ljharb#37](ljharb/eslint-plugin-import#37)], thanks \[[@aks-](https://github.com/aks-)])
-   \[Refactor] `exportMapBuilder`: avoid hoisting (\[[#2989](import-js/eslint-plugin-import#2989)], thanks \[[@soryy708](https://github.com/soryy708)])
-   \[Refactor] `ExportMap`: extract "builder" logic to separate files (\[[#2991](import-js/eslint-plugin-import#2991)], thanks \[[@soryy708](https://github.com/soryy708)])
-   \[Docs] \[`order`]: update the description of the `pathGroupsExcludedImportTypes` option (\[[#3036](import-js/eslint-plugin-import#3036)], thanks \[[@liby](https://github.com/liby)])
-   \[readme] Clarify how to install the plugin (\[[#2993](import-js/eslint-plugin-import#2993)], thanks \[[@jwbth](https://github.com/jwbth)])
SukkaW added a commit to SukkaW/eslint-plugin-import-x that referenced this pull request Sep 4, 2024
SukkaW added a commit to un-ts/eslint-plugin-import-x that referenced this pull request Sep 4, 2024
* fix: backports import-js#3033

* ci: cancel-in-progress when pr is updated

backports import-js#2997

* fix: backports import-js#2952

* docs: improve `order` rule docs

Backports:
- import-js#2640
- import-js#3036
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Sep 4, 2024
##### [v4.2.1](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#421)

##### Patch Changes

-   [#148](un-ts/eslint-plugin-import-x#148) [`d228129`](un-ts/eslint-plugin-import-x@d228129) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix `newline-after-import`'s `considerComments` options when linting `require`, backports import-js/eslint-plugin-import#2952

-   [#147](un-ts/eslint-plugin-import-x#147) [`eca73ed`](un-ts/eslint-plugin-import-x@eca73ed) Thanks [@nchevsky](https://github.com/nchevsky)! - Fix regression in rule `no-unused-modules` which would incorrectly initialize option `src` to `[]` instead of `[process.cwd()]`, breaking file discovery.

-   [#148](un-ts/eslint-plugin-import-x#148) [`d228129`](un-ts/eslint-plugin-import-x@d228129) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix `no-duplicates` for TypeScript, backports import-js/eslint-plugin-import#3033
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Sep 17, 2024
##### [v4.2.1](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#421)

##### Patch Changes

-   [#148](un-ts/eslint-plugin-import-x#148) [`d228129`](un-ts/eslint-plugin-import-x@d228129) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix `newline-after-import`'s `considerComments` options when linting `require`, backports import-js/eslint-plugin-import#2952

-   [#147](un-ts/eslint-plugin-import-x#147) [`eca73ed`](un-ts/eslint-plugin-import-x@eca73ed) Thanks [@nchevsky](https://github.com/nchevsky)! - Fix regression in rule `no-unused-modules` which would incorrectly initialize option `src` to `[]` instead of `[process.cwd()]`, breaking file discovery.

-   [#148](un-ts/eslint-plugin-import-x#148) [`d228129`](un-ts/eslint-plugin-import-x@d228129) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix `no-duplicates` for TypeScript, backports import-js/eslint-plugin-import#3033
##### [v4.2.0](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#420)

##### Minor Changes

-   [#142](un-ts/eslint-plugin-import-x#142) [`f12447e`](un-ts/eslint-plugin-import-x@f12447e) Thanks [@Zamiell](https://github.com/Zamiell)! - Add new option "whitelist" for rule "no-extraneous-dependencies"

##### Patch Changes

-   [#146](un-ts/eslint-plugin-import-x#146) [`e5e4580`](un-ts/eslint-plugin-import-x@e5e4580) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix nuxt/eslint#494 by avoid importing from `@typescript-eslint/typescript-estree`.
##### [v4.1.1](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#411)

##### Patch Changes

-   [#133](un-ts/eslint-plugin-import-x#133) [`757ffa9`](un-ts/eslint-plugin-import-x@757ffa9) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix [#123](un-ts/eslint-plugin-import-x#123) where the rule `no-named-as-default` will confuse TypeScript namespace exports with actual exports.
##### [v4.1.0](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#410)

##### Minor Changes

-   [#122](un-ts/eslint-plugin-import-x#122) [`cd52e86`](un-ts/eslint-plugin-import-x@cd52e86) Thanks [@michaelfaith](https://github.com/michaelfaith)! - Add ESLint flat configuration presets. You can access them with:

    ```ts
    import eslintPluginImportX from "eslint-plugin-import-x";

    eslintPluginImportX.flatConfigs.recommended;
    eslintPluginImportX.flatConfigs.react;
    eslintPluginImportX.flatConfigs.typescript;
    eslintPluginImportX.flatConfigs.electron;
    ```

-   [#132](un-ts/eslint-plugin-import-x#132) [`9948c78`](un-ts/eslint-plugin-import-x@9948c78) Thanks [@SukkaW](https://github.com/SukkaW)! - Added `no-rename-default` that forbid importing a default export by a different name. Originally created by [@whitneyit](https://github.com/whitneyit), ported by [@SukkaW](https://github.com/SukkaW)
##### [v4.0.0](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#400)

##### Major Changes

-   [#112](un-ts/eslint-plugin-import-x#112) [`4ba14da`](un-ts/eslint-plugin-import-x@4ba14da) Thanks [@SukkaW](https://github.com/SukkaW)! - Use typescript-eslint v8. The minimum supported ESLint version is now >= 8.57.0 and the minimum required Node.js version is now 18.18.0.
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Sep 17, 2024
##### [v4.2.1](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#421)

##### Patch Changes

-   [#148](un-ts/eslint-plugin-import-x#148) [`d228129`](un-ts/eslint-plugin-import-x@d228129) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix `newline-after-import`'s `considerComments` options when linting `require`, backports import-js/eslint-plugin-import#2952

-   [#147](un-ts/eslint-plugin-import-x#147) [`eca73ed`](un-ts/eslint-plugin-import-x@eca73ed) Thanks [@nchevsky](https://github.com/nchevsky)! - Fix regression in rule `no-unused-modules` which would incorrectly initialize option `src` to `[]` instead of `[process.cwd()]`, breaking file discovery.

-   [#148](un-ts/eslint-plugin-import-x#148) [`d228129`](un-ts/eslint-plugin-import-x@d228129) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix `no-duplicates` for TypeScript, backports import-js/eslint-plugin-import#3033
##### [v4.2.0](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#420)

##### Minor Changes

-   [#142](un-ts/eslint-plugin-import-x#142) [`f12447e`](un-ts/eslint-plugin-import-x@f12447e) Thanks [@Zamiell](https://github.com/Zamiell)! - Add new option "whitelist" for rule "no-extraneous-dependencies"

##### Patch Changes

-   [#146](un-ts/eslint-plugin-import-x#146) [`e5e4580`](un-ts/eslint-plugin-import-x@e5e4580) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix nuxt/eslint#494 by avoid importing from `@typescript-eslint/typescript-estree`.
##### [v4.1.1](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#411)

##### Patch Changes

-   [#133](un-ts/eslint-plugin-import-x#133) [`757ffa9`](un-ts/eslint-plugin-import-x@757ffa9) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix [#123](un-ts/eslint-plugin-import-x#123) where the rule `no-named-as-default` will confuse TypeScript namespace exports with actual exports.
##### [v4.1.0](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#410)

##### Minor Changes

-   [#122](un-ts/eslint-plugin-import-x#122) [`cd52e86`](un-ts/eslint-plugin-import-x@cd52e86) Thanks [@michaelfaith](https://github.com/michaelfaith)! - Add ESLint flat configuration presets. You can access them with:

    ```ts
    import eslintPluginImportX from "eslint-plugin-import-x";

    eslintPluginImportX.flatConfigs.recommended;
    eslintPluginImportX.flatConfigs.react;
    eslintPluginImportX.flatConfigs.typescript;
    eslintPluginImportX.flatConfigs.electron;
    ```

-   [#132](un-ts/eslint-plugin-import-x#132) [`9948c78`](un-ts/eslint-plugin-import-x@9948c78) Thanks [@SukkaW](https://github.com/SukkaW)! - Added `no-rename-default` that forbid importing a default export by a different name. Originally created by [@whitneyit](https://github.com/whitneyit), ported by [@SukkaW](https://github.com/SukkaW)
##### [v4.0.0](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#400)

##### Major Changes

-   [#112](un-ts/eslint-plugin-import-x#112) [`4ba14da`](un-ts/eslint-plugin-import-x@4ba14da) Thanks [@SukkaW](https://github.com/SukkaW)! - Use typescript-eslint v8. The minimum supported ESLint version is now >= 8.57.0 and the minimum required Node.js version is now 18.18.0.
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Sep 17, 2024
##### [v4.2.1](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#421)

##### Patch Changes

-   [#148](un-ts/eslint-plugin-import-x#148) [`d228129`](un-ts/eslint-plugin-import-x@d228129) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix `newline-after-import`'s `considerComments` options when linting `require`, backports import-js/eslint-plugin-import#2952

-   [#147](un-ts/eslint-plugin-import-x#147) [`eca73ed`](un-ts/eslint-plugin-import-x@eca73ed) Thanks [@nchevsky](https://github.com/nchevsky)! - Fix regression in rule `no-unused-modules` which would incorrectly initialize option `src` to `[]` instead of `[process.cwd()]`, breaking file discovery.

-   [#148](un-ts/eslint-plugin-import-x#148) [`d228129`](un-ts/eslint-plugin-import-x@d228129) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix `no-duplicates` for TypeScript, backports import-js/eslint-plugin-import#3033
##### [v4.2.0](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#420)

##### Minor Changes

-   [#142](un-ts/eslint-plugin-import-x#142) [`f12447e`](un-ts/eslint-plugin-import-x@f12447e) Thanks [@Zamiell](https://github.com/Zamiell)! - Add new option "whitelist" for rule "no-extraneous-dependencies"

##### Patch Changes

-   [#146](un-ts/eslint-plugin-import-x#146) [`e5e4580`](un-ts/eslint-plugin-import-x@e5e4580) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix nuxt/eslint#494 by avoid importing from `@typescript-eslint/typescript-estree`.
##### [v4.1.1](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#411)

##### Patch Changes

-   [#133](un-ts/eslint-plugin-import-x#133) [`757ffa9`](un-ts/eslint-plugin-import-x@757ffa9) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix [#123](un-ts/eslint-plugin-import-x#123) where the rule `no-named-as-default` will confuse TypeScript namespace exports with actual exports.
##### [v4.1.0](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#410)

##### Minor Changes

-   [#122](un-ts/eslint-plugin-import-x#122) [`cd52e86`](un-ts/eslint-plugin-import-x@cd52e86) Thanks [@michaelfaith](https://github.com/michaelfaith)! - Add ESLint flat configuration presets. You can access them with:

    ```ts
    import eslintPluginImportX from "eslint-plugin-import-x";

    eslintPluginImportX.flatConfigs.recommended;
    eslintPluginImportX.flatConfigs.react;
    eslintPluginImportX.flatConfigs.typescript;
    eslintPluginImportX.flatConfigs.electron;
    ```

-   [#132](un-ts/eslint-plugin-import-x#132) [`9948c78`](un-ts/eslint-plugin-import-x@9948c78) Thanks [@SukkaW](https://github.com/SukkaW)! - Added `no-rename-default` that forbid importing a default export by a different name. Originally created by [@whitneyit](https://github.com/whitneyit), ported by [@SukkaW](https://github.com/SukkaW)
##### [v4.0.0](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#400)

##### Major Changes

-   [#112](un-ts/eslint-plugin-import-x#112) [`4ba14da`](un-ts/eslint-plugin-import-x@4ba14da) Thanks [@SukkaW](https://github.com/SukkaW)! - Use typescript-eslint v8. The minimum supported ESLint version is now >= 8.57.0 and the minimum required Node.js version is now 18.18.0.
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Sep 17, 2024
##### [v4.2.1](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#421)

##### Patch Changes

-   [#148](un-ts/eslint-plugin-import-x#148) [`d228129`](un-ts/eslint-plugin-import-x@d228129) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix `newline-after-import`'s `considerComments` options when linting `require`, backports import-js/eslint-plugin-import#2952

-   [#147](un-ts/eslint-plugin-import-x#147) [`eca73ed`](un-ts/eslint-plugin-import-x@eca73ed) Thanks [@nchevsky](https://github.com/nchevsky)! - Fix regression in rule `no-unused-modules` which would incorrectly initialize option `src` to `[]` instead of `[process.cwd()]`, breaking file discovery.

-   [#148](un-ts/eslint-plugin-import-x#148) [`d228129`](un-ts/eslint-plugin-import-x@d228129) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix `no-duplicates` for TypeScript, backports import-js/eslint-plugin-import#3033
##### [v4.2.0](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#420)

##### Minor Changes

-   [#142](un-ts/eslint-plugin-import-x#142) [`f12447e`](un-ts/eslint-plugin-import-x@f12447e) Thanks [@Zamiell](https://github.com/Zamiell)! - Add new option "whitelist" for rule "no-extraneous-dependencies"

##### Patch Changes

-   [#146](un-ts/eslint-plugin-import-x#146) [`e5e4580`](un-ts/eslint-plugin-import-x@e5e4580) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix nuxt/eslint#494 by avoid importing from `@typescript-eslint/typescript-estree`.
##### [v4.1.1](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#411)

##### Patch Changes

-   [#133](un-ts/eslint-plugin-import-x#133) [`757ffa9`](un-ts/eslint-plugin-import-x@757ffa9) Thanks [@SukkaW](https://github.com/SukkaW)! - Fix [#123](un-ts/eslint-plugin-import-x#123) where the rule `no-named-as-default` will confuse TypeScript namespace exports with actual exports.
##### [v4.1.0](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#410)

##### Minor Changes

-   [#122](un-ts/eslint-plugin-import-x#122) [`cd52e86`](un-ts/eslint-plugin-import-x@cd52e86) Thanks [@michaelfaith](https://github.com/michaelfaith)! - Add ESLint flat configuration presets. You can access them with:

    ```ts
    import eslintPluginImportX from "eslint-plugin-import-x";

    eslintPluginImportX.flatConfigs.recommended;
    eslintPluginImportX.flatConfigs.react;
    eslintPluginImportX.flatConfigs.typescript;
    eslintPluginImportX.flatConfigs.electron;
    ```

-   [#132](un-ts/eslint-plugin-import-x#132) [`9948c78`](un-ts/eslint-plugin-import-x@9948c78) Thanks [@SukkaW](https://github.com/SukkaW)! - Added `no-rename-default` that forbid importing a default export by a different name. Originally created by [@whitneyit](https://github.com/whitneyit), ported by [@SukkaW](https://github.com/SukkaW)
##### [v4.0.0](https://github.com/un-ts/eslint-plugin-import-x/blob/HEAD/CHANGELOG.md#400)

##### Major Changes

-   [#112](un-ts/eslint-plugin-import-x#112) [`4ba14da`](un-ts/eslint-plugin-import-x@4ba14da) Thanks [@SukkaW](https://github.com/SukkaW)! - Use typescript-eslint v8. The minimum supported ESLint version is now >= 8.57.0 and the minimum required Node.js version is now 18.18.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants