Kibit can now continually apply rules on a form until no further alternatives can be made

This commit is contained in:
Paul deGrandis 2012-03-23 01:44:15 -04:00
parent 8cd50e5299
commit 9278b06a46
2 changed files with 13 additions and 2 deletions

View file

@ -49,6 +49,17 @@
:alt alt
:line (-> expr meta :line)}))))))
(defn simplify-multipass
([expr]
(simplify-multipass expr all-rules))
([expr rules]
(loop [expr expr
simplify-map nil]
(if-let [new-simplify-map (simplify-one expr rules)]
(recur (:alt new-simplify-map)
new-simplify-map)
simplify-map))))
;; Guarding `simplify` allows for fine-grained control over what
;; gets passed to a reporter. This allows those using kibit
;; as a library or building out tool compatibility to shape
@ -78,7 +89,7 @@
(simplify expr rules unique-alt?))
([expr rules simplify-guard]
(let [line-num (-> expr meta :line)
simp-partial #(simplify-one %1 rules)
simp-partial #(simplify-multipass %1 rules)
alt (walk/postwalk #(or (-> % simp-partial :alt) %) expr)]
(simplify-guard
{:expr expr

View file

@ -19,7 +19,7 @@
nil '(if (> 2 3) :one :two)))
(deftest simplify-deep
(is (= '(when (zero? 0) :one)
(is (= :one
(:alt (kibit/simplify '(if (= 0 0) :one nil))))))
(deftest simplify-one