Skip to content

Commit

Permalink
Merge branch 'better-reporting'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonase committed Mar 13, 2012
2 parents f2280ed + aa3fd93 commit 058c7c6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
18 changes: 13 additions & 5 deletions src/jonase/kibit/rules/control_structures.clj
Expand Up @@ -16,8 +16,16 @@
(comment
(when (not (pred? x y)) (f x y))

(when true
(if (pred? x)
(do
(action a)
(action b)))))
(if (pred? x)
(do (action a)
(action b)
(if-let [x (f a b c)
y (g a b c)
z (h a b c)]
(do (+ 1 0)
(= 1 1)
(< 1 0)))
(action d)
(action f))
nil))

27 changes: 24 additions & 3 deletions src/leiningen/kibit.clj
@@ -1,7 +1,24 @@
(ns leiningen.kibit
(:require [clojure.tools.namespace :as clj-ns]
(:require [clojure.string :as string]
[clojure.tools.namespace :as clj-ns]
[clojure.java.io :as io]
[jonase.kibit.core :as kibit]))
[clojure.pprint :as pp]
[jonase.kibit.core :as kibit])
(:import [java.io StringWriter]))

;; A hack to get the code indented.
(defn pprint-code [form]
(let [string-writer (StringWriter.)]
(pp/write form
:dispatch pp/code-dispatch
:stream string-writer
:pretty true)
(->> (str string-writer)
string/split-lines
(map #(str " " %))
(string/join "\n")
println)))


(defn kibit
"Suggest idiomatic replacements for patterns of code."
Expand All @@ -14,5 +31,9 @@
(or (second (clj-ns/read-file-ns-decl source-file)) source-file))
(with-open [reader (io/reader source-file)]
(doseq [{:keys [line expr alt]} (kibit/check-file reader)]
(printf "[%s] Consider %s instead of %s\n" line alt expr)))
(printf "[%s] Consider:\n" line)
(pprint-code alt)
(println "instead of:")
(pprint-code expr)
(newline)))
(flush))))

0 comments on commit 058c7c6

Please sign in to comment.