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
  • Loading branch information
calda committed Jan 3, 2025
1 parent 6db7324 commit e2da757
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 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
13 changes: 13 additions & 0 deletions Tests/Rules/OrganizeDeclarationsTests.swift
Original file line number Diff line number Diff line change
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 e2da757

Please sign in to comment.