Open lukepighetti opened 3 years ago
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:
package:analyzer
Hopefully that helps!
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.