no-alert
禁止使用 alert
、confirm
和 prompt
JavaScript 的 alert
、confirm
和 prompt
函数被广泛认为是作为 UI 元素的突兀,应该被更合适的自定义 UI 实现所取代。此外,alert
经常在调试代码时使用,应在部署到生产之前将其删除。
¥JavaScript’s alert
, confirm
, and prompt
functions are widely considered to be obtrusive as UI elements and should be replaced by a more appropriate custom UI implementation. Furthermore, alert
is often used while debugging code, which should be removed before deployment to production.
alert("here!");
规则详情
¥Rule Details
此规则旨在捕获应删除的调试代码和应替换为不那么突兀的自定义 UI 的弹出 UI 元素。因此,它会在遇到未隐藏的 alert
、prompt
和 confirm
函数调用时触发警告。
¥This rule is aimed at catching debugging code that should be removed and popup UI elements that should be replaced with less obtrusive, custom UIs. As such, it will warn when it encounters alert
, prompt
, and confirm
function calls which are not shadowed.
此规则的错误代码示例:
¥Examples of incorrect code for this rule:
/*eslint no-alert: "error"*/
alert("here!");
confirm("Are you sure?");
prompt("What's your name?", "John Doe");
此规则的正确代码示例:
¥Examples of correct code for this rule:
/*eslint no-alert: "error"*/
customAlert("Something happened!");
customConfirm("Are you sure?");
customPrompt("Who are you?");
function foo() {
const alert = myCustomLib.customAlert;
alert();
}
相关规则
版本
此规则是在 ESLint v0.0.5 中引入。