Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #71 from RyanMcG/master

Add GFM reporter, Allow user to select reporter with CL option
  • Loading branch information...
commit ce7d9b6e63b9641b8d201400903a8d88f0a5d3a6 2 parents 65b9fda + 09ada8b
@jonase authored
View
3  project.clj
@@ -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)
View
19 src/kibit/driver.clj
@@ -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)))))))
View
18 src/kibit/reporters.clj
@@ -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})
View
36 test/kibit/test/reporters.clj
@@ -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)"
+ "```"
+ "" ""]))
Please sign in to comment.
Something went wrong with that request. Please try again.