Skip to content

chained_assignment

Reports an assignment whose value is itself an assignment, such as first = second = 0. Write each assignment on its own.

Tier
advisory
Scope
Dart
Lowest preset
strict
Fix
none

An assignment whose value is itself an assignment, also in brackets: first = second = 0, total += (step = next()). A chain of three or more is reported once, at the outermost assignment.

It does not report:

  • an assignment whose value is computed from an assignment: a = (b = 1) + 1;
  • a declaration initialized by an assignment;
  • an assignment in a condition or a return.

One expression writes two places. The value that reaches the first is the value of the inner assignment, not what its target reads back after it: a setter that changes what it stores gives the two places different values.

Violating
first = second = 0;
Corrected
second = 0;
first = 0;

Set under the assay: key of the project’s root analysis_options.yaml.

Rule parameter Default Effect
enabled true false switches the rule off for the whole project.
exclude [] Path globs where the rule is silent.

Write why on the line directly above the suppression:

// Both counters start the round at zero, and neither has a setter.
// ignore: assay/chained_assignment

// ignore_for_file: assay/chained_assignment silences it in a whole file, and // ignore: chained_assignment without the prefix works too. See Suppressions.