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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update colon spacing rule to apply to dictionary literals #285

Merged
merged 2 commits into from
Aug 21, 2024

Conversation

calda
Copy link
Member

@calda calda commented Aug 13, 2024

Summary

This PR proposes updating the existing colon-spacing rule to also apply to dictionary literals. Previously, it applied to all usage of commas except dictionary literals.

// WRONG
let moons: [Planet : Moon] = [
  mercury : [], 
  venus : [], 
  earth : [theMoon], 
  mars : [phobos,deimos],
]

// RIGHT
let moons: [Planet: Moon] = [
  mercury: [], 
  venus: [], 
  earth: [theMoon], 
  mars: [phobos,deimos],
]

Reasoning

It is much more common to omit the space before colon in dictionary literals. This also makes the rule more consistent and general.

This will also let us replace the SwiftLint colon rule with the SwiftFormat spaceAroundOperators rule. The SwiftLint rule has a apply_to_dictionaries: false option to exclude dictionary literals, but the SwiftFormat rule currently does not.


<details>

```swift
// WRONG
var something : Double = 0
let planet:CelestialObject = sun.planets[0]
Copy link
Member Author

Choose a reason for hiding this comment

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

Improved the existing examples to follow the theme used elsewhere in the style guide

Copy link
Member Author

@calda calda left a comment

Choose a reason for hiding this comment

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

Strong support for this change internally 👍🏻

@calda calda merged commit ae60ffe into master Aug 21, 2024
5 checks passed
@calda calda deleted the cal--colon-spacing branch August 21, 2024 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant