menu
prefer-match
Prefer match over switch statements and repeated equality chains
Repeated equality branches and switch cases encode selection as independent statements.
Instead, you SHOULD use match to bind the selected value and its cases in one expression.
Reported
1function describe(value: int32): string {2 if (value === 0) {3 return "zero";4 } else if (value === 1) {5 return "one";6 } else if (value === 2) {7 return "two";8 }9 10 return "many";11}Accepted
1function describe(value: int32): string {2 return match (value) {3 0 => "zero"4 1 => "one"5 2 => "two"6 _ => "many"7 };8}