Skip to content

Clarify AlwaysUseLowerCamelCase docs on the test-code carve-out#1209

Merged
allevato merged 3 commits into
swiftlang:mainfrom
adityasingh2400:clarify-lowercamelcase-test-docs
May 26, 2026
Merged

Clarify AlwaysUseLowerCamelCase docs on the test-code carve-out#1209
allevato merged 3 commits into
swiftlang:mainfrom
adityasingh2400:clarify-lowercamelcase-test-docs

Conversation

@adityasingh2400

Copy link
Copy Markdown
Contributor

Problem

The AlwaysUseLowerCamelCase rule documentation says the rule "does not apply to test code" (code that imports XCTest or has a function marked with @Test). That is not what the rule does. The test-code carve-out only relaxes the restriction on underscores; the lower camel-case requirement still applies, so a test function whose name begins with a capital letter is still diagnosed.

For example, this still produces a warning even though the function is marked @Test:

import Testing

struct MyTests {
  @Test func MyTestCase() {}  // warning: [AlwaysUseLowerCamelCase] rename the function 'MyTestCase' using lowerCamelCase
}

This matches the behavior described by the maintainer in #1129: underscores are permitted in test names by convention, but UpperCamelCase is not allowed just because something is a test.

Fix

Reword the rule's doc comment to describe the actual behavior: underscores are allowed in test function names, while the lower camel-case requirement otherwise still applies. RuleDocumentation.md is regenerated from that comment via swift run generate-swift-format.

This is a documentation-only change; the rule's behavior is unchanged.

Testing

swift build and swift test --filter AlwaysUseLowerCamelCaseTests pass. The existing tests already cover both halves of the clarified wording: underscores are accepted in test names (testIgnoresUnderscoresInTestNames, testIgnoresFunctionsWithTestAttributes) while invalid casing is still flagged (testInvalidFunctionCasing).

Fixes #1129.

The rule documentation stated that AlwaysUseLowerCamelCase does not apply
to test code. In practice the carve-out only relaxes the restriction on
underscores; a test function whose name begins with a capital letter is
still diagnosed. Reword the rule's doc comment to describe the actual
behavior and regenerate RuleDocumentation.md.
Comment on lines +21 to +23
/// code is defined as code which:
/// * Contains the line `import XCTest`
/// * The function is marked with `@Test` attribute
/// * Has a function marked with the `@Test` attribute

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
/// code is defined as code which:
/// * Contains the line `import XCTest`
/// * The function is marked with `@Test` attribute
/// * Has a function marked with the `@Test` attribute
/// functions are functions that either:
/// * start with `test` in a file containing `import XCTest`, or
/// * are marked with the `@Test` attribute.

Adopt allevato's phrasing describing test functions as those that start with test in an XCTest file or are marked with the @test attribute.
@adityasingh2400

Copy link
Copy Markdown
Contributor Author

Thanks @allevato, applied your suggested wording verbatim. The doc comment now reads "Test functions are functions that either: start with test in a file containing import XCTest, or are marked with the @Test attribute." Build and strict lint both pass.

@allevato

Copy link
Copy Markdown
Member

Thanks @allevato, applied your suggested wording verbatim. The doc comment now reads "Test functions are functions that either: start with test in a file containing import XCTest, or are marked with the @Test attribute." Build and strict lint both pass.

Please make sure the Markdown file is updated as well (running the generator will do this).

@adityasingh2400

Copy link
Copy Markdown
Contributor Author

Done, regenerated Documentation/RuleDocumentation.md with generate-swift-format. The AlwaysUseLowerCamelCase section now matches the updated doc comment. Ready for another look.

@allevato allevato enabled auto-merge (squash) May 26, 2026 12:36
@adityasingh2400

Copy link
Copy Markdown
Contributor Author

Heads up: the red CI here is a transient infrastructure failure, not the doc change. Every failed job, including unrelated ones like the shell, YAML, and license-header checks, failed at the Checkout repository step and then skipped the actual check. The only change in the last commit is the regenerated RuleDocumentation.md, so a re-run should bring it back green. I do not have permission to re-run it from my side.

@allevato allevato merged commit 38f6e71 into swiftlang:main May 26, 2026
43 of 60 checks passed
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.

AlwaysUseLowerCamelCase reports violation for uppercase-starting test function names

2 participants