-
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
Lint proposal: prefer static
member function
#57108
Comments
Personally I'd rather have a lint to suggest converting such functions to extension methods on the first argument: extension StringExtension on String {
void foo() {
print(this);
}
} Whether or not we have any lints like these, we should add assists for both transformations. |
This sounds like something that cannot be determined locally. If some other library calls |
@lrhn let me rephrase to make sure I understood correctly,
would also mean modifying all calls like finding all references to Could you clarify, when a function can locally become static and will result in something impossible for the caller? |
I believe that the comments from @lrhn are more related to the assist I suggested than the lint rule. We could certainly flag all instance methods that don't refer to |
If you convert a method to be a static function and all calls to be static function calls, then it should keep working - as long as nobody overrides the method. And as long as you can reference the type, which you should be for non-pathological code. That obviously assumes that the method can be static (doesn't reference |
Good point. And because lints can't see anything beyond the local context, such a lint might well have too many false positives to be useful. |
@bwilkerson From my understanding, only functions that could be static but are intended to be overridden would make a false positive. |
suggest all member functions that can be
static
example
suggest:
The text was updated successfully, but these errors were encountered: