avoid-mutating-parameters
Warns when a parameter's field or setter is reassigned.
Mutating fields of complex parameter objects can lead to unexpected results (for example, when one function changes the passed object in a way that affects the outer function's result) and reduce readability and maintainability of the code.
Example
❌ Bad:
class SomeClass {
var flag = true;
set value(String value) {
...
}
}
void function(SomeClass some) {
some.flag = false; // LINT: Avoid mutating parameters.
some.value = 'hello'; // LINT: Avoid mutating parameters.
}
✅ Good:
class SomeClass {
var flag = true;
set value(String value) {
...
}
}
SomeClass function(SomeClass some) {
final newValue = SomeClass();
newValue.flag = false;
newValue.value = 'hello';
return newValue; // Correct, returning a new object instead
}