Skip to content

Commit

Permalink
#3: adding options to yagni
Browse files Browse the repository at this point in the history
  • Loading branch information
tolitius committed Jul 27, 2016
1 parent 4cc16f1 commit 227ea48
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
5 changes: 4 additions & 1 deletion build.boot
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
(deftask test-yagni []
(set-env! :source-paths #{"src" "test"})
(comp
(check/with-yagni)))
(check/with-yagni)
(check/with-yagni :options {:entry-points ["test.with-yagni/-main"
"test.with-yagni/func-the-second"
42]})))

(deftask test-eastwood []
(set-env! :source-paths #{"src" "test"})
Expand Down
8 changes: 3 additions & 5 deletions src/tolitius/boot_check.clj
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@
(deftask with-yagni
"Static code analyzer for Clojure that helps you find unused code in your applications and libraries.
This task will run all the yagni checks within a pod.
At the moment it takes no arguments, but behold..! it will."
[]
This task will run all the yagni checks within a pod."
[o options OPTIONS edn "yagni options edn map"]
(let [pod-pool (make-pod-pool (concat pod-deps yagni-deps) bootstrap)]
(core/with-pre-wrap fileset
(yagni/check pod-pool fileset) ;; TODO with args
(yagni/check pod-pool fileset options)
fileset)))

(deftask with-eastwood
Expand Down
21 changes: 17 additions & 4 deletions src/tolitius/checker/yagni.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
(def yagni-deps
'[[venantius/yagni "0.1.4" :exclusions [org.clojure/clojure]]])

;; yagni implementation (07/26/2016) is coupled with a lein specific file
(defonce entry-points-file ".lein-yagni")

(defn- pp [s]
(s/join "\n" s))

Expand All @@ -21,15 +24,25 @@
(when no-parent-refs
(boot.util/warn (str "\nWARN: the following have references to them, but their parents do not:\n\n" (pp no-parent-refs) "\n"))))

(defn check [pod-pool fileset & args]
(defn create-entry-points [entry-points]
(when entry-points
(->> (interpose "\n" entry-points)
(apply str)
(spit entry-points-file))))

(defn check [pod-pool fileset {:keys [entry-points]}]
(let [worker-pod (pod-pool :refresh)
sources (fileset->paths fileset)]
(pod/with-eval-in worker-pod
(boot.util/dbug (str "yagni is about to look at: -- " '~sources " --"))
(boot.util/dbug (str "yagni is about to look at: -- " '~sources " --"
(if '~entry-points
(str "\nwith entry points -- " '~entry-points " --")
"\nwith no entry points")))
(require '[yagni.core :as yagni]
'[yagni.graph :refer [find-children-and-parents]]
'[tolitius.checker.yagni :refer [check-graph report]])
(let [graph# (binding [*ns* (the-ns *ns*)]
'[tolitius.checker.yagni :refer [check-graph report create-entry-points]])
(let [graph# (binding [*ns* (the-ns *ns*)]
(create-entry-points '~entry-points)
(yagni/construct-reference-graph '~sources))
problems# (check-graph find-children-and-parents graph#)]
(if (seq problems#)
Expand Down

0 comments on commit 227ea48

Please sign in to comment.