If a private field is initialized in the body of a constructor and could be replaced by a formal, a lint should be produce to move it to an initializer.
class MyClass {
Foo _foo;
MyClass.incorrect(Foo otherFoo) {
_foo = otherFoo; // LINT
...
}
// This could also enable other lints like declare _foo as final or remove constructor body.
MyClass.correct(Foo otherFoo) : _foo = otherFoo {
...
}
}
Kind of surprising that we don't have a rule yet for this; I guess it would be tricky to calculate whether the value (the right side) is something accessible in initializers.
If a private field is initialized in the body of a constructor and could be replaced by a formal, a lint should be produce to move it to an initializer.