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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule that protocol composition type aliases should be sorted alphabetically #227

Merged
merged 3 commits into from
May 15, 2023

Conversation

calda
Copy link
Member

@calda calda commented May 8, 2023

Summary

This PR proposes a new rule that protocol composition type aliases should be sorted alphabetically.

Autocorrect is implemented in the SwiftFormat sortTypealiases rule, added in nicklockwood/SwiftFormat#1445.

// WRONG (not sorted)
public typealias Dependencies
  = UniverseBuilderProviding
  & LawsOfPhysicsProviding
  & UniverseSimulatorServiceProviding
  & PlanetBuilderProviding
  & CivilizationServiceProviding

// RIGHT
public typealias Dependencies
  = CivilizationServiceProviding
  & LawsOfPhysicsProviding
  & PlanetBuilderProviding
  & UniverseBuilderProviding
  & UniverseSimulatorServiceProviding

Reasoning

Type aliases are an unordered list with no natural ordering. Sorting alphabetically keeps these lists more organized, which is especially valuable for long protocol compositions.

Please react with 馃憤/馃憥 if you agree or disagree with this proposal.

Copy link
Collaborator

@erichoracek erichoracek left a comment

Choose a reason for hiding this comment

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

Good stuff!

README.md Outdated Show resolved Hide resolved
Co-authored-by: Eric Horacek <eric.horacek@airbnb.com>
@calda calda merged commit 67702b2 into master May 15, 2023
3 checks passed
@calda calda deleted the cal--sortTypealiases branch May 15, 2023 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants