File tree 3 files changed +23
-36
lines changed
Tests/SwiftFormatRulesTests
3 files changed +23
-36
lines changed Original file line number Diff line number Diff line change @@ -31,12 +31,6 @@ func populate(_ pipeline: Pipeline) {
31
31
MemberDeclBlockSyntax . self
32
32
)
33
33
34
- pipeline. addFormatter (
35
- CloseBraceWhitespace . self,
36
- for:
37
- TokenSyntax . self
38
- )
39
-
40
34
pipeline. addFormatter (
41
35
CollectionLiteralWhitespace . self,
42
36
for:
@@ -280,6 +274,12 @@ func populate(_ pipeline: Pipeline) {
280
274
SwitchStmtSyntax . self
281
275
)
282
276
277
+ pipeline. addLinter (
278
+ CloseBraceWhitespace . self,
279
+ for:
280
+ TokenSyntax . self
281
+ )
282
+
283
283
pipeline. addLinter (
284
284
CommentWhitespace . self,
285
285
for:
Original file line number Diff line number Diff line change @@ -20,17 +20,14 @@ import SwiftSyntax
20
20
/// Lint: If a close brace does not have a line break before it, except as covered by One Statement
21
21
/// Per Line, a lint error will be raised.
22
22
///
23
- /// Format: Line breaks will be inserted for all non-conforming close braces.
24
- ///
25
23
/// - SeeAlso: https://google.github.io/swift#braces
26
- public final class CloseBraceWhitespace : SyntaxFormatRule {
27
- public override func visit( _ token: TokenSyntax ) -> Syntax {
28
- guard token. tokenKind == . rightBrace else { return token }
29
- if isInAllowedSingleLineContainer ( token) { return token }
30
- if token. leadingTrivia. containsNewlines { return token }
24
+ public final class CloseBraceWhitespace : SyntaxLintRule {
25
+ public override func visit( _ token: TokenSyntax ) {
26
+ guard token. tokenKind == . rightBrace else { return }
27
+ if isInAllowedSingleLineContainer ( token) { return }
28
+ if token. leadingTrivia. containsNewlines { return }
31
29
32
30
diagnose ( . lineBreakRequiredBeforeCloseBrace, on: token)
33
- return token. withOneLeadingNewline ( )
34
31
}
35
32
}
36
33
@@ -57,4 +54,3 @@ extension Diagnostic.Message {
57
54
static let lineBreakRequiredBeforeCloseBrace =
58
55
Diagnostic . Message ( . warning, " insert a newline before this '}' " )
59
56
}
60
-
Original file line number Diff line number Diff line change @@ -6,32 +6,23 @@ import SwiftSyntax
6
6
7
7
public class CloseBraceWhitespaceTests : DiagnosingTestCase {
8
8
public func testInvalidCloseBraceWhitespace( ) {
9
- XCTAssertFormatting (
10
- CloseBraceWhitespace . self,
11
- input: """
12
- func a()
13
- { print( " hello " )
14
- print( " goodbye " )}
15
- func b(){
16
- }
17
- func c() {}
18
- """ ,
19
- expected: """
20
- func a()
21
- { print( " hello " )
22
- print( " goodbye " )
23
- }
24
- func b(){
25
- }
26
- func c() {}
27
- """ )
9
+ let input =
10
+ """
11
+ func a()
12
+ { print( " hello " )
13
+ print( " goodbye " )}
14
+ func b(){
15
+ }
16
+ func c() {}
17
+ """
18
+
19
+ performLint ( CloseBraceWhitespace . self, input: input)
20
+ XCTAssertDiagnosed ( . lineBreakRequiredBeforeCloseBrace)
28
21
}
29
22
30
23
#if !os(macOS)
31
24
static let allTests = [
32
25
CloseBraceWhitespaceTests . testInvalidCloseBraceWhitespace,
33
26
]
34
27
#endif
35
-
36
28
}
37
-
You can’t perform that action at this time.
0 commit comments