diff --git a/Sources/Rules.swift b/Sources/Rules.swift index 93ebf67f2..97bebc294 100644 --- a/Sources/Rules.swift +++ b/Sources/Rules.swift @@ -261,7 +261,8 @@ public struct _FormatRules { .identifier("any") where formatter.isTypePosition(at: index), .identifier("borrowing") where formatter.isTypePosition(at: index), .identifier("consuming") where formatter.isTypePosition(at: index), - .identifier("isolated") where formatter.isTypePosition(at: index): + .identifier("isolated") where formatter.isTypePosition(at: index), + .identifier("sending") where formatter.isTypePosition(at: index): formatter.insert(.space(" "), at: i) case .space: let index = i - 2 @@ -273,7 +274,8 @@ public struct _FormatRules { .identifier("any") where formatter.isTypePosition(at: index), .identifier("borrowing") where formatter.isTypePosition(at: index), .identifier("consuming") where formatter.isTypePosition(at: index), - .identifier("isolated") where formatter.isTypePosition(at: index): + .identifier("isolated") where formatter.isTypePosition(at: index), + .identifier("sending") where formatter.isTypePosition(at: index): break case let .keyword(string) where !spaceAfter(string, index: index): fallthrough @@ -343,14 +345,16 @@ public struct _FormatRules { switch prevToken { case .keyword, .identifier("borrowing") where formatter.isTypePosition(at: index), - .identifier("consuming") where formatter.isTypePosition(at: index): + .identifier("consuming") where formatter.isTypePosition(at: index), + .identifier("sending") where formatter.isTypePosition(at: index): formatter.insert(.space(" "), at: i) case .space: let index = i - 2 if let token = formatter.token(at: index) { switch token { case .identifier("borrowing") where formatter.isTypePosition(at: index), - .identifier("consuming") where formatter.isTypePosition(at: index): + .identifier("consuming") where formatter.isTypePosition(at: index), + .identifier("sending") where formatter.isTypePosition(at: index): break case .identifier, .number, .endOfScope("]"), .endOfScope("}"), .endOfScope(")"): formatter.removeToken(at: i - 1) diff --git a/Tests/RulesTests+Spacing.swift b/Tests/RulesTests+Spacing.swift index d34a51712..e5e257a70 100644 --- a/Tests/RulesTests+Spacing.swift +++ b/Tests/RulesTests+Spacing.swift @@ -341,6 +341,12 @@ class SpacingTests: RulesTests { testFormatting(for: input, output, rule: FormatRules.spaceAroundParens) } + func testAddSpaceBetweenParenAndSending() { + let input = "func foo(_: sending(any Foo)) {}" + let output = "func foo(_: sending (any Foo)) {}" + testFormatting(for: input, output, rule: FormatRules.spaceAroundParens) + } + // MARK: - spaceInsideParens func testSpaceInsideParens() { @@ -439,6 +445,12 @@ class SpacingTests: RulesTests { exclude: ["noExplicitOwnership"]) } + func testAddSpaceBetweenSendingAndStringArray() { + let input = "func foo(arg _: sending[String]) {}" + let output = "func foo(arg _: sending [String]) {}" + testFormatting(for: input, output, rule: FormatRules.spaceAroundBrackets) + } + // MARK: - spaceInsideBrackets func testSpaceInsideBrackets() {