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(eslint-plugin): [member-ordering] report alphabetical sorting for all groups instead of just the first failing group #8263
Conversation
Thanks for the PR, @arka1002! 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 failed.
|
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.
Seems reasonable on a read-through, but I'm having a hard time understanding the added code. Which means future folks with less context would probably have a harder time. What do you think about the clarification + cleanup comments?
Btw, emphasizing from a comment: this rule is inherently pretty tricky and complex. So I think any changes will be that way too. Nice job getting it to work! 👏
Btw, no need to put the |
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.
return grouped | ||
.map(groupMember => | ||
checkAlphaSort(groupMember, order as AlphabeticalOrder), | ||
) | ||
.some(result => !result); |
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.
[Performance] Why waste time run lot iteration when few do trick?
return grouped | |
.map(groupMember => | |
checkAlphaSort(groupMember, order as AlphabeticalOrder), | |
) | |
.some(result => !result); | |
return grouped.some( | |
groupMember => | |
!checkAlphaSort(groupMember, order as AlphabeticalOrder), | |
); |
More helpfully: .map
does a loop over everything in grouped
, then .some
bails out as soon as a result is found. So we can combine the two into one to bail out early if possible.
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.
Yeah, using .some
is a part of the problem of the issue. Currently before this pr, the rule only run alphabetical sort on a particular group, if that group was sorted, then only it checked the next group(which is the early bailing out due to .some
), else the next group remains unchecked.
An example test - https://github.com/typescript-eslint/typescript-eslint/pull/8263/files#diff-28e99227546efaad4ed38d47dcd8746943b60b09b2095a68ec4209856d709e1fR128-R129
But yeah, I removed .some
, I think it isn't necessary.
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
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.
🙌 Whoop! This looks wonderful - thanks for working with me on it.
Since I've looked at it so much, I'll leave it open as 1 approval
in the hopes another team member can get to it.
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.
The changes looks great! 🚀
c06ce1a
into
typescript-eslint:main
Just updated and tested. This is a huge improvement to have all the errors at once. Thank you again for the fix and reviews! 🙂 |
PR Checklist
Overview