realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.45k stars 2.2k forks source link

change excludingSyntaxKinds for VerticalWhitespaceBetweenCasesRule.swift #5612

Closed ilendemli closed 1 week ago

ilendemli commented 1 month ago

Hi I was applying this ruleset and saw it skip some parts of my code

Regarding this: https://github.com/realm/SwiftLint/blob/b42f6ffe77159aed1060bf607212a0410c7623b8/Source/SwiftLintBuiltInRules/Rules/Style/VerticalWhitespaceBetweenCasesRule.swift#L6

I think it should also apply for String cases and only exclude SyntaxKind.commentKinds

SimplyDanny commented 2 weeks ago

What's an example that would work correctly with this change?

ilendemli commented 2 weeks ago

Currently running the fix argument against a file such as:

import Foundation

enum TestCase: String {
    case one = "1"
    case two = "2"
    case three = "3"

    var caseToString: String {
        switch self {
        case .one:
            return "one"
        case .two:
            return "two"
        case .three:
            return "three"
        }
    }

    var rawToString: String {
        switch rawValue {
        case "1":
            return "one"
        case "2":
            return "two"
        case "3":
            return "three"
        }
    }
}

does not change anything. With the above change to only exclude SyntaxKind.commentKinds the file gets corrected to:

import Foundation

enum TestCase: String {
    case one = "1"
    case two = "2"
    case three = "3"

    var caseToString: String {
        switch self {
        case .one:
            return "one"

        case .two:
            return "two"

        case .three:
            return "three"
        }
    }

    var rawToString: String {
        switch rawValue {
        case "1":
            return "one"

        case "2":
            return "two"

        case "3":
            return "three"
        }
    }
}
SimplyDanny commented 2 weeks ago

Would you like to open a PR to fix this, @ilendemli?

ilendemli commented 2 weeks ago

@SimplyDanny https://github.com/realm/SwiftLint/pull/5628