Skip to content

package-level lint: unused, unexposed public members #57724

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
srawlins opened this issue Jun 21, 2018 · 13 comments
Open

package-level lint: unused, unexposed public members #57724

srawlins opened this issue Jun 21, 2018 · 13 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. customer-google3 devexp-linter Issues with the analyzer's support for the linter package linter-lint-request P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@srawlins
Copy link
Member

I'd like a lint rule that flags public library members (classes, top-level variables, typedefs, functions) and public class members (all the usual suspects) that are unused within their package, and not exposed from a library in the lib/ directory.

// lib/foo.dart

export 'src/foo.dart' show usedConstant;
// lib/src/foo.dart

// BAD
final unusedConstant = "CONSTANT";

final usedConstant = "CONSTANT";
@matanlurey
Copy link
Contributor

I don't see how this is possible for the analyzer, it won't necessarily know the entire scope of imports.

@srawlins
Copy link
Member Author

I thought the linter project had some aims to do package-level analysis? @pq is this done/feasible/planned?

@bwilkerson
Copy link
Member

It isn't currently implemented. I'm not sure whether we're going to get there. But I do think we want to do this kind of analysis (and I have a prototype implementation that I've been using on some of our packages).

@pq
Copy link
Member

pq commented Jun 21, 2018

Thanks for chiming in, @bwilkerson! Was just about to ping you. 😄

@chrisnorman7
Copy link

I'd like to add my support for this request too. I've been doing a lot of work with FFI bindings recently, and it would be nice to know what new functions ETC ffigen has created that I'm not yet using. Otherwise you have to go out and catalogue every function, and work out if you've already used it yet.

Unless I'm completely mis-writing bindings of course. That is more than possible.

@srawlins
Copy link
Member Author

srawlins commented May 3, 2021

I had forgotten about my linter request here 😆 and in fact, I think this is beyond what the linter does these days...

I have an internal proposal for Whole World analysis, which would enfold this. I think there are some great benefits to Whole World analysis, and would like to prioritize the feature.

@rrousselGit
Copy link

👋 Just dropping by to gently bump this.

It'd help detect a lot of dead code. Lots of members end-up public when splitting members across different libraries.
It's common that after a refactoring, some public class/function isn't removed even though it's now unused.

The same logic could be applied to dependencies too. It's common that after a refactoring, a package isn't used anymore yet isn't removed from the pubspec.yaml.

@incendial
Copy link
Contributor

It'd help detect a lot of dead code. Lots of members end-up public when splitting members across different libraries.
It's common that after a refactoring, some public class/function isn't removed even though it's now unused.

Have you tried DCM check-unused-code?

@incendial
Copy link
Contributor

@rrousselGit I see the reaction, but don't understand it though. Do you really need a real-time IDE highlight? If not, DCM can already show unused code from the CLI.

@rrousselGit
Copy link

Yes, real-time IDE highlight matters.

And you're asking to use a package. This is an important feature. I would expect this to be official, not community-based.

@incendial
Copy link
Contributor

Yes, real-time IDE highlight matters.

The only question is how it will affect the analyzer's performance.

And you're asking to use a package.

The package that already solves the problem with unused code (and other) while the Dart team can focus on more important (and mostly importantly unsolved) things. And yeah, in that terms analyzer is also a package.

I would expect this to be official, not community-based.

It kinda destroys the whole idea of having the community and community based packages if some features "are expected to be official". Don't see any particular reason for that.

@rrousselGit
Copy link

rrousselGit commented Mar 21, 2023

I don't think this is the right place to debate the validity of packages.
But anyway there's nothing wrong with you working on DCM, supporting this, and wanting to promote it. But that's not what's being discussed here.

I believe that this feature is important enough that it should be core to the SDK, like how many other lints are also core to the SDK.
This is in the end an extension of unused_element, one of the most used lint rules, to catch some false negatives.

@incendial
Copy link
Contributor

But that's not what's being discussed here.

I mean, you've pointed out to a specific problem giving impression of importance like it's not solved anyhow else which is not true (with the only argument why you can't use an existing solution is that it's not official). It has nothing to do with promoting DCM.

This is in the end an extension of unused_element

It might look like that from a user standpoint, but implementation wise it's not. Keeping all the references and updating them properly (taking into consideration multiple packages and that multiple drivers should not store same references multiple times, etc.) is a whole another level of problems. Checking usage for private variables is easy.

@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 18, 2024
@pq pq added the P3 A lower priority bug or feature request label Nov 20, 2024
@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 21, 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. customer-google3 devexp-linter Issues with the analyzer's support for the linter package linter-lint-request 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

8 participants