File tree 2 files changed +41
-0
lines changed
2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -10,4 +10,15 @@ import SwiftSyntax
10
10
/// - SeeAlso: https://google.github.io/swift#trailing-closures
11
11
public final class OnlyOneTrailingClosureArgument : SyntaxLintRule {
12
12
13
+ public override func visit( _ node: FunctionCallExprSyntax ) {
14
+ guard ( node. argumentList. contains { $0. expression is ClosureExprSyntax } ) else { return }
15
+ guard node. trailingClosure != nil else { return }
16
+ diagnose ( . removeTrailingClosure, on: node)
17
+ }
18
+ }
19
+
20
+ extension Diagnostic . Message {
21
+ static let removeTrailingClosure =
22
+ Diagnostic . Message ( . warning,
23
+ " function call shouldn't have both closure arguments and a trailing closure " )
13
24
}
Original file line number Diff line number Diff line change
1
+ import Foundation
2
+ import SwiftSyntax
3
+ import XCTest
4
+
5
+ @testable import Rules
6
+
7
+ public class OnlyOneTrailingClosureArgumentTests : DiagnosingTestCase {
8
+ public func testInvalidTrailingClosureCall( ) {
9
+ let input =
10
+ """
11
+ callWithBoth(someClosure: {}) {
12
+ // ...
13
+ }
14
+ callWithClosure(someClosure: {})
15
+ callWithTrailingClosure {
16
+ // ...
17
+ }
18
+ """
19
+ performLint ( OnlyOneTrailingClosureArgument . self, input: input)
20
+ XCTAssertDiagnosed ( . removeTrailingClosure)
21
+ XCTAssertNotDiagnosed ( . removeTrailingClosure)
22
+ XCTAssertNotDiagnosed ( . removeTrailingClosure)
23
+ }
24
+
25
+ #if !os(macOS)
26
+ static let allTests = [
27
+ OnlyOneTrailingClosureArgumentTests . testInvalidTrailingClosureCall,
28
+ ]
29
+ #endif
30
+ }
You can’t perform that action at this time.
0 commit comments