mirror of
https://github.com/nicklockwood/SwiftFormat.git
synced 2026-06-16 10:34:34 +00:00
Fix hoistTry in concatenated string clause
This commit is contained in:
@@ -994,7 +994,11 @@ extension Formatter {
|
||||
case let .keyword(name) where ["is", "as", "try", "await"].contains(name),
|
||||
let .operator(name, .infix) where name != "=":
|
||||
break
|
||||
case .endOfScope(")") where prevToken.isStringBody:
|
||||
case .operator(_, .prefix), .stringBody,
|
||||
.endOfScope(")") where prevToken.isStringBody ||
|
||||
(prevToken.isEndOfScope && prevToken.isStringDelimiter),
|
||||
.startOfScope where tokens[i].isStringDelimiter,
|
||||
.endOfScope where tokens[i].isStringDelimiter:
|
||||
break
|
||||
case .operator(_, .postfix), .identifier, .number, .endOfScope:
|
||||
if !prevToken.isOperator(ofType: .infix),
|
||||
@@ -1002,9 +1006,6 @@ extension Formatter {
|
||||
{
|
||||
break loop
|
||||
}
|
||||
case .operator(_, .prefix), .stringBody,
|
||||
.startOfScope where tokens[i].isStringDelimiter:
|
||||
break
|
||||
default:
|
||||
break loop
|
||||
}
|
||||
|
||||
@@ -70,6 +70,20 @@ class HoistingTests: RulesTests {
|
||||
testFormatting(for: input, output, rule: FormatRules.hoistTry)
|
||||
}
|
||||
|
||||
func testHoistTryInsideStringInterpolation5() {
|
||||
let input = """
|
||||
return str +
|
||||
"&enrolments[\\(index)][roleid]=\\(MoodleRoles.studentRole.rawValue)" +
|
||||
"&enrolments[\\(index)][userid]=\\(try user.requireMoodleID())"
|
||||
"""
|
||||
let output = """
|
||||
return try str +
|
||||
"&enrolments[\\(index)][roleid]=\\(MoodleRoles.studentRole.rawValue)" +
|
||||
"&enrolments[\\(index)][userid]=\\(user.requireMoodleID())"
|
||||
"""
|
||||
testFormatting(for: input, output, rule: FormatRules.hoistTry)
|
||||
}
|
||||
|
||||
func testHoistTryInsideArgument() {
|
||||
let input = """
|
||||
array.append(contentsOf: try await asyncFunction(param1: param1))
|
||||
|
||||
Reference in New Issue
Block a user