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): [unbound-method] Support Array methods with 'this' argument #797
feat(eslint-plugin): [unbound-method] Support Array methods with 'this' argument #797
Conversation
Thanks for the PR, @jacekjagiello! 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 |
if ( | ||
parent.callee.type === AST_NODE_TYPES.MemberExpression && | ||
parent.callee.property.type === AST_NODE_TYPES.Identifier | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I really would like to do, is to check if callee for ex. nodes
is an Array
. Is this possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should be able to get the type of the node, and ensure its type is an array.
I can't remember the flags exactly, so you might want to spend some time with the debugger in vscode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've spent some time trying to play with the debugger to find any flags that might indicate Array
type, but with no success for now. If you think we can't leave it like this, I'll spend more time and maybe find the better way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Digging back into this, sorry a lot going on. Finally taken time to tackle the PR queue.
Feel free to add this file into your PR, and use that API.
https://github.com/typescript-eslint/typescript-eslint/blob/naming-conventions/packages/eslint-plugin/typings/typescript.d.ts
The API is "internal", but it's stable - they just haven't gotten around to exposing their type relationship API yet (there's a whole discussion around why they haven't yet...)
You can then pass the typechecker into this function and call checker.isArrayType(type)
(you'll also have to pass the type map in).
Also just as an FYI - this site is amazing for playing with TS's type API: https://ts-ast-viewer.com/
You can open the chrome dev tools, and interrogate the selected type via the global variables it maintains: type
, program
and typeChecker
.
Also as an example, here is another PR doing a similar thing in looking for array functions: #1206
Codecov Report
@@ Coverage Diff @@
## master #797 +/- ##
==========================================
+ Coverage 94.13% 94.17% +0.03%
==========================================
Files 115 112 -3
Lines 5016 4841 -175
Branches 1403 1341 -62
==========================================
- Hits 4722 4559 -163
+ Misses 166 160 -6
+ Partials 128 122 -6
|
if ( | ||
parent.callee.type === AST_NODE_TYPES.MemberExpression && | ||
parent.callee.property.type === AST_NODE_TYPES.Identifier | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should be able to get the type of the node, and ensure its type is an array.
I can't remember the flags exactly, so you might want to spend some time with the debugger in vscode.
…jagiello/typescript-eslint into bugfix/743-false-positive-thisArgs
#743
Hey, this is my first PR. I don't have much experience with AST, so it feels for me like walking in the fog 😄 I assume there is a better solution for this bug. Any help appreciated. I'll leave some questions in PR