Analysis for unused code in a Django codebase
This is an idea that has been floating around my head for a long time in various forms. Currently it has been crystalised by me working on a codebase that has a lot of cruft such that URL patterns, views and templates exist, but are not actually currently used.
At a high-level the tool would use the following process:
- Analyse all templates, looking for plain internal
href
attributes and theurl
tag and then report these. - Then it would collate the urls and match them to the currently defined urlpatterns
- Which in turn is linked to views
- Which will mention template names again
From the following process the tool could then annotate files or produce a report that would list:
- Which views are referenced by a URL (and how many times)
- Which URLs are referenced in a template
- Which templates are referenced by views.
This is just the start of course, there are going to be templates from include
and extend
which would could be reported on during the template process or URLs referenced by reverse
or redirect
in other parts of the codebase.
I think this could be invaluable of getting a birds-eye view of a Django codebase, what do you think?