Skip to content

Commit

Permalink
Add rule to avoid prefixing Swift Testing test case methods with "tes…
Browse files Browse the repository at this point in the history
…t" (#299)
  • Loading branch information
calda authored Mar 7, 2025
1 parent f297b9c commit c90016b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
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.56-beta-6/SwiftFormat.artifactbundle.zip",
checksum: "5248a8e1d3ff8165ed1f4bbfbc9b763a77f22e656f067d8e01b61b3b8d6ca5ec"),
url: "https://github.com/calda/SwiftFormat/releases/download/0.56-beta-8/SwiftFormat.artifactbundle.zip",
checksum: "32e21fd84bffcc9154c7d80ff2173fb1d6a3dbd740e4bf6a151b6e33e0cced3d"),

.binaryTarget(
name: "SwiftLintBinary",
Expand Down
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3781,7 +3781,7 @@ _You can enable the following settings in Xcode by running [this script](resourc

</details>

* <a id='void-type'></a>(<a href='#void-type'>link</a>) **Avoid using `()` as a type**. Prefer `Void`.
* <a id='void-type'></a>(<a href='#void-type'>link</a>) **Avoid using `()` as a type**. Prefer `Void`. [![SwiftFormat: void](https://img.shields.io/badge/SwiftFormat-void-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#void)

<details>

Expand All @@ -3794,7 +3794,7 @@ _You can enable the following settings in Xcode by running [this script](resourc
```
</details>

* <a id='void-instance'></a>(<a href='#void-instance'>link</a>) **Avoid using `Void()` as an instance of `Void`**. Prefer `()`.
* <a id='void-instance'></a>(<a href='#void-instance'>link</a>) **Avoid using `Void()` as an instance of `Void`**. Prefer `()`. [![SwiftFormat: void](https://img.shields.io/badge/SwiftFormat-void-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#void)

<details>

Expand All @@ -3809,7 +3809,7 @@ _You can enable the following settings in Xcode by running [this script](resourc
```
</details>

* <a id='count-where'></a>(<a href='#count-where'>link</a>) **Prefer using `count(where: { })` over `filter { }.count`**.
* <a id='count-where'></a>(<a href='#count-where'>link</a>) **Prefer using `count(where: { })` over `filter { }.count`**. [![SwiftFormat: preferCountWhere](https://img.shields.io/badge/SwiftFormat-preferCountWhere-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#preferCountWhere)

<details>

Expand All @@ -3824,6 +3824,37 @@ _You can enable the following settings in Xcode by running [this script](resourc
```
</details>

* <a id='swift-testing-test-case-names'></a>(<a href='#swift-testing-test-case-names'>link</a>) **In Swift Testing, don't prefix test case methods with "`test`".** [![SwiftFormat: swiftTestingTestCaseNames](https://img.shields.io/badge/SwiftFormat-swiftTestingTestCaseNames-7B0051.svg)](https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#swiftTestingTestCaseNames)

<details>

### Why?

Prefixing test case methods with "`test`" was necessary with XCTest, but is not necessary in Swift Testing. [Idiomatic usage](https://developer.apple.com/documentation/testing/migratingfromxctest#Convert-test-methods) of Swift Testing excludes the "`test`" prefix.

```swift
import Testing

/// WRONG
struct SpaceshipTests {
@Test
func testWarpDriveEnablesFTLTravel() { ... }

@Test
func testArtificialGravityMatchesEarthGravity() { ... }
}

/// RIGHT
struct SpaceshipTests {
@Test
func warpDriveEnablesFTLTravel() { ... }

@Test
func artificialGravityMatchesEarthGravity() { ... }
}
```
</details>

**[ back to top](#table-of-contents)**

## File Organization
Expand Down
1 change: 1 addition & 0 deletions Sources/AirbnbSwiftFormatTool/airbnb.swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,4 @@
--rules unusedPrivateDeclarations
--rules emptyExtensions
--rules preferCountWhere
--rules swiftTestingTestCaseNames

0 comments on commit c90016b

Please sign in to comment.