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(eslint-plugin): [no-shadow] ignore type-only imports properly #3868

Merged
merged 2 commits into from Sep 21, 2021

Conversation

rafaelss95
Copy link
Contributor

@rafaelss95 rafaelss95 commented Sep 12, 2021

Fixes #3862.

@typescript-eslint
Copy link
Contributor

@typescript-eslint typescript-eslint bot commented Sep 12, 2021

Thanks for the PR, @rafaelss95!

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 12, 2021

Codecov Report

Merging #3868 (ebea51a) into master (4195919) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #3868   +/-   ##
=======================================
  Coverage   93.50%   93.51%           
=======================================
  Files         151      151           
  Lines        8134     8137    +3     
  Branches     2580     2581    +1     
=======================================
+ Hits         7606     7609    +3     
  Misses        167      167           
  Partials      361      361           
Flag Coverage Δ
unittest 93.51% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
packages/eslint-plugin/src/rules/no-shadow.ts 77.16% <100.00%> (+0.55%) ⬆️

@bradzacher bradzacher added the bug label Sep 13, 2021
Copy link
Member

@bradzacher bradzacher left a comment

thanks for this!
almost there

@@ -99,7 +99,9 @@ export default util.createRule<Options, MessageIds>({
}

const isShadowedValue =
'isValueVariable' in shadowed ? shadowed.isValueVariable : true;
!('isValueVariable' in shadowed) ||
(shadowed.defs[0]?.type !== DefinitionType.ImportBinding &&
Copy link
Member

@bradzacher bradzacher Sep 20, 2021

Choose a reason for hiding this comment

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

this isn't quite correct because it will match all import variables.
We specifically only want to match variables imported via import type.

Copy link
Contributor Author

@rafaelss95 rafaelss95 Sep 21, 2021

Choose a reason for hiding this comment

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

Good catch! It should be fixed with the fixup.

@bradzacher bradzacher added the awaiting response label Sep 20, 2021
@bradzacher
Copy link
Member

@bradzacher bradzacher commented Sep 20, 2021

This is off-topic from your current change - could you please also update these two lines:

return variable.defs[0].type === 'Parameter' && variable.name === 'this';

((innerDef.type === 'FunctionName' &&

To use DefinitionType like you've imported? It'd be great to ensure we're doing the comparisons the same everywhere :)

@rafaelss95
Copy link
Contributor Author

@rafaelss95 rafaelss95 commented Sep 20, 2021

This is off-topic from your current change - could you please also update these two lines:

return variable.defs[0].type === 'Parameter' && variable.name === 'this';

((innerDef.type === 'FunctionName' &&

To use DefinitionType like you've imported? It'd be great to ensure we're doing the comparisons the same everywhere :)

What about adding DefinitionType to prefer-ast-types-enum rule and fix all possible occurrences once in a separate PR? Would this work for you?

@bradzacher
Copy link
Member

@bradzacher bradzacher commented Sep 21, 2021

What about adding DefinitionType to prefer-ast-types-enum rule and fix all possible occurrences once in a separate PR? Would this work for you?

You can certainly give that a go - I'm not sure if that will false-positive a lot (due to words like Variable and Type being part of the member). It might be noisy - but we can see if it is or not.

There's an open issue to create a generic rule to do that enum check (#308)

@rafaelss95
Copy link
Contributor Author

@rafaelss95 rafaelss95 commented Sep 21, 2021

I've tested it locally and I think it'll be fine, I'll send it ASAP.

Copy link
Member

@bradzacher bradzacher left a comment

LGTM - thanks for your work here!

@bradzacher bradzacher merged commit dda9cee into typescript-eslint:master Sep 21, 2021
11 checks passed
@rafaelss95 rafaelss95 deleted the fix/3862 branch Sep 21, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants