avoid-passing-self-as-argument
Warns when an object is used as an argument to its own method.
Example
❌ Bad:
void main() {
final list = [1, 2, 3];
// LINT: This object is used as an argument to its own method.
// Try using a different argument or rewriting the method implementation.
list.addAll(list);
final object = Some();
// LINT: This object is used as an argument to its own method.
// Try using a different argument or rewriting the method implementation.
object.work(object);
final another = Another([1, 2, 3]);
// LINT: This object is used as an argument to its own method.
// Try using a different argument or rewriting the method implementation.
another.values.addAll(another.values);
}
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); // Correct, another argument
final another = Another([1, 2, 3]);
another.values.addAll(anotherList);
}