-
Notifications
You must be signed in to change notification settings - Fork 29
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
Consider adding deprecated_consistency
to recommended
#60
Comments
This seems like a tooling issue: Any use of a member or constructor of a class that is marked deprecated should be flagged. |
@mit-mit to file tools issue |
@goderbauer do you have an example of a case where you are not seeing a warning? I tried to create a class marked deprecated, and I get usage warnings on both static method calls and on constructor calls. |
@Piinks Do you remember where we saw the inconsistencies around deprecation that let us to adopting the |
Yes, say this is a (rough) API MyWidget(
this.myProperty
);
final int myProperty; If you do not put a deprecation annotation on both (the field member and the constructor parameter), then the user will not get a warning from the analyzer for the use case that is not deprecated. Further examples: MyWidget(
@Deprecated(...)
this.myProperty
);
// Users that access this property will not be warned
final int myProperty; MyWidget(
// Users of this parameter will not be warned
this.myProperty
);
@Deprecated(...)
final int myProperty; The lint makes sure both get the annotation. MyWidget(
@Deprecated(...)
this.myProperty
);
@Deprecated(...)
final int myProperty; |
cc @pq, is that fixable? |
Just to clarify, I think what you're asking is whether, at least for the purposes of deprecation warnings, we can consider fields and field initializing parameters to be equivalent. That is, if either is deprecated then we consider both to be deprecated. Personally, I don't have any problem with that, but we might want to update the documentation for |
I can see hypothetical cases where you want to deprecate one, and not both. Say, you want to make the field a getter computed from something else, and drop the parameter, So, I don't want to treat the two as equivalent, where annotating one will also deprecate the other. In practice, I think it's fine to temporarily use an That's a tentative "yes" from me to recommend the lint, and "no" to linking the deprecations, because then there is no way out of it if you really only mean to deprecate one. The lint description is:
The first item is unnecessary. If a class is deprecated, every member of it is also deprecated. The two other items are reasonable heuristics. As mentioned above, there can be false positives, but it's likely not a big issue. The lint documentation should say what to do in that case (use |
This has been approved for the |
An update - this is still approved, but we'll delay adding this to the lint set until after we have a fix for dart-lang/linter#4752 (comment) (and that fix has shipped in an sdk). |
@pq @lrhn - from the discussion here: dart-lang/linter#4752 (comment), are we considering this lint not necessary - that we should bake a version of |
I'd keep the lint, restricted to only warning about discrepancies in pairs of instance field/initializing formal (one, but not both, deprecated). It's a heuristic lint, it can have false positives, and probably false negatives. But it also applies rarely (requires something to be deprecated) and is easy to turn off (add an I want the lint description to say clearly that there can be false positives. In the (presumed) rare case of a field/initializing formal pair where you deprecate one and intend to keep the other, using (I don't want someone who uses This is a lint about two (or more) places in the code, so we should be clear on how they interact, including where If the field is deprecated, it should cause a warning for every non-deprecated initializing formal. That one's simple. If the field is not deprecated, but some initializing formals are, we have two choices:
The latter is "safer" (fewer warnings), but maybe not deprecating the other initializing formals was also a mistake. That will also means that we can treat each pair of (variable, initializing formal) independently Then we should make sure that the An An I'd allow the Then the guide would be:
WDYT? |
I have a CL that introduces such a check (first uploaded in March of 2021), that has not yet been able to land for various reasons that I won't go into here. Suffice it to say that warning about unnecessary ignores presents some social challenges. (Happy to talk about it more, but maybe in a different thread.)
I'm not saying that we couldn't enhance the current implementation to support what you're proposing, but the implementation we have today requires that the ignore comment be on either the same line as the beginning of the diagnostic's highlight region, or by itself on the line before the beginning of the highlight region. |
Let's hope we can do something. :)
So commenting the This diagnostic relates to two places in the code, the variable declaration and the initializing formal, being out of sync. I'm assuming we only make one diagnostic for it (or if we make two, we'll need two It's probably better to always report it at the initializing formal, because there can be more than one of those, An initializing formal is usually not that long, and easy to break onto a line of its own, so it should be easy to add a comment to that line, even if it might mean reformatting parameter list to give it a new line. SGTM. Aka:
This should be enough. Again, it's not going to be used often, it's likely that the comment goes away before the deprecated declaration, if any refactoring is done in anticipation. |
Correct. Given class B {
@Deprecated('soon')
Object? field;
B({this.field});
} there is a single diagnostic and the highlight covers
That was our reasoning too.
While that's possible, it isn't necessary. Either of the following solutions will also work: class B {
@Deprecated('soon')
Object? field;
// ignore: deprecated_consistency
B({this.field});
} or class B {
@Deprecated('soon')
Object? field;
B({this.field}); // ignore: deprecated_consistency
} |
Given the relative value we get from this lint, and the work necessary to fix it, we're unlikely to add this to our recommended lint set. Closing. |
It's frustrating to remove something that you think was properly deprecated only to discover that many users of it never saw the deprecation warning. Enabled in Flutter.
The text was updated successfully, but these errors were encountered: