mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-06-16 10:34:34 +00:00
Fixed wrapping bug when previous line contains comment
This commit is contained in:
@@ -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 ?? "")
|
||||
|
||||
@@ -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 })"
|
||||
|
||||
Reference in New Issue
Block a user