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): new extended rule 'no-invalid-this' #1823

Merged
merged 11 commits into from May 4, 2020

Conversation

anikethsaha
Copy link
Contributor

@anikethsaha anikethsaha commented Mar 30, 2020

Supports functions with a this argument

Fixes #604

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @anikethsaha!

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.

@bradzacher bradzacher changed the title feat(eslint-plugin): new extendedrule 'no-invalid-this' feat(eslint-plugin): new extended rule 'no-invalid-this' Mar 30, 2020
@bradzacher bradzacher added the enhancement: new base rule extension New base rule extension required to handle a TS specific case label Mar 30, 2020
@anikethsaha
Copy link
Contributor Author

@bradzacher any suggestion to fix this ?

image

@bradzacher
Copy link
Member

The error message gives you the reason that it is incompatible:

Argument of type '(param: TSESTree.Identifier) => string' is not assignable to parameter of type '(value: Parameter, index: number, array: Parameter[]) => string'.

You're attempting to assign a function with signature (param: TSESTree.Identifier) => string to a location that accepts (param: TSESTree.Parameter) => string.

This is an error, TSESTree.Parameter contains more types than just Identifier.

@anikethsaha
Copy link
Contributor Author

I did try with TSESTree.Parameter in 1st commit of this PR. f274634#diff-7fcf937f6ab4b17e2b9aa4126d5b950fR63

but that one failed as well.

@bradzacher
Copy link
Member

Why bother adding an explicit type to the param? Just let TS infer the type from the usage.

node.params.map(param => { ... });

@anikethsaha
Copy link
Contributor Author

image

implicit is Parameter I guess

  const names = node.params.map(param => param.name);

@anikethsaha anikethsaha marked this pull request as ready for review April 23, 2020 15:28
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.

mostly LGTM, a few comments.
Thanks for this!

packages/eslint-plugin/src/rules/no-invalid-this.ts Outdated Show resolved Hide resolved
packages/eslint-plugin/docs/rules/no-invalid-this.md Outdated Show resolved Hide resolved
packages/eslint-plugin/src/rules/no-invalid-this.ts Outdated Show resolved Hide resolved
@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Apr 26, 2020
@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Apr 27, 2020
@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Apr 28, 2020
@bradzacher
Copy link
Member

FYI - the CI is failing

@anikethsaha
Copy link
Contributor Author

FYI - the CI is failing

on it.

@anikethsaha
Copy link
Contributor Author

I am not sure whats wrong but all invalid test cases are failing in ruleTester

image

also, still blocked with this

image

@codecov
Copy link

codecov bot commented May 1, 2020

Codecov Report

Merging #1823 into master will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1823      +/-   ##
==========================================
+ Coverage   93.88%   93.90%   +0.01%     
==========================================
  Files         170      171       +1     
  Lines        7737     7758      +21     
  Branches     2227     2230       +3     
==========================================
+ Hits         7264     7285      +21     
  Misses        218      218              
  Partials      255      255              
Flag Coverage Δ
#unittest 93.90% <100.00%> (+0.01%) ⬆️
Impacted Files Coverage Δ
...ackages/eslint-plugin/src/rules/no-invalid-this.ts 100.00% <100.00%> (ø)

@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label May 1, 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 this

@bajtos
Copy link

bajtos commented May 15, 2020

This is awesome, thank you @anikethsaha for implementing the new rule ❤️

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 15, 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-invalid-this] allow this when it's explicitly declared in function arguments
3 participants