Making a Simple Dead Code Finding Tool for Clojure
A coworker expressed the need for finding unused Clojure functions. While we could've done something simple like regexes on lines with defn
's to find symbols and then simple string searches to see if those substrings were used again, we realized that Clojure's namespaces were quite nice to work with, most notably the ns-interns
function which allowed us to find which symbols are defined in which namespaces. Additionally since Clojure is homoiconic, we could just read the source with read-string
and do direct symbol comparisons while doing a walk over the entire codebase.
About an hour later, we killed a good amount of our codebase (which is one of the most satisfying feelings)!
While it's quite simple for now, it's hopefully the first of many awesome static analysis tools that we can build for ourselves (and hopefully for the community as well).