版本

no-alert

禁用 alertconfirmprompt 的使用

JavaScript 的 alertconfirmprompt 函式被廣泛認為是侵入式的 UI 元素,應替換為更適合的自訂 UI 實作。此外,alert 通常在除錯程式碼時使用,在部署到生產環境之前應移除。

alert("here!");

規則詳細資訊

此規則旨在捕捉應移除的除錯程式碼和應替換為較不侵入的自訂 UI 的彈出 UI 元素。因此,當遇到未被遮蔽的 alertpromptconfirm 函式呼叫時,它會發出警告。

此規則的錯誤程式碼範例

在線上測試中開啟
/*eslint no-alert: "error"*/

alert("here!");

confirm("Are you sure?");

prompt("What's your name?", "John Doe");

此規則的正確程式碼範例

在線上測試中開啟
/*eslint no-alert: "error"*/

customAlert("Something happened!");

customConfirm("Are you sure?");

customPrompt("Who are you?");

function foo() {
    var alert = myCustomLib.customAlert;
    alert();
}

版本

此規則在 ESLint v0.0.5 中引入。

資源

變更語言