Skip to content

noAlert

biome.json
{
"linter": {
"rules": {
"suspicious": {
"noAlert": "error"
}
}
}
}

Disallow the use of alert, confirm, and prompt.

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!");
code-block.js:1:1 lint/suspicious/noAlert ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected alert

> 1 │ alert(“here!”);
^^^^^^^^^^^^^^
2 │

The alert function is considered to be obtrusive. Replace it with a custom UI implementation.

confirm("Are you sure?");
code-block.js:1:1 lint/suspicious/noAlert ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected confirm

> 1 │ confirm(“Are you sure?”);
^^^^^^^^^^^^^^^^^^^^^^^^
2 │

The confirm function is considered to be obtrusive. Replace it with a custom UI implementation.

prompt("What's your name?", "John Doe");
code-block.js:1:1 lint/suspicious/noAlert ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected prompt

> 1 │ prompt(“What’s your name?”, “John Doe”);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

The prompt function is considered to be obtrusive. Replace it with a custom UI implementation.

customAlert("Something happened!");
customConfirm("Are you sure?");
customPrompt("Who are you?");
function foo() {
const alert = myCustomLib.customAlert;
alert();
}