Skip to content

Instantly share code, notes, and snippets.

Last active April 14, 2022 00:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save olivergeorge/600ea4630fc253cc02a0676f5d561829 to your computer and use it in GitHub Desktop.
most used keywords in codebase
(ns cnd.analyse-code
"Use rewrite-clj zipper to walk code.
* Doesn't use the (ns...) aliases to resolve aliases to full paths.
(:require [ :as io]
[ :as zip]
[ :as z]))
(defn find-all
[zloc pred]
(let [*ks (atom nil)]
(-> (zip/up zloc)
(fn select [zloc]
(let [expr (z/sexpr zloc)]
(when (pred expr)
(swap! *ks conj expr)))
(defn file? [f] (.isFile f))
(defn get-path [f] (.getPath f))
(defn all-source-files
(->> (io/file dir-path)
(filter file?)
(map get-path)))
(comment (all-source-files "src"))
(defn all-keywords
(mapcat (fn [file-path]
(find-all (z/of-file file-path) qualified-keyword?)
(catch Exception e
;(println file-path)
;(println e)
(defn most-used-keywords
(->> (all-source-files dir-path)
(sort-by val)
(take 20)))
(comment (most-used-keywords "src/cljs"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment