-
Notifications
You must be signed in to change notification settings - Fork 1.7k
deprecate avoid_returning_null
#58394
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
Comments
FWIW, it isn't clear to me that the rule has any value in a null safe world. If the return type is non-nullable, then returning null is a compiler error and a lint is useless. If the return type is nullable, then I'm proposing that we not produce a lint. Hence, I think the right course of action is to deprecate the lint and disable it in null safe code. |
Agreed. |
avoid_returning_null
to not trigger when a return type is nullableavoid_returning_null
@subzero911: we've been mulling over whether there's value in this lint really at all in the presence of nullability. Is there any reason you still have it enabled? |
Most likely, no. |
Thanks for the feedback. Much appreciated! |
dart-archive/linter#2750 addresses the false positive. |
Pushing ahead on this, I wonder if anyone has any misgivings wrt to deprecating /cc @bwilkerson @eernstg @lrhn ? |
The only question in my mind is how long we want to support users that have not fully migrated to null-safety. It might still be useful for code that's opted out. |
I can't see any situations in code with null safety where |
I'm agnostic towards keeping the lint. In non-null-safe code, you should just disable it. |
Thanks for the feedback!
I was thinking about this too. We don't currently have a mechanism but our notion of I guess the question is just whether the complexity is worth it (and if it'd come in handy elsewhere) or if as @lrhn suggested, folks should just bite the bullet and disable the lint in non-null-safe code. @bwilkerson: I'd be curious to get your thoughts? (@srawlins fyi, this is somewhat relevant to our discussion of tags vs. categories in #57719.) |
We have several lints that are only enabled for certain ranges of language versions, and we could certainly do the same here, but I think it's useful to make a distinction between the language versions for which a rule can be applied and whether we still support the rule at all (which is what I think 'deprecated' means: we're removing support for the deprecated item). If it's deprecated then we produce a warning in the analysis options file, when it's remove we generate an error, but there shouldn't be any diagnostic if the rule is still supported but might not apply to all code. |
I understood @lrhn's idea to be that this lint is only enabled when it is applied to code in a library with version 2.12 or higher. Sounds like that would work just fine. |
@bwilkerson: that's a great point. We do have a number of lints that, like this one, contain a check like this: // This lint does not make sense in the context of nullability.
if (!context.isEnabled(Feature.non_nullable)) {
var visitor = _Visitor(this);
registry.addFunctionExpression(this, visitor);
registry.addMethodDeclaration(this, visitor);
} I wonder if it would be worth surfacing this in the lint description? (It feels like it would.) Aside: if we configured lints this way we could even push the conditional call to |
Isn't that backward? The original supposition is that the lint has no value in null-safe code, so we'd only want to enable it in code with a version prior to 2.12.
Yes, absolutely. |
Yep, that! Lint should be enabled only in pre 2.12 code, because in 2.12+ code it can't trigger without also being a compile-time error anyway. |
This is done. |
See: dart-archive/linter#2632 (comment)
The text was updated successfully, but these errors were encountered: