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

Conversation

@yeonjuan
Copy link
Contributor

@yeonjuan yeonjuan commented Sep 29, 2020

fixes #2315

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

@typescript-eslint
Copy link

@typescript-eslint typescript-eslint bot commented Sep 29, 2020

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 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% <ø> (ø)
yeonjuan added 3 commits Sep 29, 2020
Copy link
Member

@bradzacher bradzacher left a comment

LGTM - thanks for your contribution!

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

This comment has been minimized.

@bradzacher

bradzacher Oct 4, 2020
Member

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.

This comment has been minimized.

@yeonjuan

yeonjuan Oct 4, 2020
Author Contributor

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

@bradzacher bradzacher merged commit 498f397 into typescript-eslint:master Oct 4, 2020
10 checks passed
10 checks passed
Typecheck
Details
Unit tests Unit tests
Details
Code style and lint
Details
Run integration tests on primary Node.js version
Details
Run unit tests on other Node.js versions (10.x)
Details
Run unit tests on other Node.js versions (14.x)
Details
Publish the latest code as a canary version
Details
Semantic Pull Request ready to be squashed
Details
codecov/patch Codecov Report
Details
codecov/project Codecov Report
Details
@richard-viney
Copy link

@richard-viney richard-viney commented Oct 6, 2020

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

@bradzacher bradzacher commented Oct 6, 2020

please file a new issue.

@richard-viney
Copy link

@richard-viney richard-viney commented Oct 6, 2020

New issue is here: #2636

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

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

This comment has been minimized.

@ginger-kang

ginger-kang Oct 6, 2020
Contributor

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.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants