default-case
Some coding conventions require that allswitch statements have a default case, even if empty.
Rule Type: Suggestion
Fixable: No
Fixable: No
Why This Rule Exists
Always having adefault case makes it clear whether the developer forgot to handle a case or intentionally has no default behavior.
Rule Details
This rule requires adefault clause in switch statements. You can optionally include a // no default comment if there’s no default case.
Examples
Incorrect Code
Correct Code
Options
commentPattern
Type: string (regex)Default:
/^no default$/i
Customize the comment pattern that indicates an intentional omission:
Best Practices
Explicit Default Handling
Error Handling in Default
Logging Unknown Cases
When Not to Use It
Disable this rule if you don’t want to requiredefault cases or comments in switch statements.