no-cond-assign
NOTE: this rule is part of the
推荐 rule set.Enable full set in
deno.json:{
"lint": {
"rules": {
"tags": ["推荐"]
}
}
}Enable full set using the Deno CLI:
deno lint --rules-tags=推荐
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-cond-assign"],
"exclude": ["no-cond-assign"]
}
}
}禁止在条件语句中使用赋值操作符 =。
在条件语句中使用赋值操作符通常是因为误打了相等运算符 ==。如果在条件语句中确实需要赋值,则此规则允许通过将赋值放入括号中来实现。
无效:
let x;
if (x = 0) {
let b = 1;
}
function setHeight(someNode) {
do {
someNode.height = "100px";
} while (someNode = someNode.parentNode);
}
有效:
let x;
if (x === 0) {
let b = 1;
}
function setHeight(someNode) {
do {
someNode.height = "100px";
} while ((someNode = someNode.parentNode));
}