Skip to content

Commit

Permalink
Allow closures being directly called to be wrapped into parentheses (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyDanny authored Nov 16, 2024
1 parent fb3ce5a commit 707a63d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
[SimplyDanny](https://github.com/SimplyDanny)
[#5787](https://github.com/realm/SwiftLint/issues/5787)

* Stop triggering the `control_statement` rule on closures being directly
called as conditions.
[SimplyDanny](https://github.com/SimplyDanny)
[#5846](https://github.com/realm/SwiftLint/issues/5846)

* Do not trigger `self_in_property_initialization` rule on `self` in
key paths expressions.
[SimplyDanny](https://github.com/SimplyDanny)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ struct ControlStatementRule: Rule {
Example("switch (lhs, rhs) {}"),
Example("if (f() { g() {} }) {}"),
Example("if (a + f() {} == 1) {}"),
Example("if ({ true }()) {}"),
Example("if ({if i < 1 { true } else { false }}()) {}", excludeFromDocumentation: true),
],
triggeringExamples: [
Example("↓if (condition) {}"),
Expand Down Expand Up @@ -176,7 +178,7 @@ private extension ExprSyntax {
private func containsTrailingClosure(_ node: Syntax) -> Bool {
switch node.as(SyntaxEnum.self) {
case .functionCallExpr(let node):
node.trailingClosure != nil
node.trailingClosure != nil || node.calledExpression.is(ClosureExprSyntax.self)
case .sequenceExpr(let node):
node.elements.contains { containsTrailingClosure(Syntax($0)) }
default: false
Expand Down

0 comments on commit 707a63d

Please sign in to comment.