簡體   English   中英

在Visual Studio中圍繞表達式的無端括號

[英]Gratuitous parentheses around expression in Visual Studio

我突然在Visual Studio的很多地方收到這條消息。

圍繞表達的無端括號。

我可以通過驗證我的Javascript,但它是什么意思,為什么下面的表達式導致這個?

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

}

Visual Studio 15.8.6

此規則有一個字符串選項:

  • "all" (默認值)不允許在任何表達式周圍使用不必要的括號
  • "functions"只允許在函數表達式周圍使用不必要的括號

此規則具有“all”選項例外的對象選項:

  • "conditionalAssign" :false允許在條件測試表達式中圍繞賦值使用額外的括號

  • "returnAssign" :false允許在return語句中圍繞賦值使用額外的括號

  • "nestedBinaryExpressions" :false允許嵌套二進制表達式中的額外括號

比較這兩個代碼:

使用默認"all"選項的此規則的錯誤代碼示例:

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

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

使用默認"all"選項的此規則的正確代碼示例:

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

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

你的代碼格式正確

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM