no-alert
JavaScript’salert, 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
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 aboutalert, prompt, and confirm function calls that aren’t shadowed by local variables.
Examples
Incorrect Code
Correct Code
Modern Alternatives
Custom Modal Libraries
React Example
Toast Notifications
Debugging Alternatives
Console Methods
Debugger Statement
Logger Library
Common Patterns
Quick User Feedback
Confirmation Dialogs
User Input
Testing Benefits
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