mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-06-16 10:34:34 +00:00
Fix early return statement
This commit is contained in:
+3
-2
@@ -3137,10 +3137,11 @@ public struct _FormatRules {
|
||||
return
|
||||
}
|
||||
}
|
||||
if formatter.index(of: .keyword("return"), after: i) != nil {
|
||||
let endIndex = formatter.endOfScope(at: i)
|
||||
if let endIndex = endIndex, formatter.tokens[i + 1 ..< endIndex].contains(.keyword("return")) {
|
||||
return
|
||||
}
|
||||
if formatter.next(.nonSpaceOrLinebreak, after: i) == .endOfScope("}"),
|
||||
if formatter.index(of: .nonSpaceOrLinebreak, after: i) == endIndex,
|
||||
let startIndex = formatter.index(of: .nonSpaceOrLinebreak, before: i)
|
||||
{
|
||||
formatter.removeTokens(in: startIndex + 1 ... i)
|
||||
|
||||
@@ -2919,6 +2919,22 @@ class RedundancyTests: RulesTests {
|
||||
testFormatting(for: input, output, rule: FormatRules.redundantReturn, options: options)
|
||||
}
|
||||
|
||||
func testNoRemoveDebugReturnFollowedBySwitch() {
|
||||
let input = """
|
||||
func swiftFormatBug() -> Foo {
|
||||
return .foo
|
||||
|
||||
switch state {
|
||||
case .foo, .bar:
|
||||
return state
|
||||
}
|
||||
}
|
||||
"""
|
||||
let options = FormatOptions(swiftVersion: "5.9")
|
||||
testFormatting(for: input, rule: FormatRules.redundantReturn, options: options,
|
||||
exclude: ["wrapSwitchCases", "sortSwitchCases"])
|
||||
}
|
||||
|
||||
// MARK: - redundantBackticks
|
||||
|
||||
func testRemoveRedundantBackticksInLet() {
|
||||
|
||||
Reference in New Issue
Block a user