eslint/no-const-assign 正确性
它的作用
禁止重新赋值 const 变量。
为什么这是个问题?
使用 const 关键字声明的变量无法被修改,否则会在运行时引发错误。
请注意,对于 TypeScript 代码,此规则并非必需,因为 TypeScript 已经会将此类情况识别为错误。
示例
此规则的错误代码示例:
js
const a = 0;
a = 1;
const b = 0;
b += 1;此规则的正确代码示例:
js
const a = 0;
console.log(a);
var b = 0;
b += 1;如何使用
通过配置文件或 CLI 启用此规则,可以使用:
json
{
"rules": {
"no-const-assign": "error"
}
}bash
oxlint --deny no-const-assign