8000 chore: enable unicorn/no-array-reduce by abrahamguo · Pull Request #9640 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

chore: enable unicorn/no-array-reduce #9640

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

Merged
merged 50 commits into from
Sep 2, 2024

Conversation

abrahamguo
Copy link
Contributor
@abrahamguo abrahamguo commented Jul 25, 2024

PR Checklist

Overview

Enable unicorn/no-array-reduce (docs).
Note that no-array-reduce does allow "simple operations", which it defines as a body that is only a BinaryExpression, so those were left unchanged.
I strongly feel that every place that was refactored has better readability than it did before.
In most places, there was a more appropriate method to use, such as Array.flatMap or Object.fromEntries.
In other places, it was unnecessarily confusing to return the accumulator every iteration when the accumulator never changes, and so it was better to use a const variable in conjunction with a for..of loop.

I recommend selecting Hide whitespace when looking at this diff 😄

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @abrahamguo!

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.

Copy link
netlify bot commented Jul 25, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 6b79534
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/66cdc09d4628d400085d0d6f
😎 Deploy Preview https://deploy-preview-9640--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 98 (🔴 down 1 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 90 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

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

Copy link
nx-cloud bot commented Jul 25, 2024

☁️ Nx Cloud Report

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

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Aug 8, 2024
@abrahamguo
Copy link
Contributor Author
abrahamguo commented Aug 8, 2024

Any refactors that look like

const dataStructure;
for (const ... of ...) {
  ...append to dataStructure...
}

have been removed, and either restored to use Array.reduce, or some other more appropriate method 👍

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.

This form I'm happy with 🙂 thanks!

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Aug 14, 2024
Josh-Cena
Josh-Cena previously approved these changes Aug 14, 2024
Copy link
Member
@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me :)

(['public', 'protected', 'private', '#private'] as const).forEach(
accessibility => {
if (
const allMemberTypes = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow this is a giant one. Definitely an improvement.

Comment on lines +75 to 77
const MAX_RULE_NAME_LENGTH = Math.max(
...Object.keys(eslintPlugin.rules).map(name => name.length),
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the original intention is that argument count must be <65536. Not sure it can be hit here 😅

@JoshuaKGoldberg JoshuaKGoldberg requested review from kirkwaiblinger and removed request for kirkwaiblinger August 15, 2024 02:05
kirkwaiblinger
kirkwaiblinger previously approved these changes Aug 16, 2024
Copy link
Member
@kirkwaiblinger kirkwaiblinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things that I'd personally change, but nothing that's a blocker if we want to merge.

Thanks for trudging through all these super confusing reduce constructions!

],
},
// AssignmentExpression
...(skipAssignmentExpression
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still think these types of cases should be explicit like below rather than using lots of ... operator to conditionally push within an expression.

const mappedTests = [ 
  // ... lots of cases
]
if (skipAssignmentExpression !== true) {
    mappedTests.push(/* etc */);
}

(also note that skipAssignmentExpression !== true isn't equivalent to if (!skipAssignmentExpression) here - let's preserve that).

@JoshuaKGoldberg JoshuaKGoldberg removed the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Aug 22, 2024
@kirkwaiblinger kirkwaiblinger added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Aug 30, 2024
@JoshuaKGoldberg JoshuaKGoldberg merged commit 4bc801e into typescript-eslint:main Sep 2, 2024
61 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0