I am using SwiftLint and I need to have a new line after the "{" if there is a body, for example, this is correct
func foo() {
if true { }
}
but this doesn't seem right
func foo() {
if true { print("This print should be on the new line") }
}
like this
func foo() {
if true {
print("This print should be on the new line")
}
}
How to do this?
UPD
Thanks, @Bram, there is such a regex
custom_rules:
newline_block:
name: "Newline Block"
regex: 'if \(?\w+\)? \{[ ]*(.+)+[ ]*\}'
message: "Statement must be on its own line"
The problem is this regex catch all the conditions with one word after the if
, like this
if myCondition { }
and it doesn't matter if braces are on the next line or not, however, this regex doesn't catch conditions like this
if 0 < 1 { print() }