Skip to content

Commit

Permalink
Fix false positive wrap message for blank lines
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Nov 23, 2022
1 parent 0080d0f commit 7f71a18
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/FormattingHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ extension Formatter {
linebreakIndex = index + 1
}
if !isCommentedCode(at: linebreakIndex + 1) {
if tokens[linebreakIndex].isLinebreak, !options.truncateBlankLines ||
next(.nonSpace, after: linebreakIndex).map({ !$0.isLinebreak }) ?? false
if tokens[linebreakIndex].isLinebreak,
next(.nonSpace, after: linebreakIndex).map({ !$0.isLinebreak }) ?? false
{
insertSpace(indent + options.indent, at: linebreakIndex + 1)
} else if !allowGrouping || (maxWidth > 0 &&
Expand Down
13 changes: 13 additions & 0 deletions Tests/RulesTests+Wrapping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,19 @@ class WrappingTests: RulesTests {
testFormatting(for: input, output, rule: FormatRules.wrap, options: options)
}

func testErrorNotReportedOnBlankLineAfterWrap() throws {
let input = """
[
abagdiasiudbaisndoanosdasdasdasdasdnaosnooanso(),
bar(),
]
"""
let options = FormatOptions(truncateBlankLines: false, maxWidth: 40)
let changes = try lint(input, rules: [FormatRules.wrap, FormatRules.indent], options: options)
XCTAssertEqual(changes, [.init(line: 2, rule: FormatRules.wrap, filePath: nil)])
}

// MARK: - wrapArguments

func testIndentFirstElementWhenApplyingWrap() {
Expand Down

0 comments on commit 7f71a18

Please sign in to comment.