-
Notifications
You must be signed in to change notification settings - Fork 441
Update swift syntax #1217
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
Update swift syntax #1217
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ open class BasicFormat: SyntaxRewriter { | |
Trivia(pieces: [.newlines(1), indentation]) | ||
} | ||
|
||
private var lastRewrittenToken: TokenSyntax? | ||
private var lastRewrittenToken: TokenSyntax? | ||
|
||
private var putNextTokenOnNewLine: Bool = false | ||
|
||
|
@@ -48,13 +48,13 @@ open class BasicFormat: SyntaxRewriter { | |
open override func visit(_ node: TokenSyntax) -> TokenSyntax { | ||
var leadingTrivia = node.leadingTrivia | ||
var trailingTrivia = node.trailingTrivia | ||
if requiresLeadingSpace(node) && leadingTrivia.isEmpty && lastRewrittenToken?.trailingTrivia.isEmpty != false { | ||
if requiresLeadingSpace(node) && leadingTrivia.isEmpty && lastRewrittenToken? .trailingTrivia.isEmpty != false { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😬 This seems like a regression. It’s fine now but it would be nice to fix this in BasicFormat for the future |
||
leadingTrivia += .space | ||
} | ||
if requiresTrailingSpace(node) && trailingTrivia.isEmpty { | ||
trailingTrivia += .space | ||
} | ||
if let keyPath = getKeyPath(Syntax(node)), requiresLeadingNewline(keyPath), !(leadingTrivia.first?.isNewline ?? false) { | ||
if let keyPath = getKeyPath(Syntax(node)), requiresLeadingNewline(keyPath), !(leadingTrivia.first? .isNewline ?? false) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We missed some cases here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
leadingTrivia = .newline + leadingTrivia | ||
} | ||
leadingTrivia = leadingTrivia.indented(indentation: indentation) | ||
|
@@ -136,7 +136,7 @@ open class BasicFormat: SyntaxRewriter { | |
} | ||
|
||
open func requiresLeadingSpace(_ token: TokenSyntax) -> Bool { | ||
switch (token.previousToken(viewMode: .sourceAccurate)?.tokenKind, token.tokenKind) { | ||
switch (token.previousToken(viewMode: .sourceAccurate)? .tokenKind, token.tokenKind) { | ||
case (.leftParen, .spacedBinaryOperator): | ||
return false | ||
default: | ||
|
@@ -164,10 +164,10 @@ open class BasicFormat: SyntaxRewriter { | |
|
||
open func requiresTrailingSpace(_ token: TokenSyntax) -> Bool { | ||
// Format `[:]` as-is. | ||
if token.tokenKind == .colon && token.parent?.kind == .dictionaryExpr { | ||
if token.tokenKind == .colon && token.parent? .kind == .dictionaryExpr { | ||
return false | ||
} | ||
switch (token.tokenKind, token.nextToken(viewMode: .sourceAccurate)?.tokenKind) { | ||
switch (token.tokenKind, token.nextToken(viewMode: .sourceAccurate)? .tokenKind) { | ||
case (.asKeyword, .exclamationMark), // Ensures there is not space in `as!` | ||
(.asKeyword, .postfixQuestionMark), // Ensures there is not space in `as?` | ||
(.exclamationMark, .leftParen), // Ensures there is not space in `myOptionalClosure!()` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we in basic format make if next token == nil return no trailing space