Closed as not planned
Closed as not planned
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I have searched for related issues and found none that match my proposal.
- I have searched the current rule list and found no rules that match my proposal.
- I have read the FAQ and my problem is not listed.
My proposal is suitable for this project
- I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).
Link to the rule's documentation
https://typescript-eslint.io/rules/switch-exhaustiveness-check/
Description
I propose that the switch-exhaustiveness-check
checks switch
statements that operate on non-union-types and require them to have a default case to ensure they are exhaustive.
Fail
const value: number = Math.floor(Math.random() * 3);
switch (value) {
case 0:
console.log("zero");
return;
case 1:
console.log("one");
return;
}
Pass
const value: number = Math.floor(Math.random() * 3);
switch (value) {
case 0:
console.log("zero");
return;
case 1:
console.log("one");
return;
default:
console.log("higher");
return;
// Or
default:
// Do nothing
}
Additional Info
Since it would break projects that have the switch-exhaustiveness-check
enabled, but don't have all their switch statements fully exhaustive, this should probably locked behind a default false option. Maybe this could be turned on by default with the next major version.
This option can not be replaced with default-case
due to #7539.
Originally searched for during: