-
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
New lint: avoid_collection_methods_with_unrelated_types #57844
Comments
+💯 |
Here's another friendly ping for this – it'd be super useful! |
Taking a stab at this... |
@pq – sorry to get you excited. A bit out of my wheelhouse. Although it did inspire some cleanup. |
I was looking into combining this into one giant list that knew about the Set methods and List methods etc. And it knew that
|
Do you imagine that folks would want to enable only a sub-set of the proposed lints? (I'm trying to think why one mega-rule isn't the way to go.) |
I can't imagine a case where I'd want a subset of these.
…On Thu, Feb 28, 2019 at 1:11 PM Phil Quitslund ***@***.***> wrote:
I suspect that a lint rule *per class* might be the solution.
Do you imagine that folks would want to enable only a sub-set of the
proposed lints? (I'm trying to think why one mega-rule isn't the way to go.)
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#57844>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABCiliRuaAH17qLD1G4y283MFi_9hPwks5vSEYUgaJpZM4ZOLgP>
.
|
On the surface I'd agree. All of these are cases where we're catching an error at analysis time that otherwise wouldn't be caught until runtime. I'm not proposing that we do so, but if we took this to the extreme we would have a single lint rule that would subsume this and a lot of other lint rules. After all, why would users not want us to catch such things. We could also reasonably ask why these aren't hints rather than lints so that users don't even need to opt in. The answer, in my mind, is that these are lints because they can have false positives. Given the following
it seems obvious that
and are careful to only call False positives are why they're lints rather than hints. It's also the reason we might want to split them up into multiple lints. By having a finer level of granularity we allow users to opt out of some checks without opting out of all of them. For example, consider
If we didn't want the lint on To be clear, I'm not advocating for either answer, just bringing up something that probably ought to be considered when deciding. |
I'm mostly commenting to try to help with searching, but I recently found a bug where I accidentally typed |
Note that the same trade-off has been made in Java: Java.util.HashSet also has an @MichaelRFairhurst just suggested on an internal mailing list that we could use a range (an upper bound type which is used like today's type annotations, and a lower bound which is used to statically reject any actual arguments which are not assignable, in this case: to the collection element type). That could be a language feature, but if it is restricted to the specific members mentioned here and uses the element type as the lower bound then I believe that it's the same thing as the lint which is proposed here. |
I'd love to dig back in here – I keep hitting this! |
It would be interesting to implement this and run it on some representative repos and see if anything interesting shakes out... @kevmoo: out of curiosity, where are you hitting this most? |
I hit it when working with *redacted* customer demos. This is a common
source of bugs that usually get fixed – but they take a while to find!
…On Fri, Apr 19, 2019 at 3:24 PM Phil Quitslund ***@***.***> wrote:
It would be interesting to implement this and run it on some
representative repos and see if anything interesting shakes out...
@kevmoo <https://github.com/kevmoo>: out of curiosity, where are you
hitting this most?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#57844>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAEFCUTLRAN2WKU5GOHKIDPRJBB3ANCNFSM4GJYXAHQ>
.
|
Is this still on the agenda? Is there perhaps some improvement coming in the wake of NNBD? I keep hitting this very often since I am frequently switching between IDs and whole records as keys during refactorings, turning maps of the type |
Hi another year has passed... I do hope this can be implemented - it is sooooooo useful! |
I believe that this has languished more from a lack of resources than any lack of support. Community contributions are always welcome. |
I want to contribute. But seems that I cannot implememt one and directly use it now :/ have to wait for a release (months!) |
@fzyzcjy: are you able to use |
@pq Unfortunately, no :( I am writing flutter for a app already on app store... |
The feature is implemented in this PR: dart-code-checker/dart-code-metrics#705 |
WIP at dart-lang/linter#3692 for an implementation in linter. |
Bug: https://github.com/dart-lang/linter/issues/1307 Change-Id: Ia62aa7715509a45eb9fb0feb48c58ffee551db34 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/259506 Commit-Queue: Samuel Rawlins <srawlins@google.com> Reviewed-by: Phil Quitslund <pquitslund@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This is a more general request related to #57434 – which only deals with
remove
(list_remove_unrelated_type) and the other existingiterable_contains_unrelated_type
There are more methods on Set and Map that could be generalized here.
[]
and[]=
We'd need to be thoughtful about the
Set
methods – but at first glance I think linting all of them is reasonable.CC @srawlins @bwilkerson @a14n
The text was updated successfully, but these errors were encountered: