Would it be possible to have a rule that enforces else position in multi-line guard statements?
E.g.
guard
let a = a,
let b = b else {
return
}
would be formatted into
guard
let a = a,
let b = b
else {
return
}
At the moment SwiftFormat leaves code like this untouched.
I believe this is related to #37.
Another useful formatting rule would be to enforce uniform formatting for multiline guards.
For example, when guard is multiline, but there is no newline after guard itself:
guard let a = a,
let b = b
else {
return
}
Could be formatted into
guard
let a = a,
let b = b
else {
return
}
Since it's clear that guard is multiline here.
@mgrebenets do you think it would make sense to tie this to the existing elseOnSameLine rule configuration? It seems related.
@nicklockwood Please don't tie it into the elseOnSameLine rule. We use else on same line for everything except multiline guards
A rule to enforce the multiline guard formatting would be greatly appreciated, though. With our current setup, swiftformat seems to respect/infer the current multiline guard format and leave it as is; but the reason we're using swiftformat is to enforce a certain formatting style, so it kind of defeats the purpose :)
Same here.
@mgrebenets @rafcabezas @hartbit this is now implemented in 0.45.1. It's controlled by a new --guardelse option.
Most helpful comment
@nicklockwood Please don't tie it into the
elseOnSameLinerule. We use else on same line for everything except multiline guards