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

Update ESLint config to accept separate type imports in TS again #5000

Merged
merged 1 commit into from
Jul 17, 2024

Conversation

p2edwards
Copy link
Contributor

@p2edwards p2edwards commented Jul 5, 2024

Description

Install eslint-plugin-import to improve the check for duplicate imports in TypeScript files. This permits the use of 2 imports again—when one is just for types. This was working before until updating typescript-eslint to v6, when they removed their version of this rule, deferring to the plugin.

Notes

Kudos to @magicznyleszek for pointing out this unwanted warning after #4985:

   import React from 'react'
   import type { ReactNode } from 'react'        // should be OK
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   ^ 'react' import is duplicated. // eslint(no-duplicate-imports)

In v6, typescript-eslint deprecated their version of the no-duplicate-imports rule, in favor of eslint-plugin-import. So, after #4985, TS code would fall back to the JS rule, which doesn't distinguish type-only imports.

What works now is to install and configure the suggested 'import' plugin and use their import/no-duplicates rule.

We can probably get more mileage out of this plugin, but for now I just want to get this rule working.

Related issues

Follow-up to #4985

e.g., not say 'duplicate import' for this code:

   import React from 'react'
   import type { ReactNode } from 'react'

…which used to work fine, but typescript-eslint's no-duplicate-imports
rule has been removed:

- typescript-eslint/typescript-eslint@47eeea9275bd
- https://typescript-eslint.io/rules/no-duplicate-imports/

We could do more with this plugin.

Only skimmed it, but some of the other features might require some
more config.

- https://github.com/import-js/eslint-plugin-import/blob/main/README.md#resolvers

(Meanwhile, I'll try not to think about how many dev dependencies
we bring in just for this cool rule.)
@p2edwards p2edwards added workflow Related to development process dependencies Pull requests that update a dependency file Front end labels Jul 5, 2024
@magicznyleszek magicznyleszek self-assigned this Jul 17, 2024
@magicznyleszek magicznyleszek merged commit bd881d9 into remove-context-types Jul 17, 2024
5 checks passed
@magicznyleszek magicznyleszek deleted the eslint-type-duplicate-imports branch July 17, 2024 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file Front end workflow Related to development process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants