Skip to content

AlwaysUseLowerCamelCase reports violation for uppercase-starting test function names #1129

@elmetal

Description

@elmetal

The AlwaysUseLowerCamelCase rule documentation states that test code is ignored (files that import XCTest or functions marked with @Test).
However, the rule still reports violations for test function names that start with an uppercase letter.

Should the fix be applied to the implementation, or should the documentation be updated to clarify that only underscores are ignored in test code, not uppercase-starting names?

Reproduction

import Testing

struct MyTests {
    // This triggers a warning even though it's marked with `@Test`
    @Test func MyTestCase() {
        // ...
    }
}

Expected behavior (if documentation is correct): No warning, because the function marked with @Test.

Actual behavior: Warning is reported. warning: [AlwaysUseLowerCamelCase] rename the function 'MyTestCase' using lowerCamelCase

Root Cause

In AlwaysUseLowerCamelCase.swift, whether a function is marked with @Test is determined by the allowUnderscores flag.

let allowUnderscores = testCaseFuncs.contains(node) || node.hasAttribute("Test", inModule: "Testing")

The diagnoseLowerCamelCaseViolations function checks for underscores with the allowUnderscores flag.
However, the uppercase check does not consider the allowUnderscores flag:

if (text.dropFirst().contains("_") && !allowUnderscores) || ("A"..."Z").contains(text.first!) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions