-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DISABLED] Lint to prefer using a public final field instead of a private field with a public getter (Style Guide) #57169
Comments
This rule makes only sense when the field is set directly from an argument passed in with every constructor (this.xxx or constructor initialzer list). Otherwise the linter just complaints about every field which is read-only in the public interface but writeable in the private interface. I can't see anything bad about it in the later case. |
@zoechi 👍 In fact, the advice "Make it |
Opened corresponding bug: #57183. |
Disabled pending fix of #57183. |
One way you could make this lint simpler - and not have to scan the entire library for member access is:
You could also add another lint which checks for accidental usage of class private members. (i.e. members which are not annotated as shared) I'm not sure if this level of strictness would be useful practise. But I'm sure some people, especially those coming from C# or Java would like to use it. Writing helper code to scan an entire library for member usage will be helpful for other lints, so in the long run it's probably worth doing this correctly anyway. |
I didn't realize this issue existed when I created dart-lang/site-www#2971. |
If we want to pursue this, let's start with a fresh proposal. |
From the style guide:
PREFER using a public final field instead of a private field with a public getter.
If you have a field that outside code should be able to see but not assign to (and you don’t need to set it outside of the constructor), a simple solution that works in many cases is to just mark it
final
.GOOD:
BAD:
The text was updated successfully, but these errors were encountered: