`vertical_whitespace_between_cases` does not play nicely with `#if` guards
Open
Nobody has claimed this yet.
bug
resolved
- Dominant language
- Swift
- Stars
- 19.7k
- Forks
- 2.3k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 11
Description
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
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with rules.yml and test.swift using the reported swiftlint --fix command, then trace the vertical_whitespace_between_cases rule implementation. Compare the expected and unexpected switch output, and confirm the fix no longer inserts a blank line inside the #if guard.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100