Eslint参考手册
规则 | Rules
no-alert
JavaScript的alert
,confirm
和prompt
功能被广泛认为是刺耳的UI元素,应该由更适合的定制UI实现替换。此外,alert
经常在调试代码时使用,在部署到生产之前应该将其删除。
alert("here!");
规则细节
此规则旨在捕获应该删除的调试代码,并弹出应该用不那么突兀的自定义用户界面替换的UI元素。因此,当它遇到它会发出警告alert
,prompt
以及confirm
未阴影函数调用。
此规则的错误代码示例:
/*eslint no-alert: "error"*/
alert("here!");
confirm("Are you sure?");
prompt("What's your name?", "John Doe");
此规则的正确代码示例:
/*eslint no-alert: "error"*/
customAlert("Something happened!");
customConfirm("Are you sure?");
customPrompt("Who are you?");
function foo() {
var alert = myCustomLib.customAlert;
alert();
}
相关规则
- no-console
- no-debugger
版本
该规则在ESLint 0.0.5中引入。
资源
- 规则来源
- 文档来源
规则 | Rules相关

ESLint 是一个代码规范和错误检查工具,有以下几个特性。所有东西都是可以插拔的。你可以调用任意的 rule api 或者 formatter api 去打包或者定义 rule or formatter。任意的 rule 都是独立的。没有特定的 coding style,你可以自己配置。
主页 | https://eslint.org/ |
源码 | https://github.com/eslint/eslint |
发布版本 | 4.12.0 |