Skip to content
Merged
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: 7 additions & 7 deletions Sources/SwiftBasicFormat/BasicFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ open class BasicFormat: SyntaxRewriter {

/// This method does not consider any posssible mutations to `previousToken`
/// because newlines should be added to the next token's leading trivia.
lazy var previousTokenWillEndWithNewline: Bool = {
let previousTokenWillEndWithNewline: Bool = {
guard let previousToken = previousToken else {
// Assume that the start of the tree is equivalent to a newline so we
// don't add a leading newline to the file.
Expand All @@ -386,7 +386,7 @@ open class BasicFormat: SyntaxRewriter {
return previousToken.isStringSegmentWithLastCharacterBeingNewline
}()

lazy var previousTokenIsStringLiteralEndingInNewline: Bool = {
let previousTokenIsStringLiteralEndingInNewline: Bool = {
guard let previousToken = previousToken else {
// Assume that the start of the tree is equivalent to a newline so we
// don't add a leading newline to the file.
Expand All @@ -409,7 +409,7 @@ open class BasicFormat: SyntaxRewriter {

/// Also considers `nextToken` as starting with a leading newline if `token`
/// and `nextToken` should be separated by a newline.
lazy var nextTokenWillStartWithNewline: Bool = {
let nextTokenWillStartWithNewline: Bool = {
guard let nextToken = nextToken else {
return false
}
Expand All @@ -426,16 +426,16 @@ open class BasicFormat: SyntaxRewriter {
return false
}()

var leadingTrivia = token.leadingTrivia
var trailingTrivia = token.trailingTrivia

/// This token's trailing trivia + any spaces or tabs at the start of the
/// next token's leading trivia.
lazy var combinedTrailingTrivia: Trivia = {
let combinedTrailingTrivia: Trivia = {
let nextTokenLeadingWhitespace = nextToken?.leadingTrivia.prefix(while: { $0.isSpaceOrTab }) ?? []
return trailingTrivia + Trivia(pieces: nextTokenLeadingWhitespace)
}()

var leadingTrivia = token.leadingTrivia
var trailingTrivia = token.trailingTrivia

if requiresNewline(between: previousToken, and: token) {
// Add a leading newline if the token requires it unless
// - it already starts with a newline or
Expand Down