简体   繁体   English

是否有一个 ESLint 规则来检查条件表达式中逻辑运算符的数量?

[英]Is there an ESLint rule that checks the number of logical operators in a conditional expression?

I am looking for such a rule to see the complexity of the conditional expression.我正在寻找这样的规则来查看条件表达式的复杂性。

For example, if the threshold is 5, the following conditional expression would result in an error:例如,如果阈值为 5,则以下条件表达式将导致错误:

if ((true && false) || ((false || true) && (true || false))) {
  // ...
}

However, the following conditional expression will not produce an error:但是,以下条件表达式不会产生错误:

if ((true && false) || ((false || true) && true)) {
  // ...
}

I created an ESLint plugin to check the number of logical operator .我创建了一个 ESLint 插件来检查逻辑运算符的数量 For the moment, it only check the number of logical operators in the conditional expression of the if statement.目前,它只检查 if 语句的条件表达式中的逻辑运算符的数量。 But I may update the rule to get to check any expression.但我可能会更新规则以检查任何表达式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM