Eslint
规则 | Rules

no-alert

禁止使用警报(no-alert)

JavaScript的alertconfirmprompt功能被广泛认为是刺耳的UI元素,应该由更适合的定制UI实现替换。此外,alert经常在调试代码时使用,在部署到生产之前应该将其删除。

alert("here!"

规则细节

此规则旨在捕获应该删除的调试代码,并弹出应该用不那么突兀的自定义用户界面替换的UI元素。因此,当它遇到它会发出警告alertprompt以及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中引入。

资源