Skip to content
Merged
Show file tree
Hide file tree
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
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3275,6 +3275,50 @@ _You can enable the following settings in Xcode by running [this script](resourc

</details>

* <a id='simplify-generic-constraints'></a>(<a href='#simplify-generic-constraints'>link</a>) **Prefer defining simple generic constraints in the generic parameter list rather than in the where clause.** [![SwiftFormat: simplifyGenericConstraints](https://img.shields.io/badge/SwiftFormat-simplifyGenericConstraints-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#simplifyGenericConstraints)

<details>

#### Why?
Inline generic constraints (`<T: Protocol>`) are more concise and idiomatic than where clauses (`<T> where T: Protocol`) for simple protocol conformances. Using inline constraints for simple cases makes generic declarations easier to read at a glance. Where clauses are reserved for complex constraints that cannot be expressed inline, like associated type constraints (`T.Element == Star`) or concrete type equality.
Copy link
Member

Choose a reason for hiding this comment

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

👌🏻


```swift
// WRONG
struct SpaceshipDashboard<Left, Right>: View
where Left: View, Right: View
{
...
}

extension Spaceship {
func fly<Destination>(
to: Destination,
didArrive: (Destination) -> Void
) where Destination: PlanetaryBody {
...
}
}

// RIGHT
struct SpaceshipDashboard<Left: View, Right: View>: View {
...
}

extension Spaceship {
func fly<Destination: PlanetaryBody>(
to: Destination,
didArrive: (Destination) -> Void
) {
...
}
}

// ALSO RIGHT: Complex constraints remain in where clause
struct Galaxy<T: Collection> where T.Element == Star {}
```

</details>

* <a id='static-type-methods-by-default'></a>(<a href='#static-type-methods-by-default'>link</a>) **Default type methods to `static`.**

<details>
Expand Down
1 change: 1 addition & 0 deletions Sources/AirbnbSwiftFormatTool/airbnb.swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,4 @@
--rules redundantBreak
--rules redundantTypedThrows
--rules preferFinalClasses
--rules simplifyGenericConstraints