Skip to content

Commit 4091de2

Browse files
committed
Update swift-format for renamed children in SwiftSyntax
1 parent df5ad65 commit 4091de2

22 files changed

+169
-169
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 75 additions & 75 deletions
Large diffs are not rendered by default.

Sources/SwiftFormatRules/AllPublicDeclarationsHaveDocumentation.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public final class AllPublicDeclarationsHaveDocumentation: SyntaxLintRule {
4545
}
4646

4747
public override func visit(_ node: ClassDeclSyntax) -> SyntaxVisitorContinueKind {
48-
diagnoseMissingDocComment(DeclSyntax(node), name: node.identifier.text, modifiers: node.modifiers)
48+
diagnoseMissingDocComment(DeclSyntax(node), name: node.name.text, modifiers: node.modifiers)
4949
return .skipChildren
5050
}
5151

@@ -56,17 +56,17 @@ public final class AllPublicDeclarationsHaveDocumentation: SyntaxLintRule {
5656
}
5757

5858
public override func visit(_ node: StructDeclSyntax) -> SyntaxVisitorContinueKind {
59-
diagnoseMissingDocComment(DeclSyntax(node), name: node.identifier.text, modifiers: node.modifiers)
59+
diagnoseMissingDocComment(DeclSyntax(node), name: node.name.text, modifiers: node.modifiers)
6060
return .skipChildren
6161
}
6262

6363
public override func visit(_ node: ProtocolDeclSyntax) -> SyntaxVisitorContinueKind {
64-
diagnoseMissingDocComment(DeclSyntax(node), name: node.identifier.text, modifiers: node.modifiers)
64+
diagnoseMissingDocComment(DeclSyntax(node), name: node.name.text, modifiers: node.modifiers)
6565
return .skipChildren
6666
}
6767

6868
public override func visit(_ node: TypealiasDeclSyntax) -> SyntaxVisitorContinueKind {
69-
diagnoseMissingDocComment(DeclSyntax(node), name: node.identifier.text, modifiers: node.modifiers)
69+
diagnoseMissingDocComment(DeclSyntax(node), name: node.name.text, modifiers: node.modifiers)
7070
return .skipChildren
7171
}
7272

Sources/SwiftFormatRules/AlwaysUseLowerCamelCase.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ public final class AlwaysUseLowerCamelCase: SyntaxLintRule {
6767
}
6868

6969
public override func visit(_ node: ClosureSignatureSyntax) -> SyntaxVisitorContinueKind {
70-
if let input = node.input {
70+
if let input = node.parameterClause {
7171
if let closureParamList = input.as(ClosureParamListSyntax.self) {
7272
for param in closureParamList {
7373
diagnoseLowerCamelCaseViolations(
7474
param.name, allowUnderscores: false, description: identifierDescription(for: node))
7575
}
7676
} else if let parameterClause = input.as(ClosureParameterClauseSyntax.self) {
77-
for param in parameterClause.parameterList {
77+
for param in parameterClause.parameters {
7878
diagnoseLowerCamelCaseViolations(
7979
param.firstName, allowUnderscores: false, description: identifierDescription(for: node))
8080
if let secondName = param.secondName {
@@ -83,7 +83,7 @@ public final class AlwaysUseLowerCamelCase: SyntaxLintRule {
8383
}
8484
}
8585
} else if let parameterClause = input.as(EnumCaseParameterClauseSyntax.self) {
86-
for param in parameterClause.parameterList {
86+
for param in parameterClause.parameters {
8787
if let firstName = param.firstName {
8888
diagnoseLowerCamelCaseViolations(
8989
firstName, allowUnderscores: false, description: identifierDescription(for: node))
@@ -94,7 +94,7 @@ public final class AlwaysUseLowerCamelCase: SyntaxLintRule {
9494
}
9595
}
9696
} else if let parameterClause = input.as(ParameterClauseSyntax.self) {
97-
for param in parameterClause.parameterList {
97+
for param in parameterClause.parameters {
9898
diagnoseLowerCamelCaseViolations(
9999
param.firstName, allowUnderscores: false, description: identifierDescription(for: node))
100100
if let secondName = param.secondName {
@@ -119,9 +119,9 @@ public final class AlwaysUseLowerCamelCase: SyntaxLintRule {
119119
// underscores to separate phrases in very detailed test names.
120120
let allowUnderscores = testCaseFuncs.contains(node)
121121
diagnoseLowerCamelCaseViolations(
122-
node.identifier, allowUnderscores: allowUnderscores,
122+
node.name, allowUnderscores: allowUnderscores,
123123
description: identifierDescription(for: node))
124-
for param in node.signature.input.parameterList {
124+
for param in node.signature.parameterClause.parameters {
125125
// These identifiers aren't described using `identifierDescription(for:)` because no single
126126
// node can disambiguate the argument label from the parameter name.
127127
diagnoseLowerCamelCaseViolations(
@@ -136,7 +136,7 @@ public final class AlwaysUseLowerCamelCase: SyntaxLintRule {
136136

137137
public override func visit(_ node: EnumCaseElementSyntax) -> SyntaxVisitorContinueKind {
138138
diagnoseLowerCamelCaseViolations(
139-
node.identifier, allowUnderscores: false, description: identifierDescription(for: node))
139+
node.name, allowUnderscores: false, description: identifierDescription(for: node))
140140
return .skipChildren
141141
}
142142

@@ -157,9 +157,9 @@ public final class AlwaysUseLowerCamelCase: SyntaxLintRule {
157157
} else if let functionDecl = member.decl.as(FunctionDeclSyntax.self) {
158158
// Identify test methods using the same heuristics as XCTest: name starts with "test", has
159159
// no arguments, and returns a void type.
160-
if functionDecl.identifier.text.starts(with: "test")
161-
&& functionDecl.signature.input.parameterList.isEmpty
162-
&& (functionDecl.signature.output.map(\.isVoid) ?? true)
160+
if functionDecl.name.text.starts(with: "test")
161+
&& functionDecl.signature.parameterClause.parameters.isEmpty
162+
&& (functionDecl.signature.returnClause.map(\.isVoid) ?? true)
163163
{
164164
set.insert(functionDecl)
165165
}
@@ -189,9 +189,9 @@ fileprivate func identifierDescription<NodeType: SyntaxProtocol>(for node: NodeT
189189
case .enumCaseElement: return "enum case"
190190
case .functionDecl: return "function"
191191
case .optionalBindingCondition(let binding):
192-
return binding.bindingKeyword.tokenKind == .keyword(.var) ? "variable" : "constant"
192+
return binding.bindingSpecifier.tokenKind == .keyword(.var) ? "variable" : "constant"
193193
case .variableDecl(let variableDecl):
194-
return variableDecl.bindingKeyword.tokenKind == .keyword(.var) ? "variable" : "constant"
194+
return variableDecl.bindingSpecifier.tokenKind == .keyword(.var) ? "variable" : "constant"
195195
default:
196196
return "identifier"
197197
}
@@ -200,10 +200,10 @@ fileprivate func identifierDescription<NodeType: SyntaxProtocol>(for node: NodeT
200200
extension ReturnClauseSyntax {
201201
/// Whether this return clause specifies an explicit `Void` return type.
202202
fileprivate var isVoid: Bool {
203-
if let returnTypeIdentifier = returnType.as(SimpleTypeIdentifierSyntax.self) {
203+
if let returnTypeIdentifier = type.as(SimpleTypeIdentifierSyntax.self) {
204204
return returnTypeIdentifier.name.text == "Void"
205205
}
206-
if let returnTypeTuple = returnType.as(TupleTypeSyntax.self) {
206+
if let returnTypeTuple = type.as(TupleTypeSyntax.self) {
207207
return returnTypeTuple.elements.isEmpty
208208
}
209209
return false

Sources/SwiftFormatRules/AmbiguousTrailingClosureOverload.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ public final class AmbiguousTrailingClosureOverload: SyntaxLintRule {
2424
let decl = decls[0]
2525
diagnose(
2626
.ambiguousTrailingClosureOverload(decl.fullDeclName),
27-
on: decl.identifier,
27+
on: decl.name,
2828
notes: decls.dropFirst().map { decl in
2929
Finding.Note(
3030
message: .otherAmbiguousOverloadHere(decl.fullDeclName),
3131
location: Finding.Location(
32-
decl.identifier.startLocation(converter: self.context.sourceLocationConverter))
32+
decl.name.startLocation(converter: self.context.sourceLocationConverter))
3333
)
3434
})
3535
}
@@ -39,13 +39,13 @@ public final class AmbiguousTrailingClosureOverload: SyntaxLintRule {
3939
var overloads = [String: [FunctionDeclSyntax]]()
4040
var staticOverloads = [String: [FunctionDeclSyntax]]()
4141
for fn in functions {
42-
let params = fn.signature.input.parameterList
42+
let params = fn.signature.parameterClause.parameters
4343
guard let firstParam = params.firstAndOnly else { continue }
4444
guard firstParam.type.is(FunctionTypeSyntax.self) else { continue }
4545
if let mods = fn.modifiers, mods.has(modifier: "static") || mods.has(modifier: "class") {
46-
staticOverloads[fn.identifier.text, default: []].append(fn)
46+
staticOverloads[fn.name.text, default: []].append(fn)
4747
} else {
48-
overloads[fn.identifier.text, default: []].append(fn)
48+
overloads[fn.name.text, default: []].append(fn)
4949
}
5050
}
5151

Sources/SwiftFormatRules/DontRepeatTypeInStaticProperties.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ import SwiftSyntax
2323
public final class DontRepeatTypeInStaticProperties: SyntaxLintRule {
2424

2525
public override func visit(_ node: ClassDeclSyntax) -> SyntaxVisitorContinueKind {
26-
diagnoseStaticMembers(node.memberBlock.members, endingWith: node.identifier.text)
26+
diagnoseStaticMembers(node.memberBlock.members, endingWith: node.name.text)
2727
return .skipChildren
2828
}
2929

3030
public override func visit(_ node: EnumDeclSyntax) -> SyntaxVisitorContinueKind {
31-
diagnoseStaticMembers(node.memberBlock.members, endingWith: node.identifier.text)
31+
diagnoseStaticMembers(node.memberBlock.members, endingWith: node.name.text)
3232
return .skipChildren
3333
}
3434

3535
public override func visit(_ node: ProtocolDeclSyntax) -> SyntaxVisitorContinueKind {
36-
diagnoseStaticMembers(node.memberBlock.members, endingWith: node.identifier.text)
36+
diagnoseStaticMembers(node.memberBlock.members, endingWith: node.name.text)
3737
return .skipChildren
3838
}
3939

4040
public override func visit(_ node: StructDeclSyntax) -> SyntaxVisitorContinueKind {
41-
diagnoseStaticMembers(node.memberBlock.members, endingWith: node.identifier.text)
41+
diagnoseStaticMembers(node.memberBlock.members, endingWith: node.name.text)
4242
return .skipChildren
4343
}
4444

Sources/SwiftFormatRules/FullyIndirectEnum.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public final class FullyIndirectEnum: SyntaxFormatRule {
3131
return DeclSyntax(node)
3232
}
3333

34-
diagnose(.moveIndirectKeywordToEnumDecl(name: node.identifier.text), on: node.identifier)
34+
diagnose(.moveIndirectKeywordToEnumDecl(name: node.name.text), on: node.name)
3535

3636
// Removes 'indirect' keyword from cases, reformats
3737
let newMembers = enumMembers.map {

Sources/SwiftFormatRules/FunctionDeclSyntax+Convenience.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import SwiftSyntax
1515
extension FunctionDeclSyntax {
1616
/// Constructs a name for a function that includes parameter labels, i.e. `foo(_:bar:)`.
1717
var fullDeclName: String {
18-
let params = signature.input.parameterList.map { param in
18+
let params = signature.parameterClause.parameters.map { param in
1919
"\(param.firstName.text):"
2020
}
21-
return "\(identifier.text)(\(params.joined()))"
21+
return "\(name.text)(\(params.joined()))"
2222
}
2323
}

Sources/SwiftFormatRules/NeverForceUnwrap.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public final class NeverForceUnwrap: SyntaxLintRule {
4141
guard context.importsXCTest == .doesNotImportXCTest else { return .skipChildren }
4242
guard let questionOrExclamation = node.questionOrExclamationMark else { return .skipChildren }
4343
guard questionOrExclamation.tokenKind == .exclamationMark else { return .skipChildren }
44-
diagnose(.doNotForceCast(name: node.typeName.with(\.leadingTrivia, []).with(\.trailingTrivia, []).description), on: node)
44+
diagnose(.doNotForceCast(name: node.type.with(\.leadingTrivia, []).with(\.trailingTrivia, []).description), on: node)
4545
return .skipChildren
4646
}
4747
}

Sources/SwiftFormatRules/NoEmptyTrailingClosureParentheses.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import SwiftSyntax
2222
public final class NoEmptyTrailingClosureParentheses: SyntaxFormatRule {
2323

2424
public override func visit(_ node: FunctionCallExprSyntax) -> ExprSyntax {
25-
guard node.argumentList.count == 0 else { return super.visit(node) }
25+
guard node.arguments.count == 0 else { return super.visit(node) }
2626

2727
guard let trailingClosure = node.trailingClosure,
28-
node.argumentList.isEmpty && node.leftParen != nil else
28+
node.arguments.isEmpty && node.leftParen != nil else
2929
{
3030
return super.visit(node)
3131
}

Sources/SwiftFormatRules/NoLabelsInCasePatterns.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public final class NoLabelsInCasePatterns: SyntaxFormatRule {
3737

3838
// Search function call argument list for violations
3939
var newArgs: [TupleExprElementSyntax] = []
40-
for argument in funcCall.argumentList {
40+
for argument in funcCall.arguments {
4141
guard let label = argument.label else {
4242
newArgs.append(argument)
4343
continue
@@ -50,7 +50,7 @@ public final class NoLabelsInCasePatterns: SyntaxFormatRule {
5050
}
5151

5252
// Remove label if it's the same as the value identifier
53-
let name = valueBinding.valuePattern.with(\.leadingTrivia, []).with(\.trailingTrivia, []).description
53+
let name = valueBinding.pattern.with(\.leadingTrivia, []).with(\.trailingTrivia, []).description
5454
guard name == label.text else {
5555
newArgs.append(argument)
5656
continue
@@ -60,7 +60,7 @@ public final class NoLabelsInCasePatterns: SyntaxFormatRule {
6060
}
6161

6262
let newArgList = TupleExprElementListSyntax(newArgs)
63-
let newFuncCall = funcCall.with(\.argumentList, newArgList)
63+
let newFuncCall = funcCall.with(\.arguments, newArgList)
6464
let newExpPat = expPat.with(\.expression, ExprSyntax(newFuncCall))
6565
let newItem = item.with(\.pattern, PatternSyntax(newExpPat))
6666
newCaseItems.append(newItem)

Sources/SwiftFormatRules/NoLeadingUnderscores.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,27 @@ public final class NoLeadingUnderscores: SyntaxLintRule {
3232
public override class var isOptIn: Bool { return true }
3333

3434
public override func visit(_ node: AssociatedtypeDeclSyntax) -> SyntaxVisitorContinueKind {
35-
diagnoseIfNameStartsWithUnderscore(node.identifier)
35+
diagnoseIfNameStartsWithUnderscore(node.name)
3636
return .visitChildren
3737
}
3838

3939
public override func visit(_ node: ClassDeclSyntax) -> SyntaxVisitorContinueKind {
40-
diagnoseIfNameStartsWithUnderscore(node.identifier)
40+
diagnoseIfNameStartsWithUnderscore(node.name)
4141
return .visitChildren
4242
}
4343

4444
public override func visit(_ node: EnumCaseElementSyntax) -> SyntaxVisitorContinueKind {
45-
diagnoseIfNameStartsWithUnderscore(node.identifier)
45+
diagnoseIfNameStartsWithUnderscore(node.name)
4646
return .visitChildren
4747
}
4848

4949
public override func visit(_ node: EnumDeclSyntax) -> SyntaxVisitorContinueKind {
50-
diagnoseIfNameStartsWithUnderscore(node.identifier)
50+
diagnoseIfNameStartsWithUnderscore(node.name)
5151
return .visitChildren
5252
}
5353

5454
public override func visit(_ node: FunctionDeclSyntax) -> SyntaxVisitorContinueKind {
55-
diagnoseIfNameStartsWithUnderscore(node.identifier)
55+
diagnoseIfNameStartsWithUnderscore(node.name)
5656
return .visitChildren
5757
}
5858

@@ -93,22 +93,22 @@ public final class NoLeadingUnderscores: SyntaxLintRule {
9393
}
9494

9595
public override func visit(_ node: PrecedenceGroupDeclSyntax) -> SyntaxVisitorContinueKind {
96-
diagnoseIfNameStartsWithUnderscore(node.identifier)
96+
diagnoseIfNameStartsWithUnderscore(node.name)
9797
return .visitChildren
9898
}
9999

100100
public override func visit(_ node: ProtocolDeclSyntax) -> SyntaxVisitorContinueKind {
101-
diagnoseIfNameStartsWithUnderscore(node.identifier)
101+
diagnoseIfNameStartsWithUnderscore(node.name)
102102
return .visitChildren
103103
}
104104

105105
public override func visit(_ node: StructDeclSyntax) -> SyntaxVisitorContinueKind {
106-
diagnoseIfNameStartsWithUnderscore(node.identifier)
106+
diagnoseIfNameStartsWithUnderscore(node.name)
107107
return .visitChildren
108108
}
109109

110110
public override func visit(_ node: TypealiasDeclSyntax) -> SyntaxVisitorContinueKind {
111-
diagnoseIfNameStartsWithUnderscore(node.identifier)
111+
diagnoseIfNameStartsWithUnderscore(node.name)
112112
return .visitChildren
113113
}
114114

Sources/SwiftFormatRules/NoVoidReturnOnFunctionSignature.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public final class NoVoidReturnOnFunctionSignature: SyntaxFormatRule {
2424
/// it for closure signatures, because that may introduce an ambiguity when closure signatures
2525
/// are inferred.
2626
public override func visit(_ node: FunctionSignatureSyntax) -> FunctionSignatureSyntax {
27-
if let ret = node.output?.returnType.as(SimpleTypeIdentifierSyntax.self), ret.name.text == "Void" {
27+
if let ret = node.returnClause?.type.as(SimpleTypeIdentifierSyntax.self), ret.name.text == "Void" {
2828
diagnose(.removeRedundantReturn("Void"), on: ret)
29-
return node.with(\.output, nil)
29+
return node.with(\.returnClause, nil)
3030
}
31-
if let tup = node.output?.returnType.as(TupleTypeSyntax.self), tup.elements.isEmpty {
31+
if let tup = node.returnClause?.type.as(TupleTypeSyntax.self), tup.elements.isEmpty {
3232
diagnose(.removeRedundantReturn("()"), on: tup)
33-
return node.with(\.output, nil)
33+
return node.with(\.returnClause, nil)
3434
}
3535
return node
3636
}

Sources/SwiftFormatRules/OneCasePerLine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public final class OneCasePerLine: SyntaxFormatRule {
103103
if element.associatedValue != nil || element.rawValue != nil {
104104
// Once we reach one of these, we need to write out the ones we've collected so far, then
105105
// emit a separate case declaration with the associated/raw value element.
106-
diagnose(.moveAssociatedOrRawValueCase(name: element.identifier.text), on: element)
106+
diagnose(.moveAssociatedOrRawValueCase(name: element.name.text), on: element)
107107

108108
if let caseDeclForCollectedElements = collector.makeCaseDeclAndReset() {
109109
newMembers.append(member.with(\.decl, DeclSyntax(caseDeclForCollectedElements)))

Sources/SwiftFormatRules/OnlyOneTrailingClosureArgument.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SwiftSyntax
2020
public final class OnlyOneTrailingClosureArgument: SyntaxLintRule {
2121

2222
public override func visit(_ node: FunctionCallExprSyntax) -> SyntaxVisitorContinueKind {
23-
guard (node.argumentList.contains { $0.expression.is(ClosureExprSyntax.self) }) else {
23+
guard (node.arguments.contains { $0.expression.is(ClosureExprSyntax.self) }) else {
2424
return .skipChildren
2525
}
2626
guard node.trailingClosure != nil else { return .skipChildren }

Sources/SwiftFormatRules/OrderedImports.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ fileprivate class Line {
523523
{
524524
return .testableImport
525525
}
526-
if importDecl.importKind != nil {
526+
if importDecl.importKindSpecifier != nil {
527527
return .declImport
528528
}
529529
return .regularImport

0 commit comments

Comments
 (0)