avoid-nested-switches

Path
lint/complexity/avoid-nested-switches
Default
Off, opt in
Origin
Falcon
Rule
103 of 512

Reports deeply nested switch statements.

max-nesting (integer, default: 1) limits nesting of this construct. Local functions and closures restart the nesting count.

Invalid

example.dartdart
void handle(int x) {
  switch (x) { case 0:
    switch (x + 1) {
      case 1: break;
    }
  }
}
Nesting exceeds 1 levels. Extract the nested construct into a helper.
2 switch (x) { case 0:
3 switch (x + 1) {

Valid

example.dartdart
void handle(int x) {
  switch (x) { case 0: break; }
  switch (x) { case 1: break; }
  switch (x) { case 2:
    void local() { switch (x) { case 3: break; } }
    local();
  }
}

Configure avoid-nested-switches

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "complexity": {
        "avoid-nested-switches": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/complexity/avoid-nested-switches: <reason>