-
Notifications
You must be signed in to change notification settings - Fork 30
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 depend_on_referenced_packages
for core lints inclusion
#42
Comments
sgtm @goderbauer wdyt? |
LGTM. |
We don't, I would be happy to write it but I am not sure exactly how to in the current linting framework - you need to collect all the referenced deps by visiting all the dart files and then lint on the pubspec. cc @pq Note however that I would not suggest adding this particular lint to the core set, maybe not even recommended, because there are valid reasons to have a dep on a package that you do not import in Dart files. You may be depending on some other assets it exposes (fonts, images, etc). Or in the case of the |
No, we don't. We can see when an import is referencing a package that isn't listed in the dependencies by examining two files. To catch the case where a dependency isn't referenced we'd need to analyze all of the files in the package. Neither the analyzer nor the linter are architected to make that efficient. |
In terms of the schedule for adding this to |
There is a bit of chicken/egg situation in that it probably won't actually get much adoption (and thus validation) until it is included in some default (non-prerelease) lint set. I definitely agree with the sentiment, but I am not sure what the best way is to actually get the most validation before shipping it. We could certainly validate it on our own repos, and that might be enough? I have tested it on a few of the larger ones (build & test), and some packages in the SDK. |
I think we can get good feedback before this is added to
I think a lot of people will be interested in this lint - I'm sure we'll get some traction in a beta release. We could also validate through google3 for some of the lints. |
For a lint which had been implemented for a while, I wouldn't have concerns about just adding it to the set of recommended lints. For a newly authored lint though, I think we want to find a few more click stops before turning it on for everyone. |
Ya that is a good idea, I am not on social media really myself so I would have to rely on others for this.
Unfortunately this lint doesn't apply to google3, but in general ya that is I think a good strategy.
Ya I definitely agree, not pushing back on the idea. What I want is just to figure out how to actually get it in the hands of people so we can get that validation we want :). |
I think this lint would be a good addition. I also agree with @devoncarew that we should wait a little until the lint has matured a little. We should also enable it for the flutter repositories (flutter/flutter, flutter/engine, flutter/packages, flutter/plugins) and verify that it doesn't cause any issues there. |
This should likely be blocked on fixing dart-lang/sdk#58425 |
this is under consideration for core lint inclusion: dart-lang/lints#42 (also undoubtably nice to get the early warning.) Change-Id: I3ea204444f48d3b4bde3ff65b4ce85a2cf2a7b11 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/202301 Commit-Queue: Phil Quitslund <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
Approved assuming we fix dart-lang/sdk#58425 first |
@pq Would it be possible to add an auto-fix for that? (i.e. should this issue be labeled "should have a dart fix"?) |
We should investigate. I'm not 100% sure if we have enough information to generate a sensible version constraint (though I guess we could default to /fyi @bwilkerson |
Not sure if you can run pub commands, but you could just do |
Calling But last I talked to @bwilkerson about it, we would likely have to give But maybe just adding |
Oh nice I didn't know that was this smart 👍 |
So we do call pub apis for completions (see |
But I could be convinced to add a |
If this lint is reported, but errors are not present, then the package is available as a transitive dep. This should mean it is available in PubPackageService.cachedPackages, yes? So using this info we could add We could also just add We could also wait for |
If there is a desire for |
This is a new lint which hasn't shipped in the sdk yet but will in the next lint release.
What it does is ensure that you have a dependency (or dev dependency) in your pubspec if you import a package. There should be no valid situation where you import a package and don't depend on it in your pubspec, and there should be no false positives for this lint.
Not depending on a package but importing it means you are relying on it being available as a transitive dep which is risky (it could disappear at any time). It also means that you have no dependency constraint on it and could be broken by the package if it has a breaking change.
Note that
pub lish
already warns about this and may negatively score already, so we would want to avoid a duplicate negative score - @jonasfj might know more about the existing behavior.The text was updated successfully, but these errors were encountered: