avoid-nested-switch-expressions

Path
lint/complexity/avoid-nested-switch-expressions
Default
Off, opt in
Origin
Falcon
Rule
102 of 512

Reports deeply nested switch expressions.

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

Invalid

example.dartdart
int handle(int x) => switch (x) {
  0 => switch (x + 1) { 1 => 2, _ => 3 },
  _ => 4,
};
Nesting exceeds 1 levels. Extract the nested construct into a helper.
1int handle(int x) => switch (x) {
2 0 => switch (x + 1) { 1 => 2, _ => 3 },

Valid

example.dartdart
int handle(int x) => switch (x) { 0 => 1, _ => 2 };
int independent(int x) => switch (x) { 1 => 2, _ => 3 };

Configure avoid-nested-switch-expressions

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

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

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

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