make normalize-keywords walk clj[cdx]? files in specified location (#1420) [skip ci]

This commit is contained in:
Max Penet 2022-11-16 17:01:39 +01:00 committed by GitHub
parent 3751749ca3
commit b57981bcd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,6 @@
(ns normalize-keywords
(:require [babashka.pods :as pods]
[clojure.java.io :as io]
[rewrite-clj.node :as node]
[rewrite-clj.zip :as z]))
@ -9,10 +10,9 @@
(def code (first *command-line-args*))
(def findings
(->> (with-in-str code
(clj-kondo/run! {:lint [code]
:config {:output {:analysis {:keywords true}}}}))
(defn findings [file-path]
(->> (clj-kondo/run! {:lint [file-path]
:config {:output {:analysis {:keywords true}}}})
:analysis
:keywords
(filter (some-fn :alias :auto-resolved))))
@ -33,6 +33,11 @@
zloc (z/replace zloc (node/coerce k))]
(recur zloc (next findings)))
(recur (z/next zloc) findings)))
(println (str (z/root zloc))))))
(str (z/root zloc)))))
(remove-locs (z/of-file code) findings)
(doseq [f (file-seq (io/file code))
:when (re-find #"\.clj[cdx]?$" (str f))
:let [file-path (str f)]]
(when-let [findings' (findings file-path)]
(prn (format "Rewriting %s" file-path))
(spit f (remove-locs (z/of-file file-path) findings'))))