-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add lint warning about recommended import style #57700
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
Comments
This has come up a bunch. Thanks for the report! cc @bwilkerson |
The most critical piece is that you be consistent when a library inside |
I have only seen such issues in Flutter projects, where the entry-point file is in This is because Flutter violates the pub package convention by having entry-point files in I haven't experienced or seen mentioned issues where package and relative imports were mixed within
Honestly if this is a requirement, in my opinion the only sane solution is to remove relative imports from the language entirely, because the cause of potential issues far outweighs the benefit of relative imports. Not even linter rules that point out conflicts could make up for that. |
Unfortunately, relative imports are required when a library outside of |
In light of that, how about a rule that flags all relative imports to files in |
I still think the only issue is the invalid entry point file flutter expects in |
related #33076 |
Any progress or more thoughts on this? I would really like a lint to only allow package imports in /lib. |
I'm not opposed to having such a lint, similar to |
I have some code which confused me for a while.
main.dart
import 'package:kbml_viewer/globals.dart';
import 'preferences/preferences_description_list.dart';
preferences_description_list.dart
import '../globals.dart';
The main page displays the preferences_description_list (a list of descriptions).
The main page, has a preferences page button and that preferences page also displays a variant of the same list (e.g. can also delete items from the list).
When displaying the list from the main page I get an error :
When I display the list from the preferences page it works just fine. It confused me for a while since I am new to dart I thought I didnt write the singleton correctly.
I can fix the error, by either changing to :
import 'package:kbml_viewer/preferences/preferences_description_list.dart';
in the main page, or :
import 'package:kbml_viewer/globals.dart';
I realise I should not be mixing styles, but for beginners it would be nice to get some advice on the best style.
The text was updated successfully, but these errors were encountered: