A rule that enforces the min or max amount of cases required per switch statement. E.g. a switch statement with just one case or two would be better expressed with if-else
. At the same time a switch statement with too many cases might be better refactored to a lookup table.
{
"switch-case-limits": [
"error",
{ "min": 2, "max": 10 }
]
}
// min: 2
switch (foo) {
case: 'bar':
return 'BAR';
}
// max: 3
switch (foo) {
case: 'bar1':
return 'BAR1';
case: 'bar2':
return 'BAR2';
case: 'bar3':
return 'BAR3';
case: 'bar4':
return 'BAR4';
}
// min: 2
switch (foo) {
case: 'bar1':
return 'BAR1';
case: 'bar2':
return 'BAR2';
}
// max: 3
switch (foo) {
case: 'bar1':
return 'BAR1';
case: 'bar2':
return 'BAR2';
case: 'bar3':
return 'BAR3';
}
switch-case-limits
No response
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too