avoid-if-with-many-branches
- Group
- Complexity
- Path
lint/complexity/avoid-if-with-many-branches- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 70 of 512
Reports long if/else-if chains; replace them with a switch or extracted helpers.
max-branches (integer, default: 3) counts every if and the final else.
Invalid
example.dartdart
void handle(int x) {
if (x == 0) {
print(0);
} else if (x == 1) { print(1); } else { print(2); }
}If chain has 3 branches (max 2). Replace it with a switch or extracted helpers.
1
void handle(int x) {2
if (x == 0) {Valid
example.dartdart
void handle(int x) {
if (x == 0) { print(0); } else { print(1); }
if (x == 2) { if (x > 0) { print(2); } }
}Configure avoid-if-with-many-branches
Set its severity in falcon.json. See the configuration guide.
falcon.jsonjson
{
"linter": {
"rules": {
"complexity": {
"avoid-if-with-many-branches": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
example.dartdart
// falcon-ignore lint/complexity/avoid-if-with-many-branches: <reason>More complexity rules
- avoid-inverted-boolean-expressions
avoid_inverted_boolean_expressionsrecommendedFlags a doubly-negated boolean expression such as
!!x. - avoid-long-records
Reports record values and record types with too many fields.
- avoid-nested-conditional-expressions
avoid-nested-conditional-expressionsFlags a ternary conditional expression nested inside another ternary.
- avoid-nested-if
avoid_nested_ifFlags an
ifstatement whose then-branch contains nestedifstatements. - avoid-nested-switch-expressions
Reports deeply nested switch expressions.
- avoid-nested-switches
Reports deeply nested switch statements.
- avoid-nested-try-statements
Reports deeply nested try statements.
- avoid-redundant-async
avoid-redundant-asyncrecommendedFlags an
asyncfunction whose body is a singlereturn await ...;.