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
?
Notice that
else
comes next to}
According to the tslint docs the problem is that when
"check-else"
is specified underone-line
the else must be on the same line as the closing brace for your if.So in your case instead of:
Use this format:
End of
If
and start ofelse
should be on the same line.You have :
Else must be one one line. So:
Just easier to read. Its a styleguide for consistency.