SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

`statement_position` rule customization

Open andreiardelean-kwiff opened this issue 4 years ago • 2 comments

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.

andreiardelean-kwiff avatar Jun 18 '21 07:06 andreiardelean-kwiff

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 avatar Aug 04 '21 00:08 lhunath

@lhunath I'm pretty sure your request is the same as #1181 and the configuration for that i.e. uncuddled_else exists already.

thisIsTheFoxe avatar Mar 21 '22 08:03 thisIsTheFoxe