SwiftLint
SwiftLint copied to clipboard
`statement_position` rule customization
I would like statement_position to allow:
if condition { print("\(value1)") }
else { print("\(value2)") }
if condition {
print("\(value1)")
} else {
print("\(value2)")
}
but don't allow :
if condition {
print("\(value1)")
}
else {
print("\(value2)")
}
Basically, allow \n else only if the { and } are on the same line with else.
I came here to ask for something similar but different, ie. a configuration for statement_position to ensure else, catch are styled as:
if condition {
print("\(value1)")
}
else {
print("\(value2)")
}
since they are keywords introducing a new block, it's more symmetric to have them formatted as equivalent. In this context, the following would also be permissible:
if condition { print("\(value1)") }
else { print("\(value2)") }
Essentially the rule would be, every block is introduced by a keyword, and the keyword should be the first thing on the line, not obscured behind something else.
I feel this request is more internally consistent than the OP.
@lhunath I'm pretty sure your request is the same as #1181 and the configuration for that i.e. uncuddled_else exists already.