Control Statement
if
, for
, guard
, switch
, while
, and catch
statements shouldn’t unnecessarily wrap their conditionals or arguments in parentheses
- Identifier:
control_statement
- Enabled by default: Yes
- Supports autocorrection: Yes
- Kind: style
- Analyzer rule: No
- Minimum Swift compiler version: 5.0.0
- Default configuration:
Key Value severity warning
Non Triggering Examples
if condition {}
if (a, b) == (0, 1) {}
if (a || b) && (c || d) {}
if (min...max).contains(value) {}
if renderGif(data) {}
renderGif(data)
guard condition else {}
while condition {}
do {} while condition {}
do { ; } while condition {}
switch foo {}
do {} catch let error as NSError {}
foo().catch(all: true) {}
if max(a, b) < c {}
switch (lhs, rhs) {}
if (f() { g() {} }) {}
if (a + f() {} == 1) {}
if ({ true }()) {}
Triggering Examples
↓if (condition) {}
↓if(condition) {}
↓if (condition == endIndex) {}
↓if ((a || b) && (c || d)) {}
↓if ((min...max).contains(value)) {}
↓guard (condition) else {}
↓while (condition) {}
↓while(condition) {}
do { ; } ↓while(condition) {}
do { ; } ↓while (condition) {}
↓switch (foo) {}
do {} ↓catch(let error as NSError) {}
↓if (max(a, b) < c) {}