noAlert
¥Summary
-
规则生效日期:
v2.1.0¥Rule available since:
v2.1.0 -
¥Diagnostic Category:
lint/suspicious/noAlert -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
¥How to configure
{ "linter": { "rules": { "suspicious": { "noAlert": "error" } } }}¥Description
禁止使用 alert、confirm 和 prompt。
¥Disallow the use of alert, confirm, and prompt.
JavaScript 的 alert、confirm 和 prompt 函数被普遍认为作为 UI 元素过于突兀,应该被更合适的自定义 UI 实现所取代。此外,alert 通常用于调试代码,在部署到生产环境之前应该移除。
¥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.
¥Examples
¥Invalid
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.
¥Valid
customAlert("Something happened!");customConfirm("Are you sure?");customPrompt("Who are you?");function foo() { const alert = myCustomLib.customAlert; alert();}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号