禁止自我赋值
注意:此规则是
recommended 规则集的一部分。在
deno.json 中启用完整集合{
"lint": {
"rules": {
"tags": ["recommended"]
}
}
}使用 Deno CLI 启用完整集合
deno lint --rules-tags=recommended
此规则可以通过在
deno.json 中将其添加到 include 或 exclude 数组,从而被显式地包含或排除在当前标签中的规则之外。{
"lint": {
"rules": {
"include": ["no-self-assign"],
"exclude": ["no-self-assign"]
}
}
}禁止自赋值。
像 a = a; 这样的自赋值完全没有效果。如果代码中存在自赋值,很可能意味着作者仍在重构过程中,并且还有一些未完成的工作。
无效示例
a = a;
[a] = [a];
[a, b] = [a, b];
[a, b] = [a, c];
[a, ...b] = [a, ...b];
a.b = a.b;
有效示例
let a = a;
a += a;
a = [a];
[a, b] = [b, a];
a.b = a.c;