]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/no-alert.md
import 8.23.1 source
[pve-eslint.git] / eslint / docs / src / rules / no-alert.md
1 ---
2 title: no-alert
3 layout: doc
4 rule_type: suggestion
5 related_rules:
6 - no-console
7 - no-debugger
8 ---
9
10
11 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.
12
13 ```js
14 alert("here!");
15 ```
16
17 ## Rule Details
18
19 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.
20
21 Examples of **incorrect** code for this rule:
22
23 :::incorrect
24
25 ```js
26 /*eslint no-alert: "error"*/
27
28 alert("here!");
29
30 confirm("Are you sure?");
31
32 prompt("What's your name?", "John Doe");
33 ```
34
35 :::
36
37 Examples of **correct** code for this rule:
38
39 :::correct
40
41 ```js
42 /*eslint no-alert: "error"*/
43
44 customAlert("Something happened!");
45
46 customConfirm("Are you sure?");
47
48 customPrompt("Who are you?");
49
50 function foo() {
51 var alert = myCustomLib.customAlert;
52 alert();
53 }
54 ```
55
56 :::