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