Skip to content

Instantly share code, notes, and snippets.

@bartojs
Created December 3, 2015 00:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bartojs/83a096ecb1221885ddd1 to your computer and use it in GitHub Desktop.
Save bartojs/83a096ecb1221885ddd1 to your computer and use it in GitHub Desktop.
formatter for clojure using cljfmt
;; boot fmt -f myfile.clj
;; boot fmt -f src
;; -- it will change files inplace
(set-env! :dependencies '[[cljfmt "0.3.0"]])
(require '[cljfmt.core :as fmt]
'[clojure.java.io :as io])
(defn fmt-file [f]
(println "formatting" (.getName f))
(spit f (fmt/reformat-string (slurp f))))
(defn clj-file? [f]
(and (.exists f) (.isFile f) (not (.isHidden f))
(contains? #{"clj" "cljs" "cljc" "cljx" "boot"}
(last (.split (.toLowerCase (.getName f)) "\\.")))))
(deftask fmt [f files VAL str "file(s) to format"]
(let [f (io/file files)]
(when (.exists f)
(doall (map fmt-file (filter clj-file? (if (.isDirectory f) (file-seq f) [f])))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment