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

feat(eslint-plugin): add extension rule no-duplicate-imports #2609

Merged
merged 6 commits into from Oct 4, 2020
Merged

feat(eslint-plugin): add extension rule no-duplicate-imports #2609

merged 6 commits into from Oct 4, 2020

Conversation

yeonjuan
Copy link
Contributor

fixes #2315

I made an extension rule which distinguishes type-only import from standard import. :)

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @yeonjuan!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@codecov
Copy link

codecov bot commented Sep 29, 2020

Codecov Report

Merging #2609 into master will increase coverage by 0.01%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #2609      +/-   ##
==========================================
+ Coverage   92.82%   92.84%   +0.01%     
==========================================
  Files         293      294       +1     
  Lines        9619     9657      +38     
  Branches     2697     2709      +12     
==========================================
+ Hits         8929     8966      +37     
  Misses        326      326              
- Partials      364      365       +1     
Flag Coverage Δ
#unittest 92.84% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/eslint-plugin/src/configs/all.ts 100.00% <ø> (ø)
...es/eslint-plugin/src/rules/no-duplicate-imports.ts 97.36% <ø> (ø)

@bradzacher bradzacher added the enhancement: new base rule extension New base rule extension required to handle a TS specific case label Sep 29, 2020
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

LGTM - thanks for your contribution!

Comment on lines +86 to +88
if (typeImports.has(value)) {
report('exportTypeAs', node, value);
}
Copy link
Member

Choose a reason for hiding this comment

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

Wait... is this really how the base rule works?

What is wrong with the code

import { T } from 'foo';
export { A } from 'foo';

This seems like it's much better than

import { T, A } from 'foo';
export { A };

Because the latter code defines a local variable for no reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bradzacher right! This rule seems just focus on duplicate module sources.🤣

@bradzacher bradzacher merged commit 498f397 into typescript-eslint:master Oct 4, 2020
@richard-viney
Copy link

I've run into some false positives with this rule when used with import type.

Specifically, the following code triggers this new rule:

import type Foo from "my-module"
import type { Bar } from "my-module"

But it is not actually possible to write

import type Foo, { Bar } from "my-module"

because that results in the TypeScript error

A type-only import can specify a default import or named bindings, but not both.ts(1363)

This rule may need some additional logic to handle this case.

@bradzacher
Copy link
Member

please file a new issue.

@richard-viney
Copy link

New issue is here: #2636

parser: '@typescript-eslint/parser',
});

ruleTester.run('no-dupe-class-members', rule, {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi :)
Isn't this rule id should be no-duplicate-imports, not no-dupe-class-members?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new base rule extension New base rule extension required to handle a TS specific case
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[no-duplicate-imports] false positive rule on "import type"
4 participants