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 invalid autofix with destructuring assignment in no-for-loops rule #476
Fix invalid autofix with destructuring assignment in no-for-loops rule #476
Conversation
Example (original): ```js for (let i = 0; i < arr.length; i++) { const { a, b } = arr[i]; console.log(a, b); } ``` Autofix (before this fix): ```js for (const element of arr) { console.log(a, b); } ``` Autofix (after this fix): ```js for (const element of arr) { const { a, b } = element; console.log(a, b); } ``` When `arr[i]` is used in a destructuring assignment, the entire assignment should not be removed (previous behavior), only `arr[i]` should be replaced with `element` (new behavior).
LGTM, but can we fix this to
if maybe we can keep |
@fisker that's a good idea. However, since that is a much more involved fix, it's probably worth considering as a follow-up improvement. |
sending a PR to your fork |
@fisker your improvement looks great, thank you! But I'm not sure how to merge it in my fork due to the conflicts. Perhaps you could just add the commit to this PR? |
…g-fix' into no-for-loops-destructuring-fix # Conflicts: # rules/no-for-loop.js # test/no-for-loop.js
This comment has been minimized.
This comment has been minimized.
Good job, thank you! @bmish |
Example (original):
Autofix (before this fix):
Autofix (after this fix):
When
arr[i]
is used in a destructuring assignment, the entire assignment should not be removed (previous behavior), onlyarr[i]
should be replaced withelement
(new behavior).