-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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): [typedef] allow array/object destructuring in for/of #1570
Conversation
Thanks for the PR, @a-tarasyuk! 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. |
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.
Since you requested review, this looks good to me! But I am not a maintainer in this repository and thus my happy opinion means relatively little. 😇
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.
idea LGTM.
unless I'm mistaken, this will break on nested destructuring.
tbh I think the rule will just break on that anyways, so it might be good to add a simple validation like "if parent is destructuring then ignore"
@@ -38,6 +38,14 @@ ruleTester.run('typedef', rule, { | |||
}, | |||
], | |||
}, | |||
{ | |||
code: `for (const [key, val] of new Map([['key', 1]])) {}`, |
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.
could you please add a test for nested destructuring
for (const [[key]] of [[['key']]]) {}
for (const [[{ key }]] of [[[{ key: 'value' }]]]) {}
for (const {p1: {p2: { p3 }}} of [{p1: {p2: {p3: 'value'}}}]) {}
for (const {p1: {p2: { p3: [key] }}} of [{p1: {p2: {p3: ['value']}}}]) {}
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.
Thinking about it - won't the rule break on these cases anyways?
const [[[{ key }]]]: [[[{ key: string }]]] = [[[{ key: 'value' }]]]
// ^^^^^^^ report ❌
// ^^^^^^^^^ report ❌
// ^^^^^^^^^^^ report ❌
// ^^^^^^^^^^^^^ no report ✅
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.
@bradzacher Added additional tests. About the last case, I think the current implementation doesn't handle that, and the proposed changes will not handle/break that behavior.
Codecov Report
@@ Coverage Diff @@
## master #1570 +/- ##
==========================================
- Coverage 95.56% 95.55% -0.01%
==========================================
Files 142 142
Lines 6537 6594 +57
Branches 1862 1886 +24
==========================================
+ Hits 6247 6301 +54
- Misses 105 106 +1
- Partials 185 187 +2
|
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.
LGTM - thanks for this
Fixes #1564