realm / realm/SwiftLint

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

Open
#4,022 4 comments 1 reaction 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.