mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-05-17 10:30:35 +00:00
Fix unsafe keyword dot-spacing edge case (#2513)
This commit is contained in:
@@ -63,6 +63,8 @@ public extension FormatRule {
|
||||
switch formatter.tokens[prevIndex] {
|
||||
case .operator(_, .infix), .startOfScope:
|
||||
return
|
||||
case let token where [.identifier("unsafe")].contains(token):
|
||||
return // `unsafe` is contextual, so leave existing spacing unchanged.
|
||||
case let token where token.isUnwrapOperator:
|
||||
if let prevToken = formatter.last(.nonSpace, before: prevIndex),
|
||||
[.keyword("as"), .keyword("try")].contains(prevToken)
|
||||
|
||||
@@ -54,6 +54,20 @@ final class SpaceAroundOperatorsTests: XCTestCase {
|
||||
testFormatting(for: input, rule: .spaceAroundOperators)
|
||||
}
|
||||
|
||||
func testSpacePreservedBetweenUnsafeAndDot() {
|
||||
let input = """
|
||||
unsafe .foo
|
||||
"""
|
||||
testFormatting(for: input, rule: .spaceAroundOperators)
|
||||
}
|
||||
|
||||
func testNoSpaceAddedBetweenUnsafeAndDot() {
|
||||
let input = """
|
||||
unsafe.foo
|
||||
"""
|
||||
testFormatting(for: input, rule: .spaceAroundOperators)
|
||||
}
|
||||
|
||||
func testSpaceBetweenOptionalAndDefaultValueInFunction() {
|
||||
let input = """
|
||||
func foo(bar _: String?=nil) {}
|
||||
|
||||
Reference in New Issue
Block a user