Tslint one line rule inappropriately 'else'

I have configin tslint.jsonforone line rule

one-line": [true,
      "check-open-brace",
      "check-catch",
      "check-else",
      "check-whitespace"
    ],

When I have lines of code like this:

if(SomethingTrue) { next("a"); }
else { next("b"); }

I have a warning:

(one-line) file.ts[17, 9]: misplaced 'else'

Why is this happening? Is it wrong practice to have one line else?

+3
source share
4 answers

You have:

else { next("b"); }

Else must be a single line. So:

else { 
    next("b"); 
}

Does bad practice have another line?

Just reading is easier. His style for consistency.

+6
source
  if (condition is true) {
    do something;
  }
else {
    do something else;
  }

Note that else appears next to}

if (condition is true) {
    do something;
  } else {
    do something else;
  }
+8
source

tslint docs , "check-else" one-line, else if.

, :

if(SomethingTrue) { next("a"); }
else { next("b"); }

:

if(SomethingTrue) { next("a"); } else { next("b"); }
+3
source
 if (Condition) {
  Your Code
   } else {
    Your Code
 }

Closing If and beginning else should be on the same line

+2
source

Source: https://habr.com/ru/post/1672531/


All Articles