diff --git a/Snapshots/Expression/Sources/AnyExpression.swift b/Snapshots/Expression/Sources/AnyExpression.swift index f489d890..6d5b5861 100755 --- a/Snapshots/Expression/Sources/AnyExpression.swift +++ b/Snapshots/Expression/Sources/AnyExpression.swift @@ -725,7 +725,7 @@ extension AnyExpression { } } - // Unwraps a potentially optional value + /// Unwraps a potentially optional value static func unwrap(_ value: Any) -> Any? { switch value { case let optional as _Optional: @@ -740,7 +740,7 @@ extension AnyExpression { } } - // Test if a value is nil + /// Test if a value is nil static func isNil(_ value: Any) -> Bool { if let optional = value as? _Optional { guard let value = optional.value else { @@ -751,7 +751,7 @@ extension AnyExpression { return value is NSNull } - // Test if a value supports subscripting + /// Test if a value supports subscripting static func isSubscriptable(_ value: Any) -> Bool { return value is _Array || value is _Dictionary || value is _String } @@ -870,7 +870,7 @@ private extension AnyExpression { } } -// Used for casting numeric values +/// Used for casting numeric values private protocol _Numeric { init(truncating: NSNumber) } @@ -896,7 +896,7 @@ extension Float: _Numeric {} extension CGFloat: _Numeric {} #endif -// Used for subscripting +/// Used for subscripting private protocol _Range { func slice(of array: _Array, for symbol: Expression.Symbol) throws -> ArraySlice func slice(of string: _String, for symbol: Expression.Symbol) throws -> Substring @@ -1104,7 +1104,7 @@ extension PartialRangeFrom: _Range { #endif -// Used for string values +/// Used for string values private protocol _String { var substring: Substring { get } } @@ -1127,7 +1127,7 @@ extension NSString: _String { } } -// Used for array values +/// Used for array values private protocol _Array { var values: [Any] { get } } @@ -1162,7 +1162,7 @@ extension NSArray: _Array { } } -// Used for dictionary values +/// Used for dictionary values private protocol _Dictionary { func value(for key: Any) -> Any? } @@ -1182,7 +1182,7 @@ extension NSDictionary: _Dictionary { } } -// Used to test if a value is Optional +/// Used to test if a value is Optional private protocol _Optional { var value: Any? { get } static var wrappedType: Any.Type { get } diff --git a/Sources/Formatter.swift b/Sources/Formatter.swift index b866eb5e..c04746e1 100644 --- a/Sources/Formatter.swift +++ b/Sources/Formatter.swift @@ -740,7 +740,13 @@ public extension Formatter { var scopeStack: [Token] = [] for i in range.reversed() { let token = tokens[i] - if case .startOfScope = token { + if token == .startOfScope(":"), scopeStack.last == .endOfScope("#endif") { + continue + } else if [.endOfScope("case"), .endOfScope("default")].contains(token), + scopeStack.last == .endOfScope("#endif") + { + continue + } else if case .startOfScope = token { if let scope = scopeStack.last, scope.isEndOfScope(token) { scopeStack.removeLast() } else if token.string == "//", linebreakEncountered { diff --git a/Tests/Rules/DocCommentsTests.swift b/Tests/Rules/DocCommentsTests.swift index d2225a3f..08842517 100644 --- a/Tests/Rules/DocCommentsTests.swift +++ b/Tests/Rules/DocCommentsTests.swift @@ -604,4 +604,42 @@ final class DocCommentsTests: XCTestCase { testFormatting(for: input, output, rule: .docComments) } + + func testDocCommentsAfterSwitchCase() { + let input = """ + func foo() { + switch bar { + case .foo: + break + default: + break + } + } + + /// Baz + func baz() {} + """ + + testFormatting(for: input, rule: .docComments) + } + + func testDocCommentsAfterConditionalSwitchCase() { + let input = """ + func foo() { + switch bar { + #if DEBUG + case .foo: + break + #endif + default: + break + } + } + + /// Baz + func baz() {} + """ + + testFormatting(for: input, rule: .docComments) + } }