Merge pull request #71 from RyanMcG/master
Add GFM reporter, Allow user to select reporter with CL option
This commit is contained in:
commit
ce7d9b6e63
4 changed files with 67 additions and 9 deletions
|
@ -7,6 +7,7 @@
|
|||
:comments "Contact if any questions"}
|
||||
:dependencies [[org.clojure/clojure "1.5.0-beta1"]
|
||||
[org.clojure/core.logic "0.8.0-beta2"]
|
||||
[org.clojure/tools.namespace "0.2.1"]]
|
||||
[org.clojure/tools.namespace "0.2.1"]
|
||||
[org.clojure/tools.cli "0.2.2"]]
|
||||
:dev-dependencies [[lein-marginalia "0.7.0"]]
|
||||
:warn-on-reflection false)
|
||||
|
|
|
@ -2,17 +2,22 @@
|
|||
(:require [clojure.tools.namespace :refer [find-clojure-sources-in-dir]]
|
||||
[clojure.java.io :as io]
|
||||
[kibit.check :refer [check-file]]
|
||||
[kibit.reporters :refer [cli-reporter]]))
|
||||
[kibit.reporters :refer :all]
|
||||
[clojure.tools.cli :refer [cli]]))
|
||||
|
||||
(def cli-specs [["-r" "--reporter"
|
||||
"The reporter used when rendering suggestions"
|
||||
:default "text"]])
|
||||
|
||||
(defn run [project & args]
|
||||
(let [source-files (if (empty? args)
|
||||
(let [[options file-args usage-text] (apply (partial cli args) cli-specs)
|
||||
source-files (if (empty? file-args)
|
||||
(mapcat #(-> % io/file find-clojure-sources-in-dir)
|
||||
(or (:source-paths project) [(:source-path project)]))
|
||||
args)]
|
||||
file-args)]
|
||||
(doseq [file source-files]
|
||||
(try (->> (check-file file)
|
||||
(map cli-reporter)
|
||||
doall)
|
||||
(try (check-file file :reporter (name-to-reporter (:reporter options)
|
||||
cli-reporter))
|
||||
(catch Exception e
|
||||
(println "Check failed -- skipping rest of file")
|
||||
(println (.getMessage e)))))))
|
||||
(println (.getMessage e)))))))
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
println)))
|
||||
|
||||
(defn cli-reporter
|
||||
"Print a check-map to `*out*`"
|
||||
"Print a check-map to `*out*` in plain text."
|
||||
[check-map]
|
||||
(let [{:keys [file line expr alt]} check-map]
|
||||
(do
|
||||
|
@ -36,3 +36,19 @@
|
|||
(pprint-code expr)
|
||||
(newline))))
|
||||
|
||||
(defn gfm-reporter
|
||||
"Print a check-map to `*out*` in github flavored markdown."
|
||||
[check-map]
|
||||
(let [{:keys [file line expr alt]} check-map]
|
||||
(printf "----\n##### `%s:%s`\nConsider using:\n" file line)
|
||||
(println "```clojure")
|
||||
(pprint-code alt)
|
||||
(println "```")
|
||||
(println "instead of:")
|
||||
(println "```clojure")
|
||||
(pprint-code expr)
|
||||
(println "```")
|
||||
(newline)))
|
||||
|
||||
(def name-to-reporter {"markdown" gfm-reporter
|
||||
"text" cli-reporter})
|
||||
|
|
36
test/kibit/test/reporters.clj
Normal file
36
test/kibit/test/reporters.clj
Normal file
|
@ -0,0 +1,36 @@
|
|||
(ns kibit.test.reporters
|
||||
(:require [kibit.reporters :as reporters]
|
||||
[clojure.string :as string]
|
||||
[clojure.test :refer :all]))
|
||||
|
||||
(deftest plain
|
||||
(are [check-map result]
|
||||
(= (with-out-str (reporters/cli-reporter check-map))
|
||||
(string/join "\n" result))
|
||||
{:file "some/file.clj"
|
||||
:line 30
|
||||
:expr '(+ x 1)
|
||||
:alt '(inc x)} ["At some/file.clj:30:"
|
||||
"Consider using:"
|
||||
" (inc x)"
|
||||
"instead of:"
|
||||
" (+ x 1)"
|
||||
"" ""]))
|
||||
(deftest gfm
|
||||
(are [check-map result]
|
||||
(= (with-out-str (reporters/gfm-reporter check-map))
|
||||
(string/join "\n" result))
|
||||
{:file "some/file.clj"
|
||||
:line 30
|
||||
:expr '(+ x 1)
|
||||
:alt '(inc x)} ["----"
|
||||
"##### `some/file.clj:30`"
|
||||
"Consider using:"
|
||||
"```clojure"
|
||||
" (inc x)"
|
||||
"```"
|
||||
"instead of:"
|
||||
"```clojure"
|
||||
" (+ x 1)"
|
||||
"```"
|
||||
"" ""]))
|
Loading…
Reference in a new issue