Skip to content

Commit

Permalink
Align left brace of additional trailing closures with right brace of …
Browse files Browse the repository at this point in the history
…previous trailing closure (realm#5761)
  • Loading branch information
SimplyDanny authored Aug 19, 2024
1 parent d5f7f9c commit 74f4778
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
[SimplyDanny](https://github.com/SimplyDanny)
[#5752](https://github.com/realm/SwiftLint/issues/5752)

* Align left brace of additional trailing closures with right brace of previous trailing closure
in `contrasted_opening_brace` rule.
[SimplyDanny](https://github.com/SimplyDanny)
[#5752](https://github.com/realm/SwiftLint/issues/5752)

## 0.56.1: Heat Pump Dryer

#### Breaking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,29 @@ private extension BracedSyntax {
}
if let closure = `as`(ClosureExprSyntax.self),
closure.keyPathInParent == \FunctionCallExprSyntax.trailingClosure {
var indentationDecidingToken = closure.leftBrace
repeat {
if let previousToken = indentationDecidingToken.previousToken(viewMode: .sourceAccurate) {
indentationDecidingToken = previousToken
} else {
break
}
} while indentationDecidingToken.leadingTrivia.containsNewlines() == false
return indentationDecidingToken
return closure.leftBrace.previousIndentationDecidingToken
}
if let closureLabel = parent?.as(MultipleTrailingClosureElementSyntax.self)?.label {
return closureLabel.previousIndentationDecidingToken
}
return parent
}
}

private extension TokenSyntax {
var previousIndentationDecidingToken: TokenSyntax {
var indentationDecidingToken = self
repeat {
if let previousToken = indentationDecidingToken.previousToken(viewMode: .sourceAccurate) {
indentationDecidingToken = previousToken
} else {
break
}
} while !indentationDecidingToken.leadingTrivia.containsNewlines()
return indentationDecidingToken
}
}

private extension IfExprSyntax {
var indentationDecidingParent: any SyntaxProtocol {
if keyPathInParent == \IfExprSyntax.elseBody, let parent = parent?.as(IfExprSyntax.self) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ struct ContrastedOpeningBraceRuleExamples {
↓{ $0 }
}
"""),
Example("""
a ↓{
$0
} b: ↓{
$1
}
"""),
]

static let corrections = [
Expand Down Expand Up @@ -456,5 +463,20 @@ struct ContrastedOpeningBraceRuleExamples {
.c
{ $1 }
"""),
Example("""
a {
$0
} b: {
$1
}
"""): Example("""
a
{
$0
} b:
{
$1
}
"""),
]
}

0 comments on commit 74f4778

Please sign in to comment.