Skip to content

Commit 8b61a40

Browse files
committed
Add documentation for local helper variables
1 parent bbcbd57 commit 8b61a40

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
@@ -295,6 +295,12 @@ open class BasicFormat: SyntaxRewriter {
295295
let previousToken = self.previousToken ?? token.previousToken(viewMode: viewMode)
296296
let nextToken = token.nextToken(viewMode: viewMode)
297297

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

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

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

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

0 commit comments

Comments
 (0)