mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-06-16 10:34:34 +00:00
Fix assertion failure in redundantSelf rule
This commit is contained in:
@@ -2753,7 +2753,7 @@ extension Formatter {
|
||||
continue
|
||||
case .startOfScope("{") where isWhereClause && scopeStack.count == 1:
|
||||
return
|
||||
case .startOfScope("{") where lastKeyword == "switch":
|
||||
case .startOfScope("{") where lastKeyword == "switch" && scopeStack.count == 1:
|
||||
lastKeyword = ""
|
||||
index += 1
|
||||
loop: while let token = self.token(at: index) {
|
||||
|
||||
@@ -6505,7 +6505,28 @@ class RedundancyTests: RulesTests {
|
||||
}
|
||||
"""
|
||||
let options = FormatOptions(swiftVersion: "5.9")
|
||||
testFormatting(for: input, rule: FormatRules.indent, options: options)
|
||||
testFormatting(for: input, rule: FormatRules.redundantSelf, options: options)
|
||||
}
|
||||
|
||||
func testRedundantSelfNotConfusedByStaticAfterSwitch() {
|
||||
let input = """
|
||||
public final class MyClass {
|
||||
private static func privateStaticFunction1() -> Bool {
|
||||
switch Result(catching: { try someThrowingFunction() }) {
|
||||
case .success:
|
||||
return true
|
||||
case .failure:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
private static func privateStaticFunction2() -> Bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
"""
|
||||
let options = FormatOptions(explicitSelf: .insert)
|
||||
testFormatting(for: input, rule: FormatRules.redundantSelf, options: options, exclude: ["enumNamespaces"])
|
||||
}
|
||||
|
||||
// MARK: - redundantStaticSelf
|
||||
|
||||
Reference in New Issue
Block a user