Skip to content

Commit 05ee7e6

Browse files
committed
// swift-format-ignore-file shouldn't modify anything, even whitespace.
1 parent d73b790 commit 05ee7e6

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
15161516

15171517
override func visit(_ node: SourceFileSyntax) -> SyntaxVisitorContinueKind {
15181518
if shouldFormatterIgnore(file: node) {
1519-
appendFormatterIgnored(node: Syntax(node))
1519+
appendToken(.verbatim(Verbatim(text: "\(node)", indentingBehavior: .none)))
15201520
return .skipChildren
15211521
}
15221522
after(node.shebang, tokens: .break(.same, newlines: .soft))

Tests/SwiftFormatTests/PrettyPrint/IgnoreNodeTests.swift

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -318,36 +318,18 @@ final class IgnoreNodeTests: PrettyPrintTestCase {
318318
{
319319
var bazzle = 0 }
320320
"""
321+
assertPrettyPrintEqual(input: input, expected: input, linelength: 50)
322+
}
321323

322-
let expected =
324+
func testIgnoreWholeFileDoesNotTouchWhitespace() {
325+
let input =
323326
"""
324327
// swift-format-ignore-file
325-
import Zoo
326-
import Aoo
327-
import foo
328-
329-
struct Foo {
330-
private var baz: Bool {
331-
return foo +
332-
bar + // poorly placed comment
333-
false
334-
}
335-
336-
var a = true // line comment
337-
// aligned line comment
338-
var b = false // correct trailing comment
339-
340-
var c = 0 +
341-
1
342-
+ (2 + 3)
343-
}
344-
345-
class Bar
346-
{
347-
var bazzle = 0 }
328+
/// foo bar
329+
\u{0020}
330+
// baz
348331
"""
349-
350-
assertPrettyPrintEqual(input: input, expected: expected, linelength: 50)
332+
assertPrettyPrintEqual(input: input, expected: input, linelength: 100)
351333
}
352334

353335
func testIgnoreWholeFileInNestedNode() {

0 commit comments

Comments
 (0)