Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tslint one line rule misplaced 'else'

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?

like image 577
sreginogemoh Avatar asked Feb 08 '16 01:02

sreginogemoh


2 Answers

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;
}
like image 200
user7823874 Avatar answered Oct 16 '22 13:10

user7823874


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.

like image 40
basarat Avatar answered Oct 16 '22 13:10

basarat