Skip to content

Commit ea5f38d

Browse files
authored
Merge pull request #590 from StevenWong12/make_shebang_a_child_of_sourcefile_syntax
Make `shebang` a child of `SourceFileSyntax`
2 parents 8c8fcd0 + 94bec52 commit ea5f38d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
15191519
appendFormatterIgnored(node: Syntax(node))
15201520
return .skipChildren
15211521
}
1522+
after(node.shebang, tokens: .break(.same, newlines: .soft))
15221523
after(node.endOfFileToken, tokens: .break(.same, newlines: .soft))
15231524
return .visitChildren
15241525
}
@@ -2673,7 +2674,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
26732674
var verbatimText = ""
26742675
for piece in trailingTrivia[...lastIndex] {
26752676
switch piece {
2676-
case .shebang, .unexpectedText, .spaces, .tabs, .formfeeds, .verticalTabs:
2677+
case .unexpectedText, .spaces, .tabs, .formfeeds, .verticalTabs:
26772678
piece.write(to: &verbatimText)
26782679
default:
26792680
// The implementation of the lexer today ensures that newlines, carriage returns, and
@@ -3160,7 +3161,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
31603161
}
31613162
}
31623163

3163-
case .shebang(let text), .unexpectedText(let text):
3164+
case .unexpectedText(let text):
31643165
// Garbage text in leading trivia might be something meaningful that would be disruptive to
31653166
// throw away when formatting the file, like a hashbang line or Unicode byte-order marker at
31663167
// the beginning of a file, or source control conflict markers. Keep it as verbatim text so

Sources/SwiftFormatRules/ReturnVoidInsteadOfEmptyTuple.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ public final class ReturnVoidInsteadOfEmptyTuple: SyntaxFormatRule {
8888
private func hasNonWhitespaceTrivia(_ token: TokenSyntax, at position: TriviaPosition) -> Bool {
8989
for piece in position == .leading ? token.leadingTrivia : token.trailingTrivia {
9090
switch piece {
91-
case .blockComment, .docBlockComment, .docLineComment, .unexpectedText, .lineComment,
92-
.shebang:
91+
case .blockComment, .docBlockComment, .docLineComment, .unexpectedText, .lineComment:
9392
return true
9493
default:
9594
break

0 commit comments

Comments
 (0)