Merge branch 'better-reporting'
This commit is contained in:
commit
058c7c66f2
2 changed files with 37 additions and 8 deletions
|
@ -16,8 +16,16 @@
|
||||||
(comment
|
(comment
|
||||||
(when (not (pred? x y)) (f x y))
|
(when (not (pred? x y)) (f x y))
|
||||||
|
|
||||||
(when true
|
|
||||||
(if (pred? x)
|
(if (pred? x)
|
||||||
(do
|
(do (action a)
|
||||||
(action a)
|
(action b)
|
||||||
(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))
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,24 @@
|
||||||
(ns leiningen.kibit
|
(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]
|
[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
|
(defn kibit
|
||||||
"Suggest idiomatic replacements for patterns of code."
|
"Suggest idiomatic replacements for patterns of code."
|
||||||
|
@ -14,5 +31,9 @@
|
||||||
(or (second (clj-ns/read-file-ns-decl source-file)) source-file))
|
(or (second (clj-ns/read-file-ns-decl source-file)) source-file))
|
||||||
(with-open [reader (io/reader source-file)]
|
(with-open [reader (io/reader source-file)]
|
||||||
(doseq [{:keys [line expr alt]} (kibit/check-file reader)]
|
(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))))
|
(flush))))
|
||||||
|
|
Loading…
Reference in a new issue