Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where organizeDeclarations rule would unexpectedly remove non-mark comment #1956

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading