-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
chore: enable unicorn/no-array-reduce #9640
Conversation
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. |
All reactions
Sorry, something went wrong.
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
All reactions
Sorry, something went wrong.
☁️ Nx Cloud ReportCI 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 targetsSent with 💌 from NxCloud. |
All reactions
Sorry, something went wrong.
Any refactors that look like
have been removed, and either restored to use |
All reactions
Sorry, something went wrong.
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.
This form I'm happy with 🙂 thanks!
Sorry, something went wrong.
All reactions
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.
Looks great to me :)
Sorry, something went wrong.
All reactions
(['public', 'protected', 'private', '#private'] as const).forEach( | ||
accessibility => { | ||
if ( | ||
const allMemberTypes = [ |
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.
Wow this is a giant one. Definitely an improvement.
Sorry, something went wrong.
All reactions
-
👍 1 reaction -
❤️ 1 reaction
const MAX_RULE_NAME_LENGTH = Math.max( | ||
...Object.keys(eslintPlugin.rules).map(name => name.length), | ||
); |
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.
I believe the original intention is that argument count must be <65536. Not sure it can be hit here 😅
Sorry, something went wrong.
All reactions
-
😄 2 reactions
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.
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!
Sorry, something went wrong.
All reactions
], | ||
}, | ||
// AssignmentExpression | ||
...(skipAssignmentExpression |
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.
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).
Sorry, something went wrong.
All reactions
1216fee
fisker
kirkwaiblinger
JoshuaKGoldberg
Josh-Cena
Successfully merging this pull request may close these issues.
PR Checklist
eslint-plugin-unicorn
rules internally #9623Overview
Enable
unicorn/no-array-reduce
(docs).Note that
no-array-reduce
does allow "simple operations", which it defines as a body that is only aBinaryExpression
, 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
orObject.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 afor..of
loop.I recommend selecting
Hide whitespace
when looking at this diff 😄