Skip to content

Commit 84af4c8

Browse files
authored
Merge pull request #847 from ahoppen/ahoppen/lowercase-diagnostics
Lowercase diagnostic and Fix-It messages and remove "after <previous token>" clause from missing node diagnostics
2 parents 8a4fa32 + eeba238 commit 84af4c8

File tree

8 files changed

+173
-180
lines changed

8 files changed

+173
-180
lines changed

Sources/SwiftParser/Diagnostics/MissingNodesError.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@ public struct MissingNodesError: ParserError {
128128
}
129129
}
130130

131-
// The after clause only provides value if the first missing node is not a token.
132-
// TODO: Revisit whether we want to have this clause at all.
133-
if !firstMissingNode.is(TokenSyntax.self) {
134-
if let previousToken = firstMissingNode.previousToken(viewMode: .fixedUp), previousToken.presence == .present {
135-
return "after '\(previousToken.text)'"
136-
}
137-
}
138131
return nil
139132
}
140133

@@ -176,7 +169,7 @@ public struct MissingNodesError: ParserError {
176169
}
177170

178171
public var message: String {
179-
var message = "Expected \(missingNodesDescription(missingNodes: missingNodes, commonParent: commonParent))"
172+
var message = "expected \(missingNodesDescription(missingNodes: missingNodes, commonParent: commonParent))"
180173
if let afterClause = afterClause {
181174
message += " \(afterClause)"
182175
}

Sources/SwiftParser/Diagnostics/ParserDiagnosticMessages.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public extension ParserFixIt {
5353
/// Please order the cases in this enum alphabetically by case name.
5454
public enum StaticParserError: String, DiagnosticMessage {
5555
case cStyleForLoop = "C-style for statement has been removed in Swift 3"
56-
case missingColonInTernaryExprDiagnostic = "Expected ':' after '? ...' in ternary expression"
57-
case missingFunctionParameterClause = "Expected argument list in function declaration"
56+
case missingColonInTernaryExprDiagnostic = "expected ':' after '? ...' in ternary expression"
57+
case missingFunctionParameterClause = "expected argument list in function declaration"
5858
case throwsInReturnPosition = "'throws' may only occur before '->'"
5959

6060
public var message: String { self.rawValue }
@@ -73,9 +73,9 @@ public struct ExtaneousCodeAtTopLevel: ParserError {
7373

7474
public var message: String {
7575
if let shortContent = extraneousCode.contentForDiagnosticsIfShortSingleLine {
76-
return "Extraneous '\(shortContent)' at top level"
76+
return "extraneous '\(shortContent)' at top level"
7777
} else {
78-
return "Extraneous code at top level"
78+
return "extraneous code at top level"
7979
}
8080
}
8181
}
@@ -98,15 +98,15 @@ public struct MissingAttributeArgument: ParserError {
9898
public let attributeName: TokenSyntax
9999

100100
public var message: String {
101-
return "Expected argument for '@\(attributeName)' attribute"
101+
return "expected argument for '@\(attributeName)' attribute"
102102
}
103103
}
104104

105105
public struct UnexpectedNodesError: ParserError {
106106
public let unexpectedNodes: UnexpectedNodesSyntax
107107

108108
public var message: String {
109-
var message = "Unexpected text"
109+
var message = "unexpected text"
110110
if let shortContent = unexpectedNodes.contentForDiagnosticsIfShortSingleLine {
111111
message += " '\(shortContent)'"
112112
}
@@ -124,8 +124,8 @@ public struct UnexpectedNodesError: ParserError {
124124
// MARK: - Fix-Its (please sort alphabetically)
125125

126126
public enum StaticParserFixIt: String, FixItMessage {
127-
case insertAttributeArguments = "Insert attribute argument"
128-
case moveThrowBeforeArrow = "Move 'throws' before '->'"
127+
case insertAttributeArguments = "insert attribute argument"
128+
case moveThrowBeforeArrow = "move 'throws' before '->'"
129129

130130
public var message: String { self.rawValue }
131131

Tests/SwiftParserTest/Attributes.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ final class AttributeTests: XCTestCase {
1111
}
1212
""",
1313
diagnostics: [
14-
DiagnosticSpec(message: "Expected argument for '@_dynamicReplacement' attribute", fixIts: ["Insert attribute argument"]),
15-
DiagnosticSpec(message: "Expected ')' to end attribute", fixIts: ["Insert ')'"]),
14+
DiagnosticSpec(message: "expected argument for '@_dynamicReplacement' attribute", fixIts: ["insert attribute argument"]),
15+
DiagnosticSpec(message: "expected ')' to end attribute", fixIts: ["Insert ')'"]),
1616
],
1717
fixedSource: """
1818
@_dynamicReplacement(for: <#identifier#>)
@@ -30,9 +30,9 @@ final class AttributeTests: XCTestCase {
3030
}
3131
""",
3232
diagnostics: [
33-
DiagnosticSpec(locationMarker: "DIAG_1", message: "Expected ':' and parameters in '@differentiable' argument", fixIts: ["Insert ':' and parameters"]),
34-
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '=' and right-hand type in same type requirement", fixIts: ["Insert '=' and right-hand type"]),
35-
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected ')' to end attribute", fixIts: ["Insert ')'"]),
33+
DiagnosticSpec(locationMarker: "DIAG_1", message: "expected ':' and parameters in '@differentiable' argument", fixIts: ["Insert ':' and parameters"]),
34+
DiagnosticSpec(locationMarker: "DIAG_2", message: "expected '=' and right-hand type in same type requirement", fixIts: ["Insert '=' and right-hand type"]),
35+
DiagnosticSpec(locationMarker: "DIAG_2", message: "expected ')' to end attribute", fixIts: ["Insert ')'"]),
3636
],
3737
fixedSource: """
3838
@differentiable(reverse wrt: <#syntax#>,where T = <#type#>)
@@ -48,9 +48,9 @@ final class AttributeTests: XCTestCase {
4848
@_specialize(e#^DIAG^#
4949
""",
5050
diagnostics: [
51-
DiagnosticSpec(message: "Expected ':' in attribute argument"),
52-
DiagnosticSpec(message: "Expected ')' to end attribute"),
53-
DiagnosticSpec(message: "Expected declaration after attribute"),
51+
DiagnosticSpec(message: "expected ':' in attribute argument"),
52+
DiagnosticSpec(message: "expected ')' to end attribute"),
53+
DiagnosticSpec(message: "expected declaration after attribute"),
5454
]
5555
)
5656
}
@@ -61,9 +61,9 @@ final class AttributeTests: XCTestCase {
6161
@_specialize(e#^DIAG_1^#, exported#^DIAG_2^#)#^DIAG_3^#
6262
""",
6363
diagnostics: [
64-
DiagnosticSpec(locationMarker: "DIAG_1", message: "Expected ':' in attribute argument"),
65-
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected ': false' in attribute argument"),
66-
DiagnosticSpec(locationMarker: "DIAG_3", message: "Expected declaration after attribute"),
64+
DiagnosticSpec(locationMarker: "DIAG_1", message: "expected ':' in attribute argument"),
65+
DiagnosticSpec(locationMarker: "DIAG_2", message: "expected ': false' in attribute argument"),
66+
DiagnosticSpec(locationMarker: "DIAG_3", message: "expected declaration after attribute"),
6767
]
6868
)
6969
}
@@ -231,7 +231,7 @@ final class AttributeTests: XCTestCase {
231231
func testMissingDeclarationAfterAttributes() {
232232
AssertParse(
233233
"@resultBuilder#^DIAG^#",
234-
diagnostics: [DiagnosticSpec(message: "Expected declaration after attribute")],
234+
diagnostics: [DiagnosticSpec(message: "expected declaration after attribute")],
235235
fixedSource: """
236236
@resultBuilder
237237
<#declaration#>

0 commit comments

Comments
 (0)