-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): add new extended rule prefer-destructuring
#7117
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): add new extended rule prefer-destructuring
#7117
Conversation
autofix is still wrong.
Thanks for the PR, @seiyab! 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. |
prefer-destructuring
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #7117 +/- ##
==========================================
+ Coverage 85.25% 85.31% +0.06%
==========================================
Files 386 387 +1
Lines 13358 13417 +59
Branches 3943 3962 +19
==========================================
+ Hits 11388 11447 +59
Misses 1593 1593
Partials 377 377
Flags with carried forward coverage won't be shown. Click here to find out more.
|
I also took the liberty of merging in from |
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
I have responded to your requests🚀 |
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 both sending & updating it (with so many tests)! 🔥
I'll defer to an additional review from @typescript-eslint/triage-team because this is the first instance I can find of calling baseRule.create
in two different potential ways.
- naming of options - using nullish coalescing assignment
Thank you for your review. |
@JoshuaKGoldberg |
Heh, I was hoping for an additional review, but it seems that everyone is slammed right now. Let's merge as-is 😄. Thanks for the ping! |
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.
PR Checklist
prefer-destructuring
#1931Overview
Add a new base rule extension
@typescript-eslint/prefer-destructuring
to resolve following issues.prefer-destructuring
#1931#723 requests two things: 1. keep type annotation, 2. add an option to allow non-destructuring assignment for type annotated ones.
For the first one, I just disable auto fixer for declaration with type annotation, rather than providing correct auto fix. It's just because difficulty and maitainability.
For the second one, I add
enforceForDeclarationWithTypeAnnotation
option. I set default valuefalse
because I agree with "annotations on destructured variables aren't very pretty" in the issue.#1931 requests type-aware version and I have implemented it for numeric index access for non-iterable object, that is the only case reported in the issue (excluding comments that are duplication of #723).
There is a notable thing for it. I treated numeric index access for non-iterable object as renamed one. So it is affected by
enforceForRenamedProperties
option.