avoid-if-with-many-branches

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.
1void 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>