Skip to main content

default-case

Some coding conventions require that all switch statements have a default case, even if empty.
Rule Type: Suggestion
Fixable: No

Why This Rule Exists

Always having a default case makes it clear whether the developer forgot to handle a case or intentionally has no default behavior.

Rule Details

This rule requires a default 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:
Examples with custom pattern:

Best Practices

Explicit Default Handling

Even if the default does nothing, make it explicit to show it was considered.

Error Handling in Default

Logging Unknown Cases

When Not to Use It

Disable this rule if you don’t want to require default cases or comments in switch statements.