Skip to content

Latest commit

Β 

History

History
72 lines (61 loc) Β· 1.15 KB

File metadata and controls

72 lines (61 loc) Β· 1.15 KB

no-useless-switch-case

πŸ“ Disallow useless case in switch statements.

πŸ’Ό This rule is enabled in the following configs: βœ… recommended, β˜‘οΈ unopinionated.

πŸ’‘ This rule is manually fixable by editor suggestions.

An empty case before the last default case is useless.

Examples

// ❌
switch (foo) {
	case 1:
	default:
		handleDefaultCase();
		break;
}
// βœ…
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;
}