I have such config
in tslint.json
for one line rule
one-line": [true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
When I have code lines like that:
if(SomethingTrue) { next("a"); }
else { next("b"); }
I've got warning:
(one-line) file.ts[17, 9]: misplaced 'else'
Why that is happens?
Is it bad practice to have one line else
?
if (condition is true) {
// do something;
}
else {
// do something else;
}
Notice that else
comes next to }
if (condition is true) {
// do something;
} else {
// do something else;
}
You have :
else { next("b"); }
Else must be one one line. So:
else {
next("b");
}
Is it bad practice to have one line else?
Just easier to read. Its a styleguide for consistency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With