Gratuitous parentheses around expression in Visual Studio

Viewed 3481

I am getting this message in quite of bit of places in Visual Studio all of a sudden.

Gratuitous parentheses around expression.

I am OK with validationg my Javascript but what does it mean and why is the expressions below causing this?

if ((self.display.current() !== display.LOSER && self.display.current() !== display.WINNER) || !self.bye()) {

}

Visual Studio 15.8.6

1 Answers

This rule has a string option:

  • "all" (default) disallows unnecessary parentheses around any expression
  • "functions" disallows unnecessary parentheses only around function expressions

This rule has an object option for exceptions to the "all" option:

  • "conditionalAssign": false allows extra parentheses around assignments in conditional test expressions

  • "returnAssign": false allows extra parentheses around assignments in return statements

  • "nestedBinaryExpressions": false allows extra parentheses in nested binary expressions

Compare these two codes:

Examples of incorrect code for this rule with the default "all" option:

/* eslint no-extra-parens: "error" */

a = (b * c);
(a * b) + c;
typeof (a);
(function(){} ? a() : b());

Examples of correct code for this rule with the default "all" option:

/* eslint no-extra-parens: "error" */

(0).toString();
({}.toString.call());
(function(){}) ? a() : b();
(/^a$/).test(x);

And Your code correct format is

self.display.current() !== display.LOSER && self.display.current() !== display.WINNER || !self.bye()
Related