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();
}
选项
🌐 Options
此规则没有选项。
🌐 This rule has no options.
相关规则
版本
此规则是在 ESLint v0.0.5 中引入。