mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-05-17 10:30:35 +00:00
Fix incorrect replacement of && operator inside a ternary condition
This commit is contained in:
committed by
Cal Stephens
parent
fc3a2ccb10
commit
a962548ecf
@@ -35,7 +35,7 @@ public extension FormatRule {
|
||||
let endOfGroup = formatter.index(of: .delimiter(","), after: index) ?? endIndex
|
||||
var nextOpIndex = index
|
||||
while let next = formatter.index(of: .operator, after: nextOpIndex) {
|
||||
if formatter.tokens[next] == .operator("||", .infix) {
|
||||
if [.operator("||", .infix), .operator("?", .infix)].contains(formatter.tokens[next]) {
|
||||
index = endOfGroup
|
||||
continue outer
|
||||
}
|
||||
|
||||
@@ -134,6 +134,13 @@ final class AndOperatorTests: XCTestCase {
|
||||
testFormatting(for: input, rule: .andOperator)
|
||||
}
|
||||
|
||||
func testNoReplaceAndInTernaryCondition() {
|
||||
let input = """
|
||||
if foo && bar ? baz : quux {}
|
||||
"""
|
||||
testFormatting(for: input, rule: .andOperator)
|
||||
}
|
||||
|
||||
func testHandleAndAtStartOfLine() {
|
||||
let input = """
|
||||
if a == b
|
||||
|
||||
Reference in New Issue
Block a user