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

Add rule to place doc comments before any attributes #281

Merged
merged 4 commits into from
Jul 27, 2024
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
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ let package = Package(

.binaryTarget(
name: "swiftformat",
url: "https://github.com/calda/SwiftFormat/releases/download/0.55-beta-4/SwiftFormat.artifactbundle.zip",
checksum: "ebdb5cefe050099d2cbc0e00a0d45abc3f45e763c7cd6b849a1113026b2b2a3b"),
url: "https://github.com/calda/SwiftFormat/releases/download/0.55-beta-6/SwiftFormat.artifactbundle.zip",
checksum: "c4faeb1068eece2b644192afc1a35a82a81935794034d2efaa3f44ddd8a4b8d4"),

.binaryTarget(
name: "SwiftLintBinary",
Expand Down
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -843,9 +843,9 @@ _You can enable the following settings in Xcode by running [this script](resourc
var oldestMoons: [Moon]

}
```swift

```

```swift
// WRONG. These long, complex attributes should be written on the previous line.
struct RocketFactory {

Expand Down Expand Up @@ -1870,6 +1870,26 @@ _You can enable the following settings in Xcode by running [this script](resourc

</details>

* <a id='doc-comments-before-attributes'></a>(<a href='#doc-comments-before-attributes'>link</a>) **Place doc comments for a declaration before any attributes.** [![SwiftFormat: docCommentsBeforeAttributes](https://img.shields.io/badge/SwiftFormat-docCommentsBeforeAttributes-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md#docCommentsBeforeAttributes)

<details>

```swift
// WRONG

@MainActor
/// A spacecraft with everything you need to explore the universe.
struct Spaceship { … }

// RIGHT

/// A spacecraft with everything you need to explore the universe.
@MainActor
Comment on lines +1881 to +1887
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this apply to property wrappers and builtin attributes like @objc or @dynamicMemberLookup as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! It applies to everything that starts with an @.

(In the Swift grammar everything that starts with an @ is an attribute -- you can confirm this by searching for @ in the grammar documentation and seeing that it only appears once, as the start of an attribute.)

struct Spaceship { … }
```

</details>

* <a id='whitespace-around-comment-delimiters'></a>(<a href='#whitespace-around-comment-delimiters'>link</a>) Include spaces or newlines before and after comment delimiters (`//`, `///`, `/*`, and `*/`) [![SwiftFormat: spaceAroundComments](https://img.shields.io/badge/SwiftFormat-spaceAroundComments-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md#spaceAroundComments) [![SwiftFormat: spaceInsideComments](https://img.shields.io/badge/SwiftFormat-spaceInsideComments-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md#spaceInsideComments)

<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 @@ -89,6 +89,7 @@
--rules enumNamespaces
--rules blockComments
--rules docComments
--rules docCommentsBeforeAttributes
--rules spaceAroundComments
--rules spaceInsideComments
--rules blankLinesAtStartOfScope
Expand Down
Loading