Multi-line if statements - breaks and indentation
See original GitHub issueI think it would be nice to add an additional section to the guide for multi-line if statements, especially where to set breaks and how the indentation should look like? I have added some examples below and would like to know what your preferred way of formatting this is.
Example:
if (a === 123 && b === 'abc') {
doSomething();
}
Case A: Breaks are applied after logical operators.
if (a === 123 &&
b === 'abc') {
doSomething();
}
Case B: Breaks are applied before logical operators.
if (a === 123
&& b === 'abc') {
doSomething();
}
Indentation: Regardless of where the breaks are set, indent the next line with 4 instead of 2 spaces.
// Case A
if (a === 123 &&
b === 'abc') {
doSomething();
}
// Case B
if (a === 123
&& b === 'abc') {
doSomething();
}
I personally prefer Case B because you can immediately see what’s going on, but I’m not sure about the indentation - would still prefer 2 over 4 though as putting the operators in front of it help a little bit to distinguish the statement from the block.
At this point I also want to say that this guide is super useful, so thanks a lot for sharing this!
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (1 by maintainers)
Top GitHub Comments
Neither.
Only one of these two is acceptable:
We’re not decided yet, nor do we enforce, whether the operator should end lines or begin them.
A PR to the guide that adds a section on this would be appreciated.
I vote for this:
Simply because you can easily comment out a condition if you are debugging like so: