Skip to content

Commit 3dd7d5e

Browse files
committed
Remove leading newline above header in source file syntax
1 parent 369377a commit 3dd7d5e

22 files changed

+7
-43
lines changed

CodeGeneration/Sources/Utils/CodeGenerationFormat.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class CodeGenerationFormat: BasicFormat {
3636
}
3737

3838
public override func visit(_ node: CodeBlockItemSyntax) -> CodeBlockItemSyntax {
39-
if node.parent?.parent?.is(SourceFileSyntax.self) == true, !node.item.is(ImportDeclSyntax.self) {
39+
if node.parent?.parent?.is(SourceFileSyntax.self) == true, !shouldBeSeparatedByTwoNewlines(node: node) {
4040
let formatted = super.visit(node)
4141
return ensuringTwoLeadingNewlines(node: formatted)
4242
} else {
@@ -85,6 +85,12 @@ public class CodeGenerationFormat: BasicFormat {
8585

8686
// MARK: - Private
8787

88+
private func shouldBeSeparatedByTwoNewlines(node: CodeBlockItemSyntax) -> Bool {
89+
// First item in the `CodeBlockItemListSyntax` don't need a newline or identation if the parent is a `SourceFileSyntax`.
90+
// We want to group imports so newline between them should be omitted
91+
return node.parent?.as(CodeBlockItemListSyntax.self)?.first == node || node.item.is(ImportDeclSyntax.self)
92+
}
93+
8894
private func ensuringTwoLeadingNewlines<NodeType: SyntaxProtocol>(node: NodeType) -> NodeType {
8995
if node.leadingTrivia?.first?.isNewline ?? false {
9096
return node.with(\.leadingTrivia, indentedNewline + (node.leadingTrivia ?? []))

Sources/SwiftSyntax/generated/Keyword.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/Misc.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/SyntaxAnyVisitor.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/SyntaxBaseNodes.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/SyntaxCollections.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/SyntaxEnum.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/SyntaxKind.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/SyntaxRewriter.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/SyntaxTraits.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/SyntaxTransform.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/SyntaxVisitor.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/TokenKind.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/Tokens.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/Trivia.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/raw/RawSyntaxNodes.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxDeclNodes.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxExprNodes.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxNodes.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxPatternNodes.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxStmtNodes.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

Sources/SwiftSyntax/generated/syntaxNodes/SyntaxTypeNodes.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
//// Automatically Generated by generate-swiftsyntax
42
//// Do Not Edit Directly!
53
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)