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

feat(eslint-plugin): add new extended rule prefer-destructuring #7117

Merged
merged 41 commits into from Oct 11, 2023

Conversation

seiyab
Copy link
Contributor

@seiyab seiyab commented Jun 18, 2023

PR Checklist

Overview

Add a new base rule extension @typescript-eslint/prefer-destructuring to resolve following issues.

#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 value false 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.

@typescript-eslint
Copy link
Contributor

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.

@netlify
Copy link

netlify bot commented Jun 18, 2023

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 77b6704
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/64da426db8f1bd0008bf99dc
😎 Deploy Preview https://deploy-preview-7117--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@seiyab seiyab changed the title Prefer destructuring Add prefer destructuring extension Jun 18, 2023
@nx-cloud
Copy link

nx-cloud bot commented Jun 18, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 77b6704. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 37 targets

Sent with 💌 from NxCloud.

@seiyab seiyab changed the title Add prefer destructuring extension feat(eslint-plugin): add new extended rule prefer-destructuring Jun 20, 2023
@seiyab seiyab marked this pull request as ready for review June 20, 2023 13:35
@codecov
Copy link

codecov bot commented Jun 20, 2023

Codecov Report

Merging #7117 (77b6704) into main (479f9f6) will increase coverage by 0.06%.
The diff coverage is 100.00%.

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              
Flag Coverage Δ
unittest 85.31% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
...ckages/eslint-plugin/src/util/getESLintCoreRule.ts 75.00% <ø> (ø)
...es/eslint-plugin/src/rules/prefer-destructuring.ts 100.00% <100.00%> (ø)

@JoshuaKGoldberg
Copy link
Member

I also took the liberty of merging in from main, since v6 was merged & changed a few internals after this PR was sent. Cheers!

@seiyab
Copy link
Contributor Author

seiyab commented Aug 11, 2023

I have responded to your requests🚀

@JoshuaKGoldberg JoshuaKGoldberg removed the awaiting response Issues waiting for a reply from the OP or another party label Aug 12, 2023
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.

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.

packages/eslint-plugin/src/rules/prefer-destructuring.ts Outdated Show resolved Hide resolved
packages/eslint-plugin/src/rules/prefer-destructuring.ts Outdated Show resolved Hide resolved
@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready label Aug 12, 2023
- naming of options
- using nullish coalescing assignment
@seiyab
Copy link
Contributor Author

seiyab commented Aug 14, 2023

Thank you for your review.
I have responded to #7117 (comment) and #7117 (comment) but I'm wondering why create(context, [enabledTypes, options = {}]) { get uncovered renaming a variable.

@seiyab
Copy link
Contributor Author

seiyab commented Oct 5, 2023

@JoshuaKGoldberg
Could you tell me the current status?

@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Oct 11, 2023

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!

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.

Large ship with caption 'it's shipping time'

@JoshuaKGoldberg JoshuaKGoldberg merged commit 3c6379b into typescript-eslint:main Oct 11, 2023
50 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready enhancement: new base rule extension New base rule extension required to handle a TS specific case
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants