Eslint参考手册
规则 | Rules
no-const-assign
配置文件中的"extends": "eslint:recommended"属性启用此规则。
我们不能修改使用const关键字声明的变量。它会引发运行时错误。
在非 ES2015环境下,它可能仅仅被忽略。
规则细节
此规则旨在标记修改使用const关键字声明的变量。
此规则的错误代码示例:
/*eslint no-const-assign: "error"*/
/*eslint-env es6*/
const a = 0;
a = 1;/*eslint no-const-assign: "error"*/
/*eslint-env es6*/
const a = 0;
a += 1;/*eslint no-const-assign: "error"*/
/*eslint-env es6*/
const a = 0;
++a;此规则的正确代码示例:
/*eslint no-const-assign: "error"*/
/*eslint-env es6*/
const a = 0;
console.log(a);/*eslint no-const-assign: "error"*/
/*eslint-env es6*/
for (const a in [1, 2, 3]) { // `a` is re-defined (not modified) on each loop step.
    console.log(a);
}/*eslint no-const-assign: "error"*/
/*eslint-env es6*/
for (const a of [1, 2, 3]) { // `a` is re-defined (not modified) on each loop step.
    console.log(a);
}何时不使用它
如果您不希望收到有关修改使用const关键字声明的变量的通知,则可以安全地禁用此规则。
版本
该规则在 ESLint 1.0.0-rc-1中引入。
资源
- 规则资源
- 文档资源
规则 | Rules相关
 
                                ESLint 是一个代码规范和错误检查工具,有以下几个特性。所有东西都是可以插拔的。你可以调用任意的 rule api 或者 formatter api 去打包或者定义 rule or formatter。任意的 rule 都是独立的。没有特定的 coding style,你可以自己配置。
| 主页 | https://eslint.org/ | 
| 源码 | https://github.com/eslint/eslint | 
| 发布版本 | 4.12.0 | 
 
         加载中,请稍侯......
 加载中,请稍侯......