Unused import tool
RazvanN
razvan.nitu1305 at gmail.com
Tue Aug 15 08:13:04 UTC 2023
Hello everyone,
I have started working on [a tool that identifies unused
imports](https://github.com/RazvanN7/Unused-Import/tree/master).
It uses dmd as a library.
The purpose is to have a working tool, but also to better
understand what sort of information the frontend needs to output
so that such tools are possible.
Up to this point, I managed to make it work with global imports
(since dmdfe currently does not provide the scope hierarchy). The
tool does output some false positives because semantic is
destructive and some things like aliases or enums are substituted
eagerly and you cannot trace their origin.
I have tested this tool with some dmd sources and have already
identified [unused
imports](https://github.com/dlang/dmd/pulls?q=is%3Apr+delete+unused+imports+author%3ARazvanN7+is%3Aopen)ยท
So, if you have projects with lots of global imports you could
use it to at least narrow down the list of potential unused
imports.
The tool is a work in progress, so if you have any ideas for
improvement feel free to ping me.
Note that the import paths used are from my machine, so you will
need to update those accordingly to the files imported in your
project.
RazvanN
More information about the Digitalmars-d
mailing list