File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,14 @@ public final class ColonWhitespace: SyntaxFormatRule {
17
17
public override func visit( _ token: TokenSyntax ) -> Syntax {
18
18
guard let next = token. nextToken else { return token }
19
19
20
+ if token. tokenKind == . colon,
21
+ token. containingExprStmtOrDecl is DictionaryExprSyntax ,
22
+ next. tokenKind == . rightSquareBracket,
23
+ token. trailingTrivia. numberOfSpaces > 0 {
24
+ diagnose ( . noSpacesAfterColon, on: token)
25
+ return token. withoutTrailingTrivia ( )
26
+ }
27
+
20
28
/// Colons own their trailing spaces, so ensure it only has 1 if there's
21
29
/// another token on the same line.
22
30
if token. tokenKind == . colon,
@@ -51,4 +59,6 @@ extension Diagnostic.Message {
51
59
Diagnostic . Message ( . warning, " add one space after ':' " )
52
60
static let noSpacesBeforeColon =
53
61
Diagnostic . Message ( . warning, " remove spaces before ':' " )
62
+ static let noSpacesAfterColon =
63
+ Diagnostic . Message ( . warning, " remove spaces after ':' " )
54
64
}
Original file line number Diff line number Diff line change @@ -12,12 +12,16 @@ public class ColonWhitespaceTests: DiagnosingTestCase {
12
12
let v2 : Int = 1
13
13
let v3 :Int = 1
14
14
let v4 \t : \t Int = 1
15
+ let v5: [Int: String] = [: ]
16
+ let v6: [Int: String] = [23: " twenty three " ]
15
17
""" ,
16
18
expected: """
17
19
let v1: Int = 0
18
20
let v2: Int = 1
19
21
let v3: Int = 1
20
22
let v4: Int = 1
23
+ let v5: [Int: String] = [:]
24
+ let v6: [Int: String] = [23: " twenty three " ]
21
25
""" )
22
26
}
23
27
You can’t perform that action at this time.
0 commit comments