From f5dee598270e803dad503dc3743276ea005ae6dd Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Tue, 23 Aug 2016 18:10:49 +0100 Subject: [PATCH] Fixed wrapping bug when previous line contains comment --- SwiftFormat/Formatter.swift | 2 +- SwiftFormatTests/FormatterTests.swift | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/SwiftFormat/Formatter.swift b/SwiftFormat/Formatter.swift index ac1982ef..eeb78d70 100644 --- a/SwiftFormat/Formatter.swift +++ b/SwiftFormat/Formatter.swift @@ -824,7 +824,7 @@ public func indent(formatter: Formatter) { } // Indent each new line if token.type == .Linebreak { - linewrapped = !tokenIsEndOfStatement(lastNonWhitespaceIndex) + linewrapped = !tokenIsEndOfStatement(lastNonWhitespaceOrLinebreakIndex) if linewrapped && lineIndex == scopeStartLineIndexes.last { indentStack.popLast() indentStack.append(indentStack.last ?? "") diff --git a/SwiftFormatTests/FormatterTests.swift b/SwiftFormatTests/FormatterTests.swift index a132c0f1..166e299f 100644 --- a/SwiftFormatTests/FormatterTests.swift +++ b/SwiftFormatTests/FormatterTests.swift @@ -682,6 +682,12 @@ class FormatterTests: XCTestCase { XCTAssertEqual(format(input, rules: [indent]), output) } + func testWrappedLinesWithComments() { + let input = "let foo = bar ||\n//baz||\nquux" + let output = "let foo = bar ||\n //baz||\n quux" + XCTAssertEqual(format(input, rules: [indent]), output) + } + // MARK: indent comments func testCommentIndenting() { @@ -741,7 +747,7 @@ class FormatterTests: XCTestCase { let output = "func foo() { /* comment/ncomment */\n statement\n}" XCTAssertEqual(format(input, rules: [knrBraces]), output) } - + func testExtraSpaceNotAddedBeforeBrace() { let input = "foo({ bar })" let output = "foo({ bar })"