Closed benkay closed 10 months ago
@benkay thanks for reporting this. It seems like you've found a a good solution, but I'll get it fixed asap anyway.
@calda am I right in thinking the bug here is in the redundantClosure
rule? Specifically that closures containing if
or switch
expressions should not be removed when inside a conditional expression?
I think the simplest test case is probably something like:
guard let foo = {
if condition {
bar()
}
}() else {
return
}
Yeah. I'm surprised the changes in https://github.com/nicklockwood/SwiftFormat/pull/1553 don't prevent this though. Will take a look.
@calda I've just pushed a fix to develop.
Yeah. I'm surprised the changes in #1553 don't prevent this though. Will take a look.
From what I can see, you were checking for an =
, but not checking if that =
was conditional (e.g. if let foo = ...
) where it wouldn't be allowed. My fix was pretty simple, but perhaps there's a more elegant way to integrate it with the existing logic?
You code change looks reasonable to me
@benkay fixed in 0.52.9
We had this (questionable) code
0.52.8 reformats this to
Which fails to compile (and if it did, would have different semantics).
I suppose this should be formatted as
Although we actually hand-changed this to the more sensible