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): [typedef] allow array/object destructuring in for/of #1570

Merged
merged 3 commits into from Feb 19, 2020

Conversation

a-tarasyuk
Copy link
Contributor

Fixes #1564

@typescript-eslint
Copy link
Contributor

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.

@bradzacher bradzacher added the bug Something isn't working label Feb 5, 2020
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a 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. 😇

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.

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]])) {}`,
Copy link
Member

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']}}}]) {}

Copy link
Member

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 ✅ 

Copy link
Contributor Author

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
Copy link

codecov bot commented Feb 12, 2020

Codecov Report

Merging #1570 into master will decrease coverage by <.01%.
The diff coverage is 96.77%.

@@            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
Impacted Files Coverage Δ
packages/eslint-plugin/src/rules/ban-types.ts 100% <100%> (ø) ⬆️
...int-plugin/src/rules/strict-boolean-expressions.ts 96.77% <96.42%> (-3.23%) ⬇️

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'typedef/arrayDestructuring': impossible to follow this rule in for/of statement
3 participants