File tree 2 files changed +21
-1
lines changed
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,13 @@ public final class NoEmptyTrailingClosureParentheses: SyntaxFormatRule {
15
15
public override func visit( _ node: FunctionCallExprSyntax ) -> ExprSyntax {
16
16
guard node. argumentList. count == 0 else { return node }
17
17
18
- guard let name = node. calledExpression. firstToken? . withoutTrivia ( ) else { return node }
18
+ guard node. trailingClosure != nil && node. argumentList. isEmpty && node. leftParen != nil else {
19
+ return node
20
+ }
21
+ guard let name = node. calledExpression. lastToken? . withoutTrivia ( ) else {
22
+ return node
23
+ }
24
+
19
25
diagnose ( . removeEmptyTrailingParentheses( name: " \( name) " ) , on: node)
20
26
21
27
let formattedExp = replaceTrivia ( on: node. calledExpression,
Original file line number Diff line number Diff line change @@ -17,6 +17,12 @@ public class NoEmptyTrailingClosureParenthesesTests: DiagnosingTestCase {
17
17
}
18
18
greetEnthusiastically() { " John " }
19
19
greetApathetically { " not John " }
20
+ func myfunc(cls: MyClass) {
21
+ cls.myClosure { $0 }
22
+ }
23
+ func myfunc(cls: MyClass) {
24
+ cls.myBadClosure() { $0 }
25
+ }
20
26
""" ,
21
27
expected: """
22
28
func greetEnthusiastically(_ nameProvider: () -> String) {
@@ -27,8 +33,16 @@ public class NoEmptyTrailingClosureParenthesesTests: DiagnosingTestCase {
27
33
}
28
34
greetEnthusiastically { " John " }
29
35
greetApathetically { " not John " }
36
+ func myfunc(cls: MyClass) {
37
+ cls.myClosure { $0 }
38
+ }
39
+ func myfunc(cls: MyClass) {
40
+ cls.myBadClosure { $0 }
41
+ }
30
42
""" )
31
43
XCTAssertDiagnosed ( . removeEmptyTrailingParentheses( name: " greetEnthusiastically " ) )
44
+ XCTAssertDiagnosed ( . removeEmptyTrailingParentheses( name: " myBadClosure " ) )
45
+ XCTAssertNotDiagnosed ( . removeEmptyTrailingParentheses( name: " myClosure " ) )
32
46
}
33
47
34
48
#if !os(macOS)
You can’t perform that action at this time.
0 commit comments