]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/rules/no-alert.md
first commit
[pve-eslint.git] / eslint / docs / rules / no-alert.md
CommitLineData
eb39fafa
DC
1# Disallow Use of Alert (no-alert)
2
3JavaScript'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.
4
5```js
6alert("here!");
7```
8
9## Rule Details
10
11This 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.
12
13Examples of **incorrect** code for this rule:
14
15```js
16/*eslint no-alert: "error"*/
17
18alert("here!");
19
20confirm("Are you sure?");
21
22prompt("What's your name?", "John Doe");
23```
24
25Examples of **correct** code for this rule:
26
27```js
28/*eslint no-alert: "error"*/
29
30customAlert("Something happened!");
31
32customConfirm("Are you sure?");
33
34customPrompt("Who are you?");
35
36function foo() {
37 var alert = myCustomLib.customAlert;
38 alert();
39}
40```
41
42## Related Rules
43
44* [no-console](no-console.md)
45* [no-debugger](no-debugger.md)