-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Feature Request: Linter Rule for Explicit Imports Using show
or as
#60461
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
FYI @Wdestroier JIC you know some people that would like this idea. |
As a note, @frank-weindel; The issue above should have various related links of issues/fixes that make this request easier to follow today (just pointing because there are still some fixes/enhancements that will only be available on Dart 3.8 - you can see that by opening the mentioned cobybara commit and looking at the tags). |
I'm also interested to know what the community thinks of such a rule. I'm guessing, though, that we aren't likely to include this in any of the standard rule sets (core, recommended, or flutter), and that might prevent us from implementing it.
I don't know whether you use parts in your code, but this doesn't negate the need to traverse to the defining compilation unit to see what's being imported, though it would still help once you've navigated there. I'll just note that the enhanced parts feature will also have some impact on readability by allowing different parts in a library extend the imports from the parent compilation unit. It isn't clear yet what kind of support users will need if this feature becomes more widely used (outside of code generators), but we should consider the implications of the feature when designing the lint. |
Good idea! I would keep this lint enabled, because currently I need to keep an eye in the import section to check if I didn't import anything without the show clause by accident. Can the lint have an option to ignore files? For example: ignore:
- 'package:flutter/material.dart' |
@Wdestroier, currently, no lints accept configurations, here is the issue requesting this #57673. |
I have a section in my request covering that case. |
Are there any set criteria for new rules to be added that don't fall into one of those three categories? |
Not at this point, no. We've been needing for a while to create a set of criteria for what we think we should be supporting and what we think should depend on the community to support, but so far we haven't done so. |
Similar to JavaScript/TypeScript ES Module syntax, create a linter rule that forces developers to explicitly
show
every imported symbol (e.g., classes, functions, constants, extensions) from a library or use theas
keyword to explicitly import an entire library under a namespace alias symbol. This rule could be used by teams that would like to opt-in to have it be clear from the top of every file what library each symbol comes from. While static analysis and hovering over a symbol in an IDE can help you find what library something comes from, it is not possible to tell from a Pull Request/file view in GitHub or by simply looking at a raw file. Such a lint rule would make the code more readable when IDE tooling is not available. This lint rule should also be automatically fixable using tooling that exists today.I'm curious what thoughts the Dart community has for such a rule. I'm a relatively new Dart developer so I'm sure I'm missing some important implications for such a rule and the encouraged use of it.
Justification
show
keyword.Examples
Allowed
Disallowed
Further Thoughts
Performance Impact
This rule should have minimal performance impact during linting, as it primarily analyzes import statements and their usage within a file.
Configuration Options
The rule could include configuration options such as:
dart:core
,package:flutter/material.dart
)hide
would be allowed for these libraries.as
namespace aliases.as
for stylistic reasons.Naming
Rule name ideas:
explicit_imports
explicit_symbol_imports
no_implicit_imports
require_explicit_imports
The text was updated successfully, but these errors were encountered: