no-constant-condition
NOTE: this rule is part of the
recommended rule set.Enable full set in
deno.json:{
"lint": {
"rules": {
"tags": ["recommended"]
}
}
}Enable full set using the Deno CLI:
deno lint --rules-tags=recommended
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the
include or exclude array in deno.json:{
"lint": {
"rules": {
"include": ["no-constant-condition"],
"exclude": ["no-constant-condition"]
}
}
}不允许在条件测试中使用常量表达式。
在条件测试中使用常量表达式通常是错误的,或者是在开发过程中引入的临时情况,并不适合用于生产环境。
无效:
if (true) {}
if (2) {}
do {} while (x = 2); // 无限循环
有效:
if (x) {}
if (x === 0) {}
do {} while (x === 2);