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 avoid prefixing Swift Testing test case methods with "test" #299

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

calda
Copy link
Member

@calda calda commented Feb 19, 2025

Summary

This PR proposes a new rule to avoid prefixing Swift Testing test case methods with a "test" prefix. Autocorrect is implemented in the swiftTestingTestCaseNames SwiftFormat rule (nicklockwood/SwiftFormat#1979).

import Testing

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

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

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

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

Reasoning

Prefixing test case methods with "test" was necessary with XCTest, but is not necessary in Swift Testing. Idiomatic usage of Swift Testing excludes the "test" prefix.

From Apple's migration guide:

image

@calda calda force-pushed the cal--swift-testing-test-case-names branch from da1c3c1 to 4ff2363 Compare February 19, 2025 01:19
@calda calda force-pushed the cal--swift-testing-test-case-names branch from 4ff2363 to 3685f80 Compare February 19, 2025 01:22
@calda calda changed the title Add rule to avoid prefixing Swift Testing test case methods with 'test Add rule to avoid prefixing Swift Testing test case methods with "test" Feb 19, 2025
Copy link
Contributor

@miguel-jimenez-0529 miguel-jimenez-0529 left a comment

Choose a reason for hiding this comment

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

Nice!

Comment on lines 3811 to +3812

* <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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants