Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ESLint rule to disallow if-else statement in single line style

I try to find eslint rule to prevent writing if-else in one line style. What should I expect:

// Wrong
if() /* some code */
else /* some code */


// Correct
if() {
 /* some code */
} else { 
/* some code */
}

// But for if statement (without else) should be correct both
if() /* some code */
if() {
 /* some code */
}
like image 941
Vitalii Protsyk Avatar asked Oct 14 '25 15:10

Vitalii Protsyk


1 Answers

With the no-restricted-syntax rule you can disallow specific syntax.

Following rule should normally disallow the shorthand if statement.

no-restricted-syntax: ["error", "IfStatement > ExpressionStatement > AssignmentExpression"]
like image 141
SuperMarinade Avatar answered Oct 17 '25 04:10

SuperMarinade



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!