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-unused-vars] SelfReferenced should see varsIgnorePattern #2679

Closed

Conversation

aggmoulik
Copy link
Contributor

@aggmoulik aggmoulik commented Oct 16, 2020

Fix: #2648
Signed-off-by: Moulik Aggarwal qwertymoulik@gmail.com

…norePattern

Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com>
@typescript-eslint
Copy link
Contributor

Thanks for the PR, @aggmoulik!

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 Oct 16, 2020

Codecov Report

Merging #2679 into master will decrease coverage by 0.02%.
The diff coverage is 25.00%.

@@            Coverage Diff             @@
##           master    #2679      +/-   ##
==========================================
- Coverage   92.82%   92.79%   -0.03%     
==========================================
  Files         294      294              
  Lines        9670     9674       +4     
  Branches     2712     2715       +3     
==========================================
+ Hits         8976     8977       +1     
- Misses        328      329       +1     
- Partials      366      368       +2     
Flag Coverage Δ
#unittest 92.79% <25.00%> (-0.03%) ⬇️

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

Impacted Files Coverage Δ
packages/eslint-plugin/src/rules/no-unused-vars.ts 90.56% <25.00%> (-2.58%) ⬇️

});
if (
varsIgnorePattern &&
varsIgnorePattern.toString() !== variable.name

Choose a reason for hiding this comment

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

varsIgnorePattern is a regexp (or perhaps still a regexp string).

See usage in eslint:
if (config.varsIgnorePattern && config.varsIgnorePattern.test(def.name.name)) {

https://github.com/eslint/eslint/blob/551b1e9fbc463db4869e738a8228868f7323788c/lib/rules/no-unused-vars.js#L590

Choose a reason for hiding this comment

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

And this error should be reported also when no varsIgnorePattern is given.

Choose a reason for hiding this comment

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

Do we need a similar change in line 148?

Copy link
Contributor Author

@aggmoulik aggmoulik Oct 16, 2020

Choose a reason for hiding this comment

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

Initially, I was confused on the same thing.
But, I found this as my reference to go for this method:

var varIgnorePattern: "all" | "local" | {
  vars?: "all" | "local" | undefined;
  varIgnorePattern:?: string | undefined;
  args: "all" | "after-used" | "none" | undefined;
  .........
  caughtErrorsIgnorePattern?: string | undefined;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doing the regex, I am having an error

varIgnorePattern.test(variable.name)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hy @HolgerJeromin, Can you guide me ?

Copy link

Choose a reason for hiding this comment

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

No, sorry. I never hacked around around eslint.
I can try to help after my vacation in one week

Copy link
Member

Choose a reason for hiding this comment

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

So here you'll need to convert the string to a regexp:

const varIgnorePattern =
  typeof options === 'object' && options.varIgnorePattern != null
    ? new RegExp(options.varsIgnorePattern, "u")
    : null;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have worked with the regex but how can I improve codecov ? @bradzacher

Copy link
Member

Choose a reason for hiding this comment

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

you'll need some tests! right now you have none at all.

@bradzacher bradzacher added bug Something isn't working awaiting response Issues waiting for a reply from the OP or another party labels Oct 16, 2020
Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com>
Signed-off-by: Moulik Aggarwal <qwertymoulik@gmail.com>
bradzacher added a commit that referenced this pull request Nov 16, 2020
I wanted to avoid doing this, but not doing this restricts our logic too much - it causes problems when we want to consider reporting on things that the base rule wouldn't report on.

Fixes #2714
Fixes #2648
Closes #2679
@bradzacher
Copy link
Member

Closing in favour of #2768

@bradzacher bradzacher closed this Nov 18, 2020
bradzacher added a commit that referenced this pull request Nov 22, 2020
I wanted to avoid doing this, but not doing this restricts our logic too much - it causes problems when we want to consider reporting on things that the base rule wouldn't report on.

Fixes #2714
Fixes #2648
Closes #2679
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[no-unused-var] varsIgnorePattern not working for this module definition
3 participants