Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom rules #139

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/kibit/check.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
;; where necessary.
;;
;; For more information, see: [rules](#kibit.rules) namespace
(def all-rules (map unifier/prep core-rules/all-rules))
(def all-rules core-rules/all-rules)

;; Reading source files
;; --------------------
Expand Down Expand Up @@ -205,6 +205,7 @@ into the namespace."
(merge default-args
{:resolution :toplevel}
(apply hash-map kw-opts))
rules (map unifier/prep rules)
simplify-fn #((res->simplify resolution) % rules)]
(check-aux expr simplify-fn guard)))

Expand All @@ -214,6 +215,7 @@ into the namespace."
(let [{:keys [rules guard resolution init-ns]}
(merge default-args
(apply hash-map kw-opts))
rules (map unifier/prep rules)
simplify-fn #((res->simplify resolution) % rules)]
(keep #(check-aux % simplify-fn guard)
((res->read-seq resolution) reader init-ns))))
Expand Down
13 changes: 8 additions & 5 deletions src/kibit/driver.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns kibit.driver
(:require [clojure.java.io :as io]
[kibit.rules :refer [all-rules]]
[kibit.check :refer [check-file]]
[kibit.reporters :refer :all]
[clojure.tools.cli :refer [cli]])
Expand Down Expand Up @@ -30,20 +31,22 @@
(sort-by #(.getAbsolutePath ^File %)
(filter clojure-file? (file-seq dir))))

(defn run [source-paths & args]
(defn run [source-paths rules & args]
(let [[options file-args usage-text] (apply (partial cli args) cli-specs)
source-files (mapcat #(-> % io/file find-clojure-sources-in-dir)
(if (empty? file-args) source-paths file-args))]
(mapcat (fn [file] (try (check-file file :reporter (name-to-reporter (:reporter options)
cli-reporter))
(mapcat (fn [file] (try (check-file file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep this on the same line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean something like this ?

(check-file file :reporter (name-to-reporter (:reporter options)
                                             cli-reporter)
            :rules (or rules all-rules))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just keeping the indentation and line wrapping the same as it was before. But looking at this more closely I see why you changed the wrapping.

:reporter (name-to-reporter (:reporter options)
cli-reporter)
:rules (or rules all-rules))
(catch Exception e
(println "Check failed -- skipping rest of file")
(println (.getMessage e)))))
source-files)))

(defn external-run
"Used by lein-kibit to count the results and exit with exit-code 1 if results are found"
[source-paths & args]
(if (zero? (count (apply run source-paths args)))
[source-paths rules & args]
(if (zero? (count (apply run source-paths rules args)))
(System/exit 0)
(System/exit 1)))