Skip to content

Replace deprecated code from swift-syntax #540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
before(node.firstToken(viewMode: .sourceAccurate), tokens: .printerControl(kind: .disableBreaking(allowDiscretionary: false)))

arrangeAttributeList(node.attributes)
after(node.importTok, tokens: .space)
after(node.importKeyword, tokens: .space)
after(node.importKind, tokens: .space)

after(node.lastToken(viewMode: .sourceAccurate), tokens: .printerControl(kind: .enableBreaking))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public final class ReturnVoidInsteadOfEmptyTuple: SyntaxFormatRule {
return super.visit(node)
}

// Make sure that function types nested in the argument list are also rewritten (for example,
// Make sure that function types nested in the parameter list are also rewritten (for example,
// `(Int -> ()) -> ()` should become `(Int -> Void) -> Void`).
let arguments = visit(node.arguments)
let parameters = visit(node.parameters)
let voidKeyword = makeVoidIdentifierType(toReplace: returnType)
var rewrittenNode = node
rewrittenNode.arguments = arguments
rewrittenNode.parameters = parameters
rewrittenNode.output.returnType = TypeSyntax(voidKeyword)
return TypeSyntax(rewrittenNode)
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftFormatRules/UseShorthandTypeNames.swift
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public final class UseShorthandTypeNames: SyntaxFormatRule {
case .functionType(let functionType):
let result = makeFunctionTypeExpression(
leftParen: functionType.leftParen,
argumentTypes: functionType.arguments,
parameters: functionType.parameters,
rightParen: functionType.rightParen,
effectSpecifiers: functionType.effectSpecifiers,
arrow: functionType.output.arrow,
Expand Down Expand Up @@ -458,22 +458,22 @@ public final class UseShorthandTypeNames: SyntaxFormatRule {

private func makeFunctionTypeExpression(
leftParen: TokenSyntax,
argumentTypes: TupleTypeElementListSyntax,
parameters: TupleTypeElementListSyntax,
rightParen: TokenSyntax,
effectSpecifiers: TypeEffectSpecifiersSyntax?,
arrow: TokenSyntax,
returnType: TypeSyntax
) -> SequenceExprSyntax? {
guard
let argumentTypeExprs = expressionRepresentation(of: argumentTypes),
let parameterExprs = expressionRepresentation(of: parameters),
let returnTypeExpr = expressionRepresentation(of: returnType)
else {
return nil
}

let tupleExpr = TupleExprSyntax(
leftParen: leftParen,
elements: argumentTypeExprs,
elements: parameterExprs,
rightParen: rightParen)
let arrowExpr = ArrowExprSyntax(
effectSpecifiers: effectSpecifiers,
Expand Down