From fa5f98f6f396fa8a0e1fe35fe51374eda0917fdb Mon Sep 17 00:00:00 2001 From: Muhammet Ilendemli Date: Sat, 22 Jun 2024 19:50:08 +0200 Subject: [PATCH] Make `vertical_whitespace_between_cases` rule work when case block ends with a string literal (#5628) --- CHANGELOG.md | 5 +++++ .../VerticalWhitespaceBetweenCasesRule.swift | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 775e8ef1e..590831299 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,11 @@ `unneeded_synthesized_initializer` rule. [SimplyDanny](https://github.com/SimplyDanny) [#5153](https://github.com/realm/SwiftLint/issues/5153) + +* Make `vertical_whitespace_between_cases` rule work for + cases ending with a string literal. + [ilendemli](https://github.com/ilendemli) + [#5612](https://github.com/realm/SwiftLint/issues/5612) * Ignore access level modifiers restricted to value setting in `extension_access_modifier` rule. diff --git a/Source/SwiftLintBuiltInRules/Rules/Style/VerticalWhitespaceBetweenCasesRule.swift b/Source/SwiftLintBuiltInRules/Rules/Style/VerticalWhitespaceBetweenCasesRule.swift index bcc63cd45..55f28a260 100644 --- a/Source/SwiftLintBuiltInRules/Rules/Style/VerticalWhitespaceBetweenCasesRule.swift +++ b/Source/SwiftLintBuiltInRules/Rules/Style/VerticalWhitespaceBetweenCasesRule.swift @@ -3,7 +3,7 @@ import SourceKittenFramework private extension SwiftLintFile { func violatingRanges(for pattern: String) -> [NSRange] { - return match(pattern: pattern, excludingSyntaxKinds: SyntaxKind.commentAndStringKinds) + return match(pattern: pattern, excludingSyntaxKinds: SyntaxKind.commentKinds) } } @@ -57,6 +57,22 @@ struct VerticalWhitespaceBetweenCasesRule: Rule { ] private static let violatingToValidExamples: [Example: Example] = [ + Example(""" + switch x { + case 0..<5: + return "x is valid" + ↓ default: + return "x is invalid" + } + """): Example(""" + switch x { + case 0..<5: + return "x is valid" + + default: + return "x is invalid" + } + """), Example(""" switch x { case 0..<5: