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): [unbound-method] report on destructuring in function parameters #8952
base: main
Are you sure you want to change the base?
Conversation
Thanks for the PR, @auvred! 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. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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 really like these changes! The algorithm change makes sense to me, the code is easy to follow, and the new code for type inspection is very thorough.
Added a few questions and some test cases to flesh out edge cases.
node.parent.type === AST_NODE_TYPES.AssignmentExpression | ||
) { | ||
initNode = node.parent.right; | ||
} |
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.
should there be some kind of assertion here to ensure that every way that ObjectPattern could occur is handled (especially in light of the bug that this PR fixes)? Relates to #6225
nativelyBoundMembers.has(getMemberFullName(node)) && | ||
isNotImported(objectSymbol, currentSourceFile) | ||
notImported && | ||
nativelyBoundMembers.has(`${object.name}.${property.name}`) |
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.
const { log } = console;
In our current configuration, the console.log
declarations are under @types/node
. So if we remove this check, the rule will report on this case. Not sure what's the best solution there..
PR Checklist
Overview
Old approach: query for
VariableDeclarator, AssignmentExpression
and check if they haveObjectPattern
New approach: query for
ObjectPattern
, check ifVariableDeclarator, AssignmentExpression, AssignmentPattern
its parentWe're iterating over
ObjectPattern
's properties:ObjectPatterns
's parent has init node, check if it's safe to destructure this init node:ObjectPatterns
's parent isAssignmentPattern
:ObjectPattern
has a type annotation, then check if it's safe to destructure this type