Skip to content

Commit

Permalink
Fix linebreak after sortedSwitchCases
Browse files Browse the repository at this point in the history
  • Loading branch information
facumenzella authored and nicklockwood committed May 21, 2023
1 parent 336b2b4 commit 12e1846
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 1 addition & 5 deletions Sources/Rules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5207,11 +5207,7 @@ public struct _FormatRules {
for switchCase in switchCaseRanges.enumerated().reversed() {
let newTokens = Array(sortedTokens[switchCase.offset])
var newComments = Array(sortedComments[switchCase.offset])
let oldCommentsRange = sorted[switchCaseRanges.count - switchCase.offset - 1].afterDelimiterRange

let oldComments = formatter.tokens[oldCommentsRange]

var shouldInsertBreakLine = sortedComments[switchCaseRanges.count - switchCase.offset - 1].first?.isLinebreak == true
let oldComments = formatter.tokens[switchCaseRanges[switchCase.offset].afterDelimiterRange]

if newComments.last?.isLinebreak == oldComments.last?.isLinebreak {
formatter.replaceTokens(in: switchCaseRanges[switchCase.offset].afterDelimiterRange, with: newComments)
Expand Down
17 changes: 17 additions & 0 deletions Tests/RulesTests+Organization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3084,6 +3084,23 @@ class OrganizationTests: RulesTests {
testFormatting(for: input, rule: FormatRules.sortedSwitchCases)
}

func testSortedSwitchCasesNoUnwrapReturn() {
let input = """
switch self {
case .b, .a, .c, .e, .d:
return nil
}
"""
let output = """
switch self {
case .a, .b, .c, .d, .e:
return nil
}
"""
testFormatting(for: input, output, rule: FormatRules.sortedSwitchCases,
exclude: ["wrapSwitchCases"])
}

// MARK: - modifierOrder

func testVarModifiersCorrected() {
Expand Down

0 comments on commit 12e1846

Please sign in to comment.