{"record":{"id":"9b4ab9fd102a0f79","repo":"oxc-project/oxc","slug":"alert-confirm-and-prompt-functions-are-not","errorCode":null,"errorMessage":"`alert`, `confirm` and `prompt` functions are not allowed","messagePattern":"`alert`, `confirm` and `prompt` functions are not allowed","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_alert.rs","lineNumber":11,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::ScopeId;\nuse oxc_span::{GetSpan, Span};\nuse oxc_str::Ident;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn no_alert_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"`alert`, `confirm` and `prompt` functions are not allowed\")\n        .with_help(\"Use a custom UI instead\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoAlert;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow the use of `alert`, `confirm`, and `prompt`.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// 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.\n    /// Furthermore, `alert` is often used while debugging code, which should be removed before deployment to production.\n    ///\n    /// ### Examples","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_alert.rs#L1-L29","documentation":"Diagnostic from the `no-alert` rule. It disallows calls to the browser globals `alert`, `confirm`, and `prompt` (crates/oxc_linter/src/rules/eslint/no_alert.rs:64 matches exactly these three names) because they are blocking, obtrusive UI primitives and `alert` is a common leftover debugging tool. The check resolves the identifier as a global reference, and shadowed local variables assigned from those names can still be flagged depending on scoping resolution — the rule docs explicitly show the shadowing case.","triggerScenarios":"Any call `alert('here!')`, `confirm('Are you sure?')`, or `prompt(\"What's your name?\", 'John Doe')` anywhere in linted source, including debug leftovers and code that rebinds the name (`var alert = myCustomLib.customAlert; alert();` — shown in the rule's own docs at crates/oxc_linter/src/rules/eslint/no_alert.rs:49-50). The rule has no options.","commonSituations":"Debug `alert()` calls accidentally committed before deployment; browser-only code linted together with shared code; libraries wrapping native dialogs where the rule flags even intentional usage; Electron/webview apps where blocking dialogs are considered acceptable UX but the shared config forbids them.","solutions":["Remove leftover debugging calls; replace temporary debugging with `console.log`/`console.debug` or a conditional logger.","For real user-facing flows, swap in your product's UI (toast, modal component) as the help text ('Use a custom UI instead') suggests.","If the calls are intentional (kiosk/WebView tooling), disable the rule inline (`oxlint-disable no-alert`) or in the config for those files."],"exampleFix":"// before\nfunction onDelete(item) {\n  if (!confirm('Delete?')) return;\n  api.remove(item.id);\n}\n\n// after\nfunction onDelete(item) {\n  openConfirmDialog({ message: 'Delete?', onConfirm: () => api.remove(item.id) });\n}","handlingStrategy":"validation","validationCode":"// CI: oxlint --rule no_alert src/ blocks debug dialogs before merge.\n// Local pre-commit hook example:\n// oxlint --rule no_alert --deny-warn $(git diff --name-only --cached | grep -E '\\.(js|ts)$')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never use alert() for debugging; console.debug or a breakpoint does not leave residue in the code.","Standardize on one dialog/toast component for user-facing confirmations so nobody reaches for confirm().","Grep for \\b(alert|confirm|prompt)\\( before releases — it is a one-line release checklist item that catches rule escapes."],"tags":["eslint","oxlint","browser","debugging","ui","restriction"],"backgroundTag":"browser-native-dialog-blocking","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}