File tree Expand file tree Collapse file tree 3 files changed +69
-0
lines changed
Tests/SwiftFormatRulesTests Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,11 @@ class LintPipeline: SyntaxVisitor {
34
34
super. init ( viewMode: . sourceAccurate)
35
35
}
36
36
37
+ override func visit( _ node: ActorDeclSyntax ) -> SyntaxVisitorContinueKind {
38
+ visitIfEnabled ( TypeNamesShouldBeCapitalized . visit, for: node)
39
+ return . visitChildren
40
+ }
41
+
37
42
override func visit( _ node: AsExprSyntax ) -> SyntaxVisitorContinueKind {
38
43
visitIfEnabled ( NeverForceUnwrap . visit, for: node)
39
44
return . visitChildren
@@ -42,6 +47,7 @@ class LintPipeline: SyntaxVisitor {
42
47
override func visit( _ node: AssociatedTypeDeclSyntax ) -> SyntaxVisitorContinueKind {
43
48
visitIfEnabled ( BeginDocumentationCommentWithOneLineSummary . visit, for: node)
44
49
visitIfEnabled ( NoLeadingUnderscores . visit, for: node)
50
+ visitIfEnabled ( TypeNamesShouldBeCapitalized . visit, for: node)
45
51
return . visitChildren
46
52
}
47
53
@@ -304,6 +310,7 @@ class LintPipeline: SyntaxVisitor {
304
310
visitIfEnabled ( AllPublicDeclarationsHaveDocumentation . visit, for: node)
305
311
visitIfEnabled ( BeginDocumentationCommentWithOneLineSummary . visit, for: node)
306
312
visitIfEnabled ( NoLeadingUnderscores . visit, for: node)
313
+ visitIfEnabled ( TypeNamesShouldBeCapitalized . visit, for: node)
307
314
visitIfEnabled ( UseTripleSlashForDocumentationComments . visit, for: node)
308
315
return . visitChildren
309
316
}
Original file line number Diff line number Diff line change @@ -37,6 +37,21 @@ public final class TypeNamesShouldBeCapitalized : SyntaxLintRule {
37
37
return . visitChildren
38
38
}
39
39
40
+ public override func visit( _ node: ActorDeclSyntax ) -> SyntaxVisitorContinueKind {
41
+ diagnoseNameConventionMismatch ( node, name: node. name)
42
+ return . visitChildren
43
+ }
44
+
45
+ public override func visit( _ node: AssociatedTypeDeclSyntax ) -> SyntaxVisitorContinueKind {
46
+ diagnoseNameConventionMismatch ( node, name: node. name)
47
+ return . visitChildren
48
+ }
49
+
50
+ public override func visit( _ node: TypeAliasDeclSyntax ) -> SyntaxVisitorContinueKind {
51
+ diagnoseNameConventionMismatch ( node, name: node. name)
52
+ return . visitChildren
53
+ }
54
+
40
55
private func diagnoseNameConventionMismatch< T: DeclSyntaxProtocol > ( _ type: T , name: TokenSyntax ) {
41
56
if let firstChar = name. text. first, !firstChar. isUppercase {
42
57
diagnose ( . capitalizeTypeName( name: name. text) , on: type, severity: . convention)
Original file line number Diff line number Diff line change @@ -24,4 +24,51 @@ final class TypeNamesShouldBeCapitalizedTests: LintOrFormatRuleTestCase {
24
24
XCTAssertNotDiagnosed ( . capitalizeTypeName( name: " myType " ) )
25
25
XCTAssertDiagnosed ( . capitalizeTypeName( name: " innerType " ) )
26
26
}
27
+
28
+ func testActors( ) {
29
+ let input =
30
+ """
31
+ actor myActor {}
32
+ actor OtherActor {}
33
+ distributed actor greeter {}
34
+ distributed actor DistGreeter {}
35
+ """
36
+
37
+ performLint ( TypeNamesShouldBeCapitalized . self, input: input)
38
+
39
+ XCTAssertDiagnosed ( . capitalizeTypeName( name: " myActor " ) )
40
+ XCTAssertNotDiagnosed ( . capitalizeTypeName( name: " OtherActor " ) )
41
+ XCTAssertDiagnosed ( . capitalizeTypeName( name: " greeter " ) )
42
+ XCTAssertNotDiagnosed ( . capitalizeTypeName( name: " DistGreeter " ) )
43
+ }
44
+
45
+ func testAssociatedTypeandTypeAlias( ) {
46
+ let input =
47
+ """
48
+ protocol P {
49
+ associatedtype kind
50
+ associatedtype OtherKind
51
+ }
52
+
53
+ typealias x = Int
54
+ typealias Y = String
55
+
56
+ struct MyType {
57
+ typealias data<T> = Y
58
+
59
+ func test() {
60
+ typealias Value<T> = Y
61
+ }
62
+ }
63
+ """
64
+
65
+ performLint ( TypeNamesShouldBeCapitalized . self, input: input)
66
+
67
+ XCTAssertDiagnosed ( . capitalizeTypeName( name: " kind " ) )
68
+ XCTAssertNotDiagnosed ( . capitalizeTypeName( name: " OtherKind " ) )
69
+ XCTAssertDiagnosed ( . capitalizeTypeName( name: " x " ) )
70
+ XCTAssertNotDiagnosed ( . capitalizeTypeName( name: " Y " ) )
71
+ XCTAssertDiagnosed ( . capitalizeTypeName( name: " data " ) )
72
+ XCTAssertNotDiagnosed ( . capitalizeTypeName( name: " Value " ) )
73
+ }
27
74
}
You can’t perform that action at this time.
0 commit comments