New rule: sorted_collection_members - #6921
Draft
ZevEisenberg wants to merge 7 commits into
Draft
ZevEisenberg wants to merge 7 commits into
ZevEisenberg wants to merge 7 commits into
Conversation
ZevEisenberg
force-pushed
the
sorted-collection-members-rule
branch
from
September 24, 2026 21:38
0f0fc91 to
285c2ca
Compare
… members of a collection literal remain sorted.
ZevEisenberg
force-pushed
the
sorted-collection-members-rule
branch
from
September 24, 2026 21:45
285c2ca to
0a412a4
Compare
Contributor
Author
|
Here's one possible weakness with this approach: it appears that, if a rule is disabled or not-opted-in globally, it cannot be enabled with |
Contributor
Author
|
If that's too drastic a change for this repo, I was able to get something similar working in SwiftFormat, so I may just go with that. I'll leave this PR open until I hear from a maintainer, though. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've got some more work I want to do in order to polish this up, but I wanted to get some early feedback on whether a rule like this would be accepted.
A couple of questions:
Motivating use case: we have some arrays in our code, particularly in Package.swift, that look like this:
Instead of imploring future developers to keep a collection literal's members alphabetized, I'd like to propose an opt-in rule that can keep us honest: