-
Notifications
You must be signed in to change notification settings - Fork 170
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
Add a new unnecessary_late
lint
#3052
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💎
Right. Many seem to be harder to reliably check though making them not good candidates for a general lint. My thinking there is that if there are such cases we may want to lint specifically for them. Anyway, this is just a long way around to saying I think that I'll add a few more folks to get their 2 cents, especially since I think this is a good candidate for inclusion in the core or recommended lint sets. /fyi 📟 @jakemac53 @natebosch @munificent @lrhn @eernstg @leafpetersen Thanks as always @parlough for the contribution! |
I think detecting a local One other unnecessary |
@bwilkerson Is this above currently feasible within the linter? If I'm understanding correctly, I believe this would require some sort of access to flow analysis, but I'm not sure what is exposed there. |
My current understanding, though I'm not very familiar with that code, is that it would be possible, but a fair amount of work, to use the flow analysis code to test these conditions. The flow analysis support isn't part of the public API, so we'd probably want to add an API to It would be interesting to know how often local variables are marked |
Sorry for the lag on this. @parlough: any objection to landing as-is? |
@pq Yeah I'm happy with this lint in the current state. I won't have time to investigate exposing and accessing the flow analysis for now. |
Good deal. Thanks! |
* Add a new unnecessary_late lint * Sort lint implementation Dart file * Test non-late static and top-level declarations * Provide better matching examples in details
Adds a new
unnecessary_late
lint which will detect usages of the late modifierlate
on static and top-level variables which are evaluated as if they are marked withlate
already.I believe there are other situations where
late
may be unnecessary. The first that comes to mind is in a local variable declaration where the initializer will have no side effects. I have opted to not account for this and potential other more complicated situations currently(unless I'm missing something obvious). I was thinking other situations could be incorporated into this lint in the future, but if you think this should have a more specific name suchunnecessary_static_late
, let me know :)