Skip to content

Commit 431c77b

Browse files
committed
Validate that no child contains the substring 'Identifier'
1 parent 5c2923f commit 431c77b

File tree

7 files changed

+391
-178
lines changed

7 files changed

+391
-178
lines changed

CodeGeneration/Sources/SyntaxSupport/GenericNodes.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ public let GENERIC_NODES: [Node] = [
1818
nameForDiagnostics: "conformance requirement",
1919
children: [
2020
Child(
21-
name: "LeftTypeIdentifier",
21+
name: "LeftType",
22+
deprecatedName: "LeftTypeIdentifier",
2223
kind: .node(kind: .type)
2324
),
2425
Child(
2526
name: "Colon",
2627
kind: .token(choices: [.token(tokenKind: "ColonToken")])
2728
),
2829
Child(
29-
name: "RightTypeIdentifier",
30+
name: "RightType",
31+
deprecatedName: "RightTypeIdentifier",
3032
kind: .node(kind: .type)
3133
),
3234
]
@@ -193,7 +195,8 @@ public let GENERIC_NODES: [Node] = [
193195
nameForDiagnostics: "layout requirement",
194196
children: [
195197
Child(
196-
name: "TypeIdentifier",
198+
name: "Type",
199+
deprecatedName: "TypeIdentifier",
197200
kind: .node(kind: .type),
198201
nameForDiagnostics: "constrained type"
199202
),
@@ -303,7 +306,8 @@ public let GENERIC_NODES: [Node] = [
303306
nameForDiagnostics: "same type requirement",
304307
children: [
305308
Child(
306-
name: "LeftTypeIdentifier",
309+
name: "LeftType",
310+
deprecatedName: "LeftTypeIdentifier",
307311
kind: .node(kind: .type),
308312
nameForDiagnostics: "left-hand type"
309313
),
@@ -313,7 +317,8 @@ public let GENERIC_NODES: [Node] = [
313317
kind: .token(choices: [.token(tokenKind: "BinaryOperatorToken"), .token(tokenKind: "PrefixOperatorToken"), .token(tokenKind: "PostfixOperatorToken")])
314318
),
315319
Child(
316-
name: "RightTypeIdentifier",
320+
name: "RightType",
321+
deprecatedName: "RightTypeIdentifier",
317322
kind: .node(kind: .type),
318323
nameForDiagnostics: "right-hand type"
319324
),

CodeGeneration/Tests/ValidateSyntaxNodes/ValidateSyntaxNodes.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -596,16 +596,16 @@ class ValidateSyntaxNodes: XCTestCase {
596596
}
597597

598598
/// Identifier is a wonderful ambiguous term. Almost always, 'name' or something similar is more expressive
599-
func testNoChildIsNamedIdentifier() {
599+
func testNoChildContainsIdentifier() {
600600
var failures: [ValidationFailure] = []
601601

602602
for node in SYNTAX_NODES.compactMap(\.layoutNode) {
603-
for child in node.children {
604-
if child.name == "Identifier" {
603+
for child in node.nonUnexpectedChildren {
604+
if child.name.contains("Identifier") {
605605
failures.append(
606606
ValidationFailure(
607607
node: node.kind,
608-
message: "children should generally not be named 'Identifier'"
608+
message: "child '\(child.name)' should generally not contain 'Identifier'"
609609
)
610610
)
611611
}
@@ -616,8 +616,8 @@ class ValidateSyntaxNodes: XCTestCase {
616616
failures,
617617
expectedFailures: [
618618
// The identifier expr / pattern nodes do actually have a child that’s the identifier
619-
ValidationFailure(node: .identifierExpr, message: "children should generally not be named 'Identifier'"),
620-
ValidationFailure(node: .identifierPattern, message: "children should generally not be named 'Identifier'"),
619+
ValidationFailure(node: .identifierExpr, message: "child 'Identifier' should generally not contain 'Identifier'"),
620+
ValidationFailure(node: .identifierPattern, message: "child 'Identifier' should generally not contain 'Identifier'"),
621621
]
622622
)
623623
}

Sources/SwiftParserDiagnostics/generated/ChildNameForDiagnostics.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ private func childNameForDiagnostics(_ keyPath: AnyKeyPath) -> String? {
222222
return "value"
223223
case \LabeledStmtSyntax.label:
224224
return "label name"
225-
case \LayoutRequirementSyntax.typeIdentifier:
225+
case \LayoutRequirementSyntax.type:
226226
return "constrained type"
227227
case \LayoutRequirementSyntax.size:
228228
return "size"
@@ -302,9 +302,9 @@ private func childNameForDiagnostics(_ keyPath: AnyKeyPath) -> String? {
302302
return "condition"
303303
case \ReturnClauseSyntax.returnType:
304304
return "return type"
305-
case \SameTypeRequirementSyntax.leftTypeIdentifier:
305+
case \SameTypeRequirementSyntax.leftType:
306306
return "left-hand type"
307-
case \SameTypeRequirementSyntax.rightTypeIdentifier:
307+
case \SameTypeRequirementSyntax.rightType:
308308
return "right-hand type"
309309
case \StructDeclSyntax.attributes:
310310
return "attributes"

Sources/SwiftSyntax/generated/ChildNameForKeyPath.swift

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -749,20 +749,20 @@ public func childName(_ keyPath: AnyKeyPath) -> String? {
749749
return "trailingComma"
750750
case \ConditionElementSyntax.unexpectedAfterTrailingComma:
751751
return "unexpectedAfterTrailingComma"
752-
case \ConformanceRequirementSyntax.unexpectedBeforeLeftTypeIdentifier:
753-
return "unexpectedBeforeLeftTypeIdentifier"
754-
case \ConformanceRequirementSyntax.leftTypeIdentifier:
755-
return "leftTypeIdentifier"
756-
case \ConformanceRequirementSyntax.unexpectedBetweenLeftTypeIdentifierAndColon:
757-
return "unexpectedBetweenLeftTypeIdentifierAndColon"
752+
case \ConformanceRequirementSyntax.unexpectedBeforeLeftType:
753+
return "unexpectedBeforeLeftType"
754+
case \ConformanceRequirementSyntax.leftType:
755+
return "leftType"
756+
case \ConformanceRequirementSyntax.unexpectedBetweenLeftTypeAndColon:
757+
return "unexpectedBetweenLeftTypeAndColon"
758758
case \ConformanceRequirementSyntax.colon:
759759
return "colon"
760-
case \ConformanceRequirementSyntax.unexpectedBetweenColonAndRightTypeIdentifier:
761-
return "unexpectedBetweenColonAndRightTypeIdentifier"
762-
case \ConformanceRequirementSyntax.rightTypeIdentifier:
763-
return "rightTypeIdentifier"
764-
case \ConformanceRequirementSyntax.unexpectedAfterRightTypeIdentifier:
765-
return "unexpectedAfterRightTypeIdentifier"
760+
case \ConformanceRequirementSyntax.unexpectedBetweenColonAndRightType:
761+
return "unexpectedBetweenColonAndRightType"
762+
case \ConformanceRequirementSyntax.rightType:
763+
return "rightType"
764+
case \ConformanceRequirementSyntax.unexpectedAfterRightType:
765+
return "unexpectedAfterRightType"
766766
case \ConstrainedSugarTypeSyntax.unexpectedBeforeSomeOrAnySpecifier:
767767
return "unexpectedBeforeSomeOrAnySpecifier"
768768
case \ConstrainedSugarTypeSyntax.someOrAnySpecifier:
@@ -2005,12 +2005,12 @@ public func childName(_ keyPath: AnyKeyPath) -> String? {
20052005
return "statement"
20062006
case \LabeledStmtSyntax.unexpectedAfterStatement:
20072007
return "unexpectedAfterStatement"
2008-
case \LayoutRequirementSyntax.unexpectedBeforeTypeIdentifier:
2009-
return "unexpectedBeforeTypeIdentifier"
2010-
case \LayoutRequirementSyntax.typeIdentifier:
2011-
return "typeIdentifier"
2012-
case \LayoutRequirementSyntax.unexpectedBetweenTypeIdentifierAndColon:
2013-
return "unexpectedBetweenTypeIdentifierAndColon"
2008+
case \LayoutRequirementSyntax.unexpectedBeforeType:
2009+
return "unexpectedBeforeType"
2010+
case \LayoutRequirementSyntax.type:
2011+
return "type"
2012+
case \LayoutRequirementSyntax.unexpectedBetweenTypeAndColon:
2013+
return "unexpectedBetweenTypeAndColon"
20142014
case \LayoutRequirementSyntax.colon:
20152015
return "colon"
20162016
case \LayoutRequirementSyntax.unexpectedBetweenColonAndLayoutConstraint:
@@ -2813,20 +2813,20 @@ public func childName(_ keyPath: AnyKeyPath) -> String? {
28132813
return "expression"
28142814
case \ReturnStmtSyntax.unexpectedAfterExpression:
28152815
return "unexpectedAfterExpression"
2816-
case \SameTypeRequirementSyntax.unexpectedBeforeLeftTypeIdentifier:
2817-
return "unexpectedBeforeLeftTypeIdentifier"
2818-
case \SameTypeRequirementSyntax.leftTypeIdentifier:
2819-
return "leftTypeIdentifier"
2820-
case \SameTypeRequirementSyntax.unexpectedBetweenLeftTypeIdentifierAndEqual:
2821-
return "unexpectedBetweenLeftTypeIdentifierAndEqual"
2816+
case \SameTypeRequirementSyntax.unexpectedBeforeLeftType:
2817+
return "unexpectedBeforeLeftType"
2818+
case \SameTypeRequirementSyntax.leftType:
2819+
return "leftType"
2820+
case \SameTypeRequirementSyntax.unexpectedBetweenLeftTypeAndEqual:
2821+
return "unexpectedBetweenLeftTypeAndEqual"
28222822
case \SameTypeRequirementSyntax.equal:
28232823
return "equal"
2824-
case \SameTypeRequirementSyntax.unexpectedBetweenEqualAndRightTypeIdentifier:
2825-
return "unexpectedBetweenEqualAndRightTypeIdentifier"
2826-
case \SameTypeRequirementSyntax.rightTypeIdentifier:
2827-
return "rightTypeIdentifier"
2828-
case \SameTypeRequirementSyntax.unexpectedAfterRightTypeIdentifier:
2829-
return "unexpectedAfterRightTypeIdentifier"
2824+
case \SameTypeRequirementSyntax.unexpectedBetweenEqualAndRightType:
2825+
return "unexpectedBetweenEqualAndRightType"
2826+
case \SameTypeRequirementSyntax.rightType:
2827+
return "rightType"
2828+
case \SameTypeRequirementSyntax.unexpectedAfterRightType:
2829+
return "unexpectedAfterRightType"
28302830
case \SequenceExprSyntax.unexpectedBeforeElements:
28312831
return "unexpectedBeforeElements"
28322832
case \SequenceExprSyntax.elements:

0 commit comments

Comments
 (0)