Skip to content

Commit

Permalink
Fix issue where --beforemarks unexpectedly checked function bodies fo…
Browse files Browse the repository at this point in the history
…r matching keywords
  • Loading branch information
calda committed Oct 24, 2024
1 parent 5ab6cec commit 86797ad
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
4 changes: 0 additions & 4 deletions Sources/DeclarationHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,6 @@ extension Declaration {
return .beforeMarks
}

for token in declarationParser.tokens {
if beforeMarks.contains(token.string) { return .beforeMarks }
}

let isStaticDeclaration = declarationParser.index(
of: .keyword("static"),
before: declarationTypeTokenIndex
Expand Down
46 changes: 46 additions & 0 deletions Tests/Rules/OrganizeDeclarationsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3482,4 +3482,50 @@ class OrganizeDeclarationsTests: XCTestCase {
rule: .organizeDeclarations
)
}

func testIssue1907() {
let input = """
public final class Test: ObservableObject {
var someProperty: Int? = 0
// MARK: - Public -
public func somePublicFunction() {
print("Hello")
print("Hello")
print("Hello")
print("Hello")
print("Hello")
}
// MARK: - Internal -
func someInternalFunction() {
guard let someProperty else {
return
}
print("Hello")
print("Hello")
print("Hello")
print("Hello")
print("Hello")
}
// MARK: - Private -
private func somePrivateFunction() {
print("Hello")
print("Hello")
}
}
"""

let options = FormatOptions(
categoryMarkComment: "MARK: - %c -",
beforeMarks: ["class", "let", "var"]
)

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

0 comments on commit 86797ad

Please sign in to comment.