Skip to content

Commit 6f41221

Browse files
committed
Add documentation for local helper variables
1 parent a64d0ef commit 6f41221

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Sources/SwiftBasicFormat/BasicFormat.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ open class BasicFormat: SyntaxRewriter {
296296
let previousToken = self.previousToken ?? token.previousToken(viewMode: viewMode)
297297
let nextToken = token.nextToken(viewMode: viewMode)
298298

299+
/// In addition to existing trivia of `previousToken`, also considers
300+
/// `previousToken` as ending with whitespace if it and `token` should be
301+
/// separated by whitespace.
302+
/// It does not consider whether a newline should be added between
303+
/// `previousToken` and the `token` because that newline should be added to
304+
/// the next token's trailing trivia.
299305
lazy var previousTokenWillEndWithWhitespace: Bool = {
300306
guard let previousToken = previousToken else {
301307
return false
@@ -304,6 +310,8 @@ open class BasicFormat: SyntaxRewriter {
304310
|| (requiresWhitespace(between: previousToken, and: token) && isMutable(previousToken))
305311
}()
306312

313+
/// This method does not consider any posssible mutations to `previousToken`
314+
/// because newlines should be added to the next token's leading trivia.
307315
lazy var previousTokenWillEndWithNewline: Bool = {
308316
guard let previousToken = previousToken else {
309317
// Assume that the start of the tree is equivalent to a newline so we
@@ -325,6 +333,10 @@ open class BasicFormat: SyntaxRewriter {
325333
return previousToken.isStringSegmentWithLastCharacterBeingNewline
326334
}()
327335

336+
/// Also considers `nextToken` as starting with a whitespace if a newline
337+
/// should be added to it. It does not check whether `token` and `nextToken`
338+
/// should be separated by whitespace because the whitespace should be added
339+
/// to the `token`’s leading trivia.
328340
lazy var nextTokenWillStartWithWhitespace: Bool = {
329341
guard let nextToken = nextToken else {
330342
return false
@@ -333,6 +345,8 @@ open class BasicFormat: SyntaxRewriter {
333345
|| (requiresNewline(between: token, and: nextToken) && isMutable(nextToken))
334346
}()
335347

348+
/// Also considers `nextToken` as starting with a leading newline if `token`
349+
/// and `nextToken` should be separated by a newline.
336350
lazy var nextTokenWillStartWithNewline: Bool = {
337351
guard let nextToken = nextToken else {
338352
return false

0 commit comments

Comments
 (0)