prefer-correct-switch-length
Warns when a switch has too few or too many cases.
⚙️ Config
Set min-length
(default is 3
) to configure the minimum number of cases.
Set max-length
(default is 10
) to configure the maximum number of cases after which the rule should trigger.
Set ignore-fallthrough-cases
(default is false
) to ignore fallthrough cases (with no body).
dart_code_metrics:
...
rules:
...
- prefer-correct-switch-length:
min-length: 5
max-length: 20
Example
❌ Bad:
// LINT
switch (value) {
case '1':
{
print('hello world');
break;
}
}
✅ Good:
switch (value) {
case '1':
{
...
}
case '2':
{
...
}
case '3':
{
...
}
}