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
What it reports
Section titled “What it reports”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.
Example
Section titled “Example”first = second = 0;second = 0;first = 0;Rule parameters
Section titled “Rule parameters”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. |
Suppressing it
Section titled “Suppressing it”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.