Pattern: Unnecessary break
Issue: -
Only use a break
in a non-empty switch case statement if you need to break
before the end of the case body. Dart does not support fallthrough execution
for non-empty cases, so break
s at the end of non-empty switch case statements
are unnecessary.
Example of incorrect code:
switch (1) {
case 1:
print("one");
break;
case 2:
print("two");
break;
}
Example of correct code:
switch (1) {
case 1:
print("one");
case 2:
print("two");
}
switch (1) {
case 1:
case 2:
print("one or two");
}
switch (1) {
case 1:
break;
case 2:
print("just two");
}