Skip to content

Add a warning similar to UNUSED_IMPORT for doc imports that are unused. #55414

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

Open
kallentu opened this issue Apr 9, 2024 · 3 comments
Open
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-warning Issues with the analyzer's Warning codes P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@kallentu
Copy link
Member

kallentu commented Apr 9, 2024

Currently, you can add doc imports to any library whether or not it's used in any references.

/// @docImport 'libb.dart'; // unused and has no warning
library a;

/// Test doc comment
class A {}

It would be nice to have it report UNUSED_IMPORT or UNUSED_DOC_IMPORT when the doc import isn't being used for any reference resolving so we can avoid unnecessary doc imports (and also see that it will actively be used).

cc. @srawlins @goderbauer

@kallentu kallentu added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. devexp-warning Issues with the analyzer's Warning codes labels Apr 9, 2024
@goderbauer
Copy link
Contributor

It should probably also warn if libb.dart is imported as a regular import and hence its doc import is unnecessary/duplicated?

Loosely related: It would also be nice to warn on regular imports if they are only used for a doc reference. The warning should tell people to use a doc import instead.

@bwilkerson
Copy link
Member

It would be nice to have it report UNUSED_IMPORT or UNUSED_DOC_IMPORT when the doc import isn't being used ...

Agreed. I'd lean toward making it a new diagnostic (UNUSED_DOC_IMPORT sgtm) because I think that the problem message, correction message, diagnostic documentation, and fixes are all likely to be different.

It should probably also warn if libb.dart is imported as a regular import and hence its doc import is unnecessary/duplicated?

Loosely related: It would also be nice to warn on regular imports if they are only used for a doc reference. The warning should tell people to use a doc import instead.

Yes, and yes.

@FMorschel
Copy link
Contributor

Loosely related: It would also be nice to warn on regular imports if they are only used for a doc reference. The warning should tell people to use a doc import instead.

I think #59741 would be the issue for this.

@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-warning Issues with the analyzer's Warning codes P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants