Skip to content

Commit 801d068

Browse files
authored
Merge pull request #115 from dylansturg/poor_formatter_formatting
Fix incorrect indentation free functions.
2 parents 0dc9228 + 3a56fdc commit 801d068

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

Sources/SwiftFormatPrettyPrint/TokenStreamCreator.swift

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2865,45 +2865,45 @@ extension Collection {
28652865
}
28662866

28672867
/// Returns whether the given trivia includes a directive to ignore formatting for the next node.
2868-
///
2869-
/// - Parameter trivia: Leading trivia for a node that the formatter supports ignoring.
2870-
private func isFormatterIgnorePresent(inTrivia trivia: Trivia) -> Bool {
2871-
func isFormatterIgnore(in commentText: String, prefix: String, suffix: String) -> Bool {
2872-
let trimmed =
2873-
commentText.dropFirst(prefix.count)
2874-
.dropLast(suffix.count)
2875-
.trimmingCharacters(in: .whitespaces)
2876-
return trimmed == "swift-format-ignore"
2877-
}
2878-
2879-
for piece in trivia {
2880-
switch piece {
2881-
case .lineComment(let text):
2882-
if isFormatterIgnore(in: text, prefix: "//", suffix: "") { return true }
2883-
break
2884-
case .blockComment(let text):
2885-
if isFormatterIgnore(in: text, prefix: "/*", suffix: "*/") { return true }
2886-
break
2887-
default:
2888-
break
2889-
}
2890-
}
2891-
return false
2892-
}
2893-
2894-
/// Returns whether the formatter should ignore the given node by printing it without changing the
2895-
/// node's internal text representation (i.e. print all text inside of the node as it was in the
2896-
/// original source).
2897-
///
2898-
/// - Note: The caller is responsible for ensuring that the given node is a type of node that can
2899-
/// be safely ignored.
2900-
///
2901-
/// - Parameter node: A node that can be safely ignored.
2902-
private func shouldFormatterIgnore(node: Syntax) -> Bool {
2903-
// Regardless of the level of nesting, if the ignore directive is present on the first token
2904-
// contained within the node then the entire node is eligible for ignoring.
2905-
if let firstTrivia = node.firstToken?.leadingTrivia {
2906-
return isFormatterIgnorePresent(inTrivia: firstTrivia)
2907-
}
2908-
return false
2909-
}
2868+
///
2869+
/// - Parameter trivia: Leading trivia for a node that the formatter supports ignoring.
2870+
private func isFormatterIgnorePresent(inTrivia trivia: Trivia) -> Bool {
2871+
func isFormatterIgnore(in commentText: String, prefix: String, suffix: String) -> Bool {
2872+
let trimmed =
2873+
commentText.dropFirst(prefix.count)
2874+
.dropLast(suffix.count)
2875+
.trimmingCharacters(in: .whitespaces)
2876+
return trimmed == "swift-format-ignore"
2877+
}
2878+
2879+
for piece in trivia {
2880+
switch piece {
2881+
case .lineComment(let text):
2882+
if isFormatterIgnore(in: text, prefix: "//", suffix: "") { return true }
2883+
break
2884+
case .blockComment(let text):
2885+
if isFormatterIgnore(in: text, prefix: "/*", suffix: "*/") { return true }
2886+
break
2887+
default:
2888+
break
2889+
}
2890+
}
2891+
return false
2892+
}
2893+
2894+
/// Returns whether the formatter should ignore the given node by printing it without changing the
2895+
/// node's internal text representation (i.e. print all text inside of the node as it was in the
2896+
/// original source).
2897+
///
2898+
/// - Note: The caller is responsible for ensuring that the given node is a type of node that can
2899+
/// be safely ignored.
2900+
///
2901+
/// - Parameter node: A node that can be safely ignored.
2902+
private func shouldFormatterIgnore(node: Syntax) -> Bool {
2903+
// Regardless of the level of nesting, if the ignore directive is present on the first token
2904+
// contained within the node then the entire node is eligible for ignoring.
2905+
if let firstTrivia = node.firstToken?.leadingTrivia {
2906+
return isFormatterIgnorePresent(inTrivia: firstTrivia)
2907+
}
2908+
return false
2909+
}

0 commit comments

Comments
 (0)