首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

no-alert

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

代码语言:javascript
复制
alert("here!");

规则细节

此规则旨在捕获应该删除的调试代码,并弹出应该用不那么突兀的自定义用户界面替换的UI元素。因此,当它遇到它会发出警告alertprompt以及confirm未阴影函数调用。

此规则的错误代码示例:

代码语言:javascript
复制
/*eslint no-alert: "error"*/

alert("here!");

confirm("Are you sure?");

prompt("What's your name?", "John Doe");

此规则的正确代码示例:

代码语言:javascript
复制
/*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中引入。

资源

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com