Allow custom kibit rules

project.clj will need to have following entry

:kibit {:rules (merge kibit.rules/rule-map
                      {:ctrl test/rules})
        :source-paths ["rules"]}

All namespaces found in source-paths dir will be required during kibit
run.

Update kibit version in project.clj and 'kibit-project'
This commit is contained in:
Kapil Reddy 2015-08-20 10:36:08 +05:30 committed by Daniel Compton
parent df4fa32160
commit ad64732baa
2 changed files with 22 additions and 10 deletions

View file

@ -3,5 +3,6 @@
:url "https://github.com/jonase/lein-kibit" :url "https://github.com/jonase/lein-kibit"
:license {:name "Eclipse Public License" :license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"} :url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[jonase/kibit "0.1.2"]] :dependencies [[jonase/kibit "0.1.2"]
[org.clojure/tools.namespace "0.2.11"]]
:eval-in-leiningen true) :eval-in-leiningen true)

View file

@ -1,17 +1,28 @@
(ns leiningen.kibit (ns leiningen.kibit
(:require [leiningen.core.eval :refer [eval-in-project]])) (:require [leiningen.core.eval :refer [eval-in-project]]
[clojure.tools.namespace.find :refer [find-namespaces]])
(:import [java.io File]))
(defn ^:no-project-needed kibit (defn ^:no-project-needed kibit
[project & args] [project & args]
(let [kibit-project '{:dependencies [[jonase/kibit "0.1.2"]]} (let [src-paths (get-in project [:kibit :source-paths] ["rules"])
paths (seq (disj (set (concat kibit-project `{:dependencies [[jonase/kibit "0.1.2"]]
(:source-paths project) :source-paths ~src-paths}
[(:source-path project)] paths (seq (disj (set (concat (:source-paths project)
(mapcat :source-paths (get-in project [:cljsbuild :builds])) [(:source-path project)]
(mapcat :source-paths (get-in project [:cljx :builds])))) (mapcat :source-paths (get-in project [:cljsbuild :builds]))
(mapcat :source-paths (get-in project [:cljx :builds]))))
nil)) nil))
src `(kibit.driver/external-run '~paths ~@args) rules (get-in project [:kibit :rules])
req '(require 'kibit.driver)] src `(kibit.driver/external-run '~paths
(when ~rules
(apply concat (vals ~rules)))
~@args)
ns-xs (mapcat identity (map #(find-namespaces [(File. %)]) src-paths))
req `(do (require 'kibit.driver)
(doseq [n# '~ns-xs]
(require n#)))]
(try (eval-in-project kibit-project src req) (try (eval-in-project kibit-project src req)
(catch Exception e (catch Exception e
(throw (ex-info "" {:exit-code 1})))))) (throw (ex-info "" {:exit-code 1}))))))