avoid-passing-self-as-argument
preset: recommended
Warns when an object is used as an argument to its own method.
Example
❌ Bad:
void main() {
final list = [1, 2, 3];
list.addAll(list); // LINT
final object = Some();
object.work(object); // LINT
final another = Another([1, 2, 3]);
another.values.addAll(another.values); // LINT
}
class Some {
void work(Some another) {}
}
class Another {
final List<int> values;
const Another(this.values);
}
✅ Good:
void main() {
final list = [1, 2, 3];
final anotherList = [4, 5, 6];
list.addAll(anotherList);
final another = Another([1, 2, 3]);
another.values.addAll(anotherList);
}
class Another {
final List<int> values;
const Another(this.values);
}