You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm just poking around with dart_codemod and I was wondering if someone would be willing to suggest/discuss a strategy for finding unused classes.
My idea was to visit every class declaration and get the name of the class, then search the rest of the AST for any use of the constructor. I tried to walk the tree and wasn't successful.
Hi @lukepighetti! I think you'd need a fully resolved AST (or maybe an ElementVisitor) so that you can determine where each class is located in addition to its name, otherwise you could have classes that are distinct but named the same.
Either way, I'd probably start by writing a visitor that implements visitClassDeclaration to collect all of the classes, and then pass that info to another visitor that implements visitTypeName to determine which classes are unused. I haven't tested that idea, so there might be another visit method that would be better.. I can never quite keep all the analyzer APIs straight in my head :)
Couple other things to keep in mind:
Any class that is publicly exported from a package is technically "used" even if it doesn't have any usages in its own package.
Depending on what you want to do once you've found the unused classes, you might not even need this package - you might be able to get by with just package:analyzer
I'm just poking around with
dart_codemod
and I was wondering if someone would be willing to suggest/discuss a strategy for finding unused classes.My idea was to visit every class declaration and get the name of the class, then search the rest of the AST for any use of the constructor. I tried to walk the tree and wasn't successful.
The text was updated successfully, but these errors were encountered: