Modify run and external-run to accept custom rules

Create unifier/prep'ed rules inside check-expr and check-reader. This
makes passing custom rules simpler
This commit is contained in:
Kapil Reddy 2015-08-20 10:39:08 +05:30 committed by Daniel Compton
parent 1248c27251
commit 0cf7a62184
2 changed files with 14 additions and 9 deletions

View file

@ -28,7 +28,7 @@
;; where necessary.
;;
;; For more information, see: [rules](#kibit.rules) namespace
(def all-rules (map unifier/prep core-rules/all-rules))
(def all-rules core-rules/all-rules)
;; Reading source files
;; --------------------
@ -205,6 +205,7 @@ into the namespace."
(merge default-args
{:resolution :toplevel}
(apply hash-map kw-opts))
rules (map unifier/prep rules)
simplify-fn #((res->simplify resolution) % rules)]
(check-aux expr simplify-fn guard)))
@ -214,6 +215,7 @@ into the namespace."
(let [{:keys [rules guard resolution init-ns]}
(merge default-args
(apply hash-map kw-opts))
rules (map unifier/prep rules)
simplify-fn #((res->simplify resolution) % rules)]
(keep #(check-aux % simplify-fn guard)
((res->read-seq resolution) reader init-ns))))

View file

@ -1,5 +1,6 @@
(ns kibit.driver
(:require [clojure.java.io :as io]
[kibit.rules :refer [all-rules]]
[kibit.check :refer [check-file]]
[kibit.reporters :refer :all]
[clojure.tools.cli :refer [cli]])
@ -30,20 +31,22 @@
(sort-by #(.getAbsolutePath ^File %)
(filter clojure-file? (file-seq dir))))
(defn run [source-paths & args]
(defn run [source-paths rules & args]
(let [[options file-args usage-text] (apply (partial cli args) cli-specs)
source-files (mapcat #(-> % io/file find-clojure-sources-in-dir)
(if (empty? file-args) source-paths file-args))]
(mapcat (fn [file] (try (check-file file :reporter (name-to-reporter (:reporter options)
cli-reporter))
(catch Exception e
(println "Check failed -- skipping rest of file")
(println (.getMessage e)))))
(mapcat (fn [file] (try (check-file file
:reporter (name-to-reporter (:reporter options)
cli-reporter)
:rules (or rules all-rules))
(catch Exception e
(println "Check failed -- skipping rest of file")
(println (.getMessage e)))))
source-files)))
(defn external-run
"Used by lein-kibit to count the results and exit with exit-code 1 if results are found"
[source-paths & args]
(if (zero? (count (apply run source-paths args)))
[source-paths rules & args]
(if (zero? (count (apply run source-paths rules args)))
(System/exit 0)
(System/exit 1)))