Skip to content

Commit

Permalink
Support SE-0430 sending in spaceAroundBrackets/Parens (#1701)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jnosh committed May 17, 2024
1 parent 7f700c8 commit 0a35ade
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Sources/Rules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions Tests/RulesTests+Spacing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 0a35ade

Please sign in to comment.