Skip to content

Commit 9e4caaa

Browse files
authored
Fix blankLinesAroundMark not ignoring trailing comments at start of scope (#2203)
1 parent 44a23ee commit 9e4caaa

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Sources/Rules/BlankLinesAroundMark.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public extension FormatRule {
2828
}
2929
if formatter.options.insertBlankLines,
3030
let lastIndex = formatter.index(of: .linebreak, before: startIndex),
31-
let lastToken = formatter.last(.nonSpace, before: lastIndex),
31+
let lastToken = formatter.last(.nonSpaceOrComment, before: lastIndex),
3232
!lastToken.isLinebreak, lastToken != .startOfScope("{")
3333
{
3434
formatter.insertLinebreak(at: lastIndex)

Tests/Rules/BlankLinesAroundMarkTests.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ class BlankLinesAroundMarkTests: XCTestCase {
7474
testFormatting(for: input, rule: .blankLinesAroundMark)
7575
}
7676

77+
func testNoInsertBlankLineBeforeMarkAtStartOfScopeWithTrailingComment() {
78+
let input = """
79+
struct Foo { // some comment here
80+
// MARK: bar
81+
82+
let string: String
83+
}
84+
"""
85+
testFormatting(for: input, rule: .blankLinesAroundMark)
86+
}
87+
7788
func testNoInsertBlankLineAfterMarkAtEndOfScope() {
7889
let input = """
7990
do {

0 commit comments

Comments
 (0)