how can I analyze dart code to remove duplicate classes?

531 Views Asked by At

this question is about static analysis of dart code. How can I analyze the dart code or visit the each class within a dart file so I could remove the duplicate class, I know these tools exists but i don't know how exactly implement it PS:duplicate class exists due to code generation using quicktype.

//psuedo code
classes = readTheDartFileSomeHow();
var map = Map<string,string>()
for (final myClass in classes){
 map.putIfAbsent(myClass.name,myClass);
}
1

There are 1 best solutions below

2
On

You can try develop custom plugin to Dart Analyzer and add it to your project. Start with Official Tutorial for get a short overview about how it works.

Also, community has some custom plugins and you can explore source code for find useful practises (for example: dart-code-metrics) and dart-enum-to-string-check).