Skip to main content

no-alert

JavaScript’s alert, confirm, and prompt functions are obtrusive UI elements and should be replaced with custom UI. They’re also often leftover debugging code.
Rule Type: Suggestion
Fixable: No

Why This Rule Exists

  • Debugging remnants: alert() is often used during debugging and should be removed
  • Poor UX: Browser dialogs are intrusive and block the entire page
  • Limited customization: Can’t match your app’s design
  • Not testable: Hard to test in automated tests

Rule Details

This rule warns about alert, prompt, and confirm function calls that aren’t shadowed by local variables.

Examples

Incorrect Code

Correct Code

Modern Alternatives

Custom Modal Libraries

Use a modal library that matches your app’s design and is non-blocking.

React Example

Toast Notifications

Debugging Alternatives

Console Methods

Debugger Statement

Logger Library

Common Patterns

Quick User Feedback

Confirmation Dialogs

User Input

Testing Benefits

Browser alert dialogs are difficult to test in automated tests.

When Not to Use It

Disable this rule if:
  • You’re writing quick prototypes or demos
  • You’re in a legacy codebase that can’t be updated
  • You’re specifically building debugging tools
For production code, this rule should be enabled.

Configuration