SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

`vertical_whitespace_between_cases` does not play nicely with `#if` guards

Open JosephPecoraro opened this issue 3 years ago • 1 comments

Describe the bug

vertical_whitespace_between_cases does not play nicely with #if guards, unexpectedly inserts an extra newline inside the guard.

Environment

disabled_rules:
 - switch_case_alignment

opt_in_rules:
 - vertical_whitespace_between_cases

Command

$ swiftlint --config rules.yml test.swift --fix
Correcting Swift files at paths test.swift
Correcting 'test.swift' (1/1)
test.swift:10:15 Corrected Vertical Whitespace Between Cases
Done inspecting 1 file for auto-correction!

Input (expected to be unchanged)

enum MyEnum {
    case one
    case two
}

let value = MyEnum.one
switch value {
    case .one:
        print("one")
#if arch(arm64)
    case .two:
        print("two")
#endif
}

Output (unexpected)

enum MyEnum {
    case one
    case two
}

let value = MyEnum.one
switch value {
    case .one:
        print("one")
#if arch(arm64)

    case .two:
        print("two")
#endif
}

JosephPecoraro avatar Jul 11 '22 20:07 JosephPecoraro

:) would like to see a fix for this too. We have many #if's in our code that doesn't look nice currently with the rule.

dungi avatar Nov 15 '23 12:11 dungi