Clarify AlwaysUseLowerCamelCase docs on the test-code carve-out#1209
Conversation
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.
| /// 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 |
There was a problem hiding this comment.
| /// 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.
|
Thanks @allevato, applied your suggested wording verbatim. The doc comment now reads "Test functions are functions that either: start with |
Please make sure the Markdown file is updated as well (running the generator will do this). |
|
Done, regenerated |
|
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 |
Problem
The
AlwaysUseLowerCamelCaserule 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: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.mdis regenerated from that comment viaswift run generate-swift-format.This is a documentation-only change; the rule's behavior is unchanged.
Testing
swift buildandswift test --filter AlwaysUseLowerCamelCaseTestspass. 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.