-
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
Lint for used package not defined in pubspec #29
Comments
Silly question: but wouldn't this result in a compilation error? |
If you specify X which depends on Y you can depend on Y. But if X later removes its dependency on Y, you'll be borked. |
Are we supposed to list all transitive dependencies in our pubspec ? |
@sethladd: absolutely not. We should have an explicit dependency for libraries with explicitly use. |
ah, yes! gotcha :) |
Is this doable? @pq @alexeieleusis @a14n ? T'would make many folks very happy |
We can certainly compute the information you're interested in. When linting each compilation unit, look for explicit references to elements defined in packages that are not explicitly depended on. We might need to cache the list of explicit dependencies somewhere to improve performance. What about implicit references? For example, given |
@bwilkerson – let's keep things crazy simple If import 'package:a/a.dart';
// or
export 'package:a/a.dart'; And |
...if the import/export directive is in a file in |
Is there a way to exclude code from that? For example when I want to share code between |
I would assume this would only be for *package:* imports...
…On Tue, Mar 6, 2018 at 1:32 PM, Günter Zöchbauer ***@***.***> wrote:
Is there a way to exclude code from that? For example when I want to share
code between test/ and example or as I had it in Flutter between test/
and test_driver/
I don't want to add dependencies used there to dependencies
It's not super important, but worth a thought.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#29 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABCisO2_wzByeZU5KpzpZIhQeK6ATQNks5tbwBWgaJpZM4Dgjlo>
.
|
...although it might be good to discuss an overall "lints for directives"
approach.
For instance, folks should NOT use relative directives in the lib direction
to things outside the lib directory...
…On Tue, Mar 6, 2018 at 1:36 PM, Kevin Moore ***@***.***> wrote:
I would assume this would only be for *package:* imports...
On Tue, Mar 6, 2018 at 1:32 PM, Günter Zöchbauer ***@***.***
> wrote:
> Is there a way to exclude code from that? For example when I want to
> share code between test/ and example or as I had it in Flutter between
> test/ and test_driver/
> I don't want to add dependencies used there to dependencies
> It's not super important, but worth a thought.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#29 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AABCisO2_wzByeZU5KpzpZIhQeK6ATQNks5tbwBWgaJpZM4Dgjlo>
> .
>
|
so if I have |
Every library inside of |
@bwilkerson but there is no valid way to import it from somewhere else, or is there? |
If you publish a package It's only by convention that other developers are expected to not reference code inside
Yes. Relative paths like this can reach any file and will work correctly for anyone that clones your repository as long as the path doesn't include directories outside your repository. We strongly discourage using relative paths inside of |
It's only for importing from other top-level directories inside the same package like |
Agreed! Thanks for following up. 👍 |
We've recently received at least a bug report in Flutter web where the user was using a transitive dependency (which was web only) in their Flutter app, and was wondering why their application was not compiling on Android. We're not sure how the "include" ended up in their code, but it might have been the user manually inputting it. I think a hint on the What needs to be done to write an efficient hint/lint? I have some experience with the AST visitors in @pq's tools; I expect something similar? |
Thanks for the added context @ditman. Very useful! @bwilkerson: putting aside API implications for a moment, is this something we can derive from an imported library's |
No, the namespace for an imported library contains all of the top-level names that are either defined in that library or are exported from other libraries by that library. What we'll need to do is parse the While the import certainly might have been hand entered, it's also possible for it to have been added automatically by server. I can think of several possibilities, and there are probably several I'm not thinking of:
If we add this lint we should consider adding a quick fix that adds an explicit dependency to the |
@bwilkerson If it were possible to know the version of the transient dependency, it'd probably be nice to set the version to that (or |
Agreed. We might be able to scrape the current version from the path in the |
@bwilkerson and I chatted and I see a path forward that would add support to |
Please, do reach out to me if I can be of any help! Thanks for considering this! |
https://dart-review.googlesource.com/c/sdk/+/134861 (Adds a |
See: dart-lang/linter#29 Change-Id: Ifcd4ad359a43c9183ab42ed6bb0ebb3586c73afd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134861 Commit-Queue: Phil Quitslund <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
Having thought about this some more, are we sure we want to limit this to pubspec dependencies? That is, are we likely to want similar behavior for /fyi @jacob314 |
We do have the same issues, but they're handled by the build system. It would be better to have a development time diagnostic rather than a build time error, but at least it gets caught, unlike in the pub case. |
I am curious what the status of this is - it is somewhat common to forget to add deps until you try to |
This is one of I think many opportunities for improvement wrt pub and analysis. /fyi @jonasfj |
One idea for how this could be implemented would be to have pub add its own field to the package_config.json with this information (list of direct deps) - and then internally we could do the same based on the build rules. Although I think that wouldn't help the IDE experience still internally. |
Hi, any update on this issue? |
Sorry, no real progress. @FufferKS: if you have any other context or experience to share, it'd be welcome. Is this an issue that you hit frequently? How does it impact you? Thanks for chiming in! |
I'm running into this issue pretty much on a daily bases. I'm working on a fairly large project that's separated into a number of packages. All of those depend on a "common" package with some core logic. The "common" package also depends on a number of public packages - bloc, etc. When working on any of the concrete packages, there is no hinting of e.q. bloc related classes. This forces me to make imports by hand, which is quite cumbersome. |
This is useful, thanks! Is the project open-source? (No worries if not but if it is, it would be useful for us to look at the structure to better understand how this and related issues are impacting folks.) |
Awesome. Thanks for this @FufferKS! /fyi @jakemac53 |
No description provided.
The text was updated successfully, but these errors were encountered: