Created
December 3, 2015 00:24
-
-
Save bartojs/83a096ecb1221885ddd1 to your computer and use it in GitHub Desktop.
formatter for clojure using cljfmt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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