no-const-assign
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-const-assign"],
"exclude": ["no-const-assign"]
}
}
}禁止修改声明为 const 的变量。
修改声明为 const 的变量将导致运行时错误。
无效:
const a = 0;
a = 1;
a += 1;
a++;
++a;
有效:
const a = 0;
const b = a + 1;
// `c` 在每次循环迭代中超出作用域,允许新的赋值
for (const c in [1, 2, 3]) {}