Skip to content

Commit c90016b

Browse files
authored
Add rule to avoid prefixing Swift Testing test case methods with "test" (#299)
1 parent f297b9c commit c90016b

3 files changed

Lines changed: 37 additions & 5 deletions

File tree

‎Package.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ let package = Package(
4242

4343
.binaryTarget(
4444
name: "swiftformat",
45-
url: "https://github.com/calda/SwiftFormat/releases/download/0.56-beta-6/SwiftFormat.artifactbundle.zip",
46-
checksum: "5248a8e1d3ff8165ed1f4bbfbc9b763a77f22e656f067d8e01b61b3b8d6ca5ec"),
45+
url: "https://github.com/calda/SwiftFormat/releases/download/0.56-beta-8/SwiftFormat.artifactbundle.zip",
46+
checksum: "32e21fd84bffcc9154c7d80ff2173fb1d6a3dbd740e4bf6a151b6e33e0cced3d"),
4747

4848
.binaryTarget(
4949
name: "SwiftLintBinary",

‎README.md‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3781,7 +3781,7 @@ _You can enable the following settings in Xcode by running [this script](resourc
37813781

37823782
</details>
37833783

3784-
* <a id='void-type'></a>(<a href='#void-type'>link</a>) **Avoid using `()` as a type**. Prefer `Void`.
3784+
* <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)
37853785

37863786
<details>
37873787

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

3797-
* <a id='void-instance'></a>(<a href='#void-instance'>link</a>) **Avoid using `Void()` as an instance of `Void`**. Prefer `()`.
3797+
* <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)
37983798

37993799
<details>
38003800

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

3812-
* <a id='count-where'></a>(<a href='#count-where'>link</a>) **Prefer using `count(where: { … })` over `filter { … }.count`**.
3812+
* <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)
38133813

38143814
<details>
38153815

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

3827+
* <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)
3828+
3829+
<details>
3830+
3831+
### Why?
3832+
3833+
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.
3834+
3835+
```swift
3836+
import Testing
3837+
3838+
/// WRONG
3839+
struct SpaceshipTests {
3840+
@Test
3841+
func testWarpDriveEnablesFTLTravel() { ... }
3842+
3843+
@Test
3844+
func testArtificialGravityMatchesEarthGravity() { ... }
3845+
}
3846+
3847+
/// RIGHT
3848+
struct SpaceshipTests {
3849+
@Test
3850+
func warpDriveEnablesFTLTravel() { ... }
3851+
3852+
@Test
3853+
func artificialGravityMatchesEarthGravity() { ... }
3854+
}
3855+
```
3856+
</details>
3857+
38273858
**[⬆ back to top](#table-of-contents)**
38283859

38293860
## File Organization

‎Sources/AirbnbSwiftFormatTool/airbnb.swiftformat‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,4 @@
122122
--rules unusedPrivateDeclarations
123123
--rules emptyExtensions
124124
--rules preferCountWhere
125+
--rules swiftTestingTestCaseNames

0 commit comments

Comments
 (0)