avoid_nested_if

SeverityQuick FixOptions
Warning

Details

DO avoid too many nested if statements.

Bad
if (x) {
  if (y) {
    if (z) {
      doSomething();
    }
  }
}
Good
if (!x) return;
if (!y) return;
if (!z) return;
doSomething();

Usage

To enable the avoid_nested_if rule, add avoid_nested_if under custom_lint > rules in your analysis_options.yaml file:

custom_lint:
  rules:
    - avoid_nested_if

Options

OptionTypeDescriptionDefault Value
max_nesting_levelintThe maximum allowed nesting level.2

To configure the max nesting level, add an integer to the max_nesting_level option:

custom_lint:
  rules:
    - avoid_nested_if:
      max_nesting_level: 3