avoid-multi-assignment
preset: recommended
Warns when multiple variable assignments are placed on the same line.
Multiple assignments on the same line can lead to confusion or indicate an incorrect operator (=
instead of ==
).
Example
❌ Bad:
class SomeClass {
String someString = 'some';
String another = 'another';
void update(String str) {
someString = another = str; // LINT: Avoid multi assignments. Try moving each assignment to its own line.
final instance = SomeClass();
instance.another = someString = str; // LINT: Avoid multi assignments. Try moving each assignment to its own line.
}
}
✅ Good:
class SomeClass {
String someString = 'some';
String another = 'another';
void update(String str) {
someString = str; // Correct, on separate lines
another = str;
}
}