Skip to content

Update based on recent changes to swift-syntax main branch. #431

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
Oct 19, 2022
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
14 changes: 13 additions & 1 deletion Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,9 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
}

override func visit(_ node: ObjectLiteralExprSyntax) -> SyntaxVisitorContinueKind {
// TODO: Remove this; it has been subsumed by `MacroExpansionDeclSyntax`. But that feature is
// still in flux and this node type is still present in the API, even though nothing in the
// parser currently creates it.
arrangeFunctionCallArgumentList(
node.arguments,
leftDelimiter: node.leftParen,
Expand All @@ -1237,6 +1240,15 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
return .visitChildren
}

override func visit(_ node: MacroExpansionDeclSyntax) -> SyntaxVisitorContinueKind {
arrangeFunctionCallArgumentList(
node.argumentList,
leftDelimiter: node.leftParen,
rightDelimiter: node.rightParen,
forcesBreakBeforeRightDelimiter: false)
return .visitChildren
}

override func visit(_ node: ParameterClauseSyntax) -> SyntaxVisitorContinueKind {
// Prioritize keeping ") throws -> <return_type>" together. We can only do this if the function
// has arguments.
Expand Down Expand Up @@ -1307,7 +1319,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
// Unlike other code blocks, where we may want a single statement to be laid out on the same
// line as a parent construct, the content of an `#if` block must always be on its own line;
// the newline token inserted at the end enforces this.
if let lastElemTok = node.elements.lastToken {
if let lastElemTok = node.elements?.lastToken {
after(lastElemTok, tokens: .break(breakKindClose, newlines: .soft), .close)
} else {
before(tokenToOpenWith.nextToken(viewMode: .all), tokens: .break(breakKindClose, newlines: .soft), .close)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftFormatRules/AlwaysUseLowerCamelCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public final class AlwaysUseLowerCamelCase: SyntaxLintRule {
if let ifConfigDecl = member.decl.as(IfConfigDeclSyntax.self) {
// Recurse into any conditional member lists and collect their test methods as well.
for clause in ifConfigDecl.clauses {
if let clauseMembers = clause.elements.as(MemberDeclListSyntax.self) {
if let clauseMembers = clause.elements?.as(MemberDeclListSyntax.self) {
collectTestMethods(from: clauseMembers, into: &set)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftFormatRules/FileScopedDeclarationPrivacy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public final class FileScopedDeclarationPrivacy: SyntaxFormatRule {
/// - Returns: A new `IfConfigDeclSyntax` that has possibly been rewritten.
private func rewrittenIfConfigDecl(_ ifConfigDecl: IfConfigDeclSyntax) -> IfConfigDeclSyntax {
let newClauses = ifConfigDecl.clauses.map { clause -> IfConfigClauseSyntax in
switch clause.elements.as(SyntaxEnum.self) {
case .codeBlockItemList(let codeBlockItemList):
switch clause.elements?.as(SyntaxEnum.self) {
case .codeBlockItemList(let codeBlockItemList)?:
return clause.withElements(Syntax(rewrittenCodeBlockItems(codeBlockItemList)))
default:
return clause
Expand Down