Skip to content

Latest commit

 

History

History
67 lines (56 loc) · 1.06 KB

no-useless-switch-case.md

File metadata and controls

67 lines (56 loc) · 1.06 KB

Disallow useless case in switch statements

✅ This rule is enabled in the recommended config.

💡 This rule is manually fixable by editor suggestions.

An empty case before the last default case is useless.

Fail

switch (foo) {
	case 1:
	default:
		handleDefaultCase();
		break;
}

Pass

switch (foo) {
	case 1:
	case 2:
		handleCase1And2();
		break;
}
switch (foo) {
	case 1:
		handleCase1();
		break;
	default:
		handleDefaultCase();
		break;
}
switch (foo) {
	case 1:
		handleCase1();
		// Fallthrough
	default:
		handleDefaultCase();
		break;
}
switch (foo) {
	// This is actually useless, but we only check cases where the last case is the `default` case
	case 1:
	default:
		handleDefaultCase();
		break;
	case 2:
		handleCase2();
		break;
}