Skip to content

Commit 0557eac

Browse files
committed
Fix swift-format In Response to SwiftSyntax Changes
1 parent f30e81e commit 0557eac

File tree

5 files changed

+29
-17
lines changed

5 files changed

+29
-17
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,21 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
155155
Syntax(node),
156156
attributes: node.attributes,
157157
modifiers: node.modifiers,
158-
typeKeyword: node.classOrActorKeyword,
158+
typeKeyword: node.classKeyword,
159+
identifier: node.identifier,
160+
genericParameterClause: node.genericParameterClause,
161+
inheritanceClause: node.inheritanceClause,
162+
genericWhereClause: node.genericWhereClause,
163+
members: node.members)
164+
return .visitChildren
165+
}
166+
167+
override func visit(_ node: ActorDeclSyntax) -> SyntaxVisitorContinueKind {
168+
arrangeTypeDeclBlock(
169+
Syntax(node),
170+
attributes: node.attributes,
171+
modifiers: node.modifiers,
172+
typeKeyword: node.actorKeyword,
159173
identifier: node.identifier,
160174
genericParameterClause: node.genericParameterClause,
161175
inheritanceClause: node.inheritanceClause,
@@ -305,21 +319,21 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
305319
}
306320

307321
override func visit(_ node: InitializerDeclSyntax) -> SyntaxVisitorContinueKind {
308-
let hasArguments = !node.parameters.parameterList.isEmpty
322+
let hasArguments = !node.signature.input.parameterList.isEmpty
309323

310-
arrangeParameterClause(node.parameters, forcesBreakBeforeRightParen: node.body != nil)
324+
arrangeParameterClause(node.signature.input, forcesBreakBeforeRightParen: node.body != nil)
311325

312326
// Prioritize keeping "<modifiers> init<punctuation>" together.
313327
let firstTokenAfterAttributes = node.modifiers?.firstToken ?? node.initKeyword
314328
before(firstTokenAfterAttributes, tokens: .open)
315329

316330
if hasArguments || node.genericParameterClause != nil {
317-
after(node.parameters.leftParen, tokens: .close)
331+
after(node.signature.input.leftParen, tokens: .close)
318332
} else {
319-
after(node.parameters.rightParen, tokens: .close)
333+
after(node.signature.input.rightParen, tokens: .close)
320334
}
321335

322-
before(node.throwsOrRethrowsKeyword, tokens: .break)
336+
before(node.signature.throwsOrRethrowsKeyword, tokens: .break)
323337

324338
arrangeFunctionLikeDecl(
325339
Syntax(node),

Sources/SwiftFormatRules/FullyIndirectEnum.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ public final class FullyIndirectEnum: SyntaxFormatRule {
6868

6969
let newModifier = SyntaxFactory.makeDeclModifier(
7070
name: SyntaxFactory.makeIdentifier(
71-
"indirect", leadingTrivia: leadingTrivia, trailingTrivia: .spaces(1)), detailLeftParen: nil,
72-
detail: nil, detailRightParen: nil)
71+
"indirect", leadingTrivia: leadingTrivia, trailingTrivia: .spaces(1)), detail: nil)
7372

7473
let newMemberBlock = node.members.withMembers(SyntaxFactory.makeMemberDeclList(newMembers))
7574
return DeclSyntax(newEnumDecl.addModifier(newModifier).withMembers(newMemberBlock))

Sources/SwiftFormatRules/ModifierListSyntax+Convenience.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extension ModifierListSyntax {
5050
func createModifierToken(name: String) -> DeclModifierSyntax {
5151
let id = SyntaxFactory.makeIdentifier(name, trailingTrivia: .spaces(1))
5252
let newModifier = SyntaxFactory.makeDeclModifier(
53-
name: id, detailLeftParen: nil, detail: nil, detailRightParen: nil)
53+
name: id, detail: nil)
5454
return newModifier
5555
}
5656

Sources/SwiftFormatRules/UseSynthesizedInitializer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public final class UseSynthesizedInitializer: SyntaxLintRule {
4040
// Collect any possible redundant initializers into a list
4141
} else if let initDecl = member.as(InitializerDeclSyntax.self) {
4242
guard initDecl.optionalMark == nil else { continue }
43-
guard initDecl.throwsOrRethrowsKeyword == nil else { continue }
43+
guard initDecl.signature.throwsOrRethrowsKeyword == nil else { continue }
4444
initializers.append(initDecl)
4545
}
4646
}
@@ -51,7 +51,7 @@ public final class UseSynthesizedInitializer: SyntaxLintRule {
5151
for initializer in initializers {
5252
guard
5353
matchesPropertyList(
54-
parameters: initializer.parameters.parameterList,
54+
parameters: initializer.signature.input.parameterList,
5555
properties: storedProperties)
5656
else { continue }
5757
guard

Sources/SwiftFormatRules/ValidateDocumentationComments.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,19 @@ public final class ValidateDocumentationComments: SyntaxLintRule {
2929

3030
public override func visit(_ node: InitializerDeclSyntax) -> SyntaxVisitorContinueKind {
3131
return checkFunctionLikeDocumentation(
32-
DeclSyntax(node), name: "init", parameters: node.parameters.parameterList, throwsOrRethrowsKeyword: node.throwsOrRethrowsKeyword)
32+
DeclSyntax(node), name: "init", signature: node.signature)
3333
}
3434

3535
public override func visit(_ node: FunctionDeclSyntax) -> SyntaxVisitorContinueKind {
3636
return checkFunctionLikeDocumentation(
37-
DeclSyntax(node), name: node.identifier.text, parameters: node.signature.input.parameterList, throwsOrRethrowsKeyword: node.signature.throwsOrRethrowsKeyword,
37+
DeclSyntax(node), name: node.identifier.text, signature: node.signature,
3838
returnClause: node.signature.output)
3939
}
4040

4141
private func checkFunctionLikeDocumentation(
4242
_ node: DeclSyntax,
4343
name: String,
44-
parameters: FunctionParameterListSyntax,
45-
throwsOrRethrowsKeyword: TokenSyntax?,
44+
signature: FunctionSignatureSyntax,
4645
returnClause: ReturnClauseSyntax? = nil
4746
) -> SyntaxVisitorContinueKind {
4847
guard let declComment = node.docComment else { return .skipChildren }
@@ -64,10 +63,10 @@ public final class ValidateDocumentationComments: SyntaxLintRule {
6463
}
6564

6665
validateThrows(
67-
throwsOrRethrowsKeyword, name: name, throwsDesc: commentInfo.throwsDescription, node: node)
66+
signature.throwsOrRethrowsKeyword, name: name, throwsDesc: commentInfo.throwsDescription, node: node)
6867
validateReturn(
6968
returnClause, name: name, returnDesc: commentInfo.returnsDescription, node: node)
70-
let funcParameters = funcParametersIdentifiers(in: parameters)
69+
let funcParameters = funcParametersIdentifiers(in: signature.input.parameterList)
7170

7271
// If the documentation of the parameters is wrong 'docCommentInfo' won't
7372
// parse the parameters correctly. First the documentation has to be fix

0 commit comments

Comments
 (0)