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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -593,37 +593,47 @@ _You can enable the following settings in Xcode by running [this script](resourc

</details>

* <a id='colon-spacing'></a>(<a href='#colon-spacing'>link</a>) **Place the colon immediately after an identifier, followed by a space.** [![SwiftFormat: spaceAroundOperators](https://img.shields.io/badge/SwiftFormat-spaceAroundOperators-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#spacearoundoperators)
* <a id='colon-spacing'></a>(<a href='#colon-spacing'>link</a>) **Colons should always be followed by a space, but not preceded by a space**. [![SwiftFormat: spaceAroundOperators](https://img.shields.io/badge/SwiftFormat-spaceAroundOperators-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#spacearoundoperators)

<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

let planet : CelestialObject = sun.planets[0]

// RIGHT
var something: Double = 0
let planet: CelestialObject = sun.planets[0]
```

```swift
// WRONG
class MyClass : SuperClass {
class Planet : CelestialObject {
// ...
}

// RIGHT
class MyClass: SuperClass {
class Planet: CelestialObject {
// ...
}
```

```swift
// WRONG
var dict = [KeyType:ValueType]()
var dict = [KeyType : ValueType]()
let moons: [Planet : Moon] = [
mercury : [],
venus : [],
earth : [theMoon],
mars : [phobos,deimos],
]

// RIGHT
var dict = [KeyType: ValueType]()
let moons: [Planet: Moon] = [
mercury: [],
venus: [],
earth: [theMoon],
mars: [phobos,deimos],
]
```

</details>
Expand Down
Loading