Skip to content

Commit

Permalink
Fix issue where organizeDeclarations rule would unexpectedly remove n…
Browse files Browse the repository at this point in the history
…on-mark comment (#1956)
  • Loading branch information
calda authored and nicklockwood committed Jan 19, 2025
1 parent 6efb862 commit d2f85de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Sources/Rules/OrganizeDeclarations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,7 @@ extension Formatter {
Array(Set([
// The user's specific category separator template
$0.markCommentBody(from: options.categoryMarkComment, with: options.organizationMode),
// Other common variants that we would want to replace with the correct variant
$0.markCommentBody(from: "%c", with: options.organizationMode),
// Always look for MARKs even if the user is using a different template
$0.markCommentBody(from: "MARK: %c", with: options.organizationMode),
]))
}.compactMap { $0 }
Expand Down
17 changes: 15 additions & 2 deletions Tests/Rules/OrganizeDeclarationsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1568,9 +1568,9 @@ class OrganizeDeclarationsTests: XCTestCase {
init() {}
// Public
// mark: Public
// - Public
// mark - Public
public func bar() {}
Expand Down Expand Up @@ -3593,4 +3593,17 @@ class OrganizeDeclarationsTests: XCTestCase {

testFormatting(for: input, output, rule: .organizeDeclarations, exclude: [.blankLinesAtStartOfScope])
}

func testPreservesUnrelatedComments() {
let input = """
enum Test {
/// Test Properties
static let foo = "foo"
static let bar = "bar"
static let baaz = "baaz"
}
"""

testFormatting(for: input, rule: .organizeDeclarations)
}
}

0 comments on commit d2f85de

Please sign in to comment.