Skip to main content

avoid-multi-assignment

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) {
// LINT: Avoid multi assignments. Try moving each assignment to its own line.
someString = another = str;

final instance = SomeClass();
// LINT: Avoid multi assignments. Try moving each assignment to its own line.
instance.another = someString = str;
}
}

✅ Good:

class SomeClass {
String someString = 'some';
String another = 'another';

void update(String str) {
someString = str; // Correct, on separate lines
another = str;
}
}

Additional Resources