Skip to main content

prefer-correct-switch-length

added in: 1.3.0
style
⚙️

Warns when a switch has too few or too many cases.

Use min-length configuration (default is 3), if you want to set the minimum number of cases.

Use max-length configuration (default is 10), to set up the maximum number of cases after which the rule should trigger.

⚙️ Config example

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':
{
...
}
}