Skip to content

Commit

Permalink
Fix regression in wrapMultilineStatementBraces rule from bad isStartO…
Browse files Browse the repository at this point in the history
…fClosure result
  • Loading branch information
calda authored and nicklockwood committed Sep 30, 2024
1 parent be3df7b commit c5b089c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
8 changes: 1 addition & 7 deletions Sources/ParsingHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -571,13 +571,7 @@ extension Formatter {
}
return last(.nonSpaceOrCommentOrLinebreak, before: prevIndex) != .keyword("func")
default:
if let nextIndex = index(of: .nonSpaceOrCommentOrLinebreak, after: i),
isAccessorKeyword(at: nextIndex) || isAccessorKeyword(at: prevIndex)
{
return false
} else {
return !isConditionalStatement(at: startOfScope)
}
return false
}
fallthrough
case .identifier, .number, .operator("?", .postfix), .operator("!", .postfix),
Expand Down
21 changes: 21 additions & 0 deletions Tests/Rules/WrapMultilineStatementBracesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -703,4 +703,25 @@ class WrapMultilineStatementBracesTests: XCTestCase {
testFormatting(for: input, rules: [.wrapMultilineStatementBraces, .wrap],
options: options, exclude: [.indent, .redundantClosure, .wrapConditionalBodies])
}

func testWrapMultilineStatementBraceAfterWhereClauseWithTuple() {
let input = """
extension Foo {
public func testWithWhereClause<A, B, Outcome>(
a: A,
b: B)
-> Outcome where
Outcome == (A, B)
{
return (a, b)
}
}
"""

let options = FormatOptions(
wrapArguments: .beforeFirst,
closingParenPosition: .sameLine
)
testFormatting(for: input, rules: [.wrapMultilineStatementBraces, .braces], options: options)
}
}

0 comments on commit c5b089c

Please sign in to comment.