Skip to content

Commit

Permalink
Use check-file instead of check-reader.
Browse files Browse the repository at this point in the history
Also, make check-file include :file metadata.  Show that including the line
number in a more conventional compiler output format, which can be easily
exploited by tools such as Emacs.

For example, the following implements kibit support for Emacs, i.e., M-x kibit
RET will run kibit in the current project and show its results in a
*compilation* buffer, where all kibit suggestions are properly highlighted and
hyperlinked to the clojure source code files.

---------------------------------------------------------------
(require 'compile)

(add-to-list 'compilation-error-regexp-alist-alist
	     '(kibit "At \\([^:]+\\):\\([[:digit:]]+\\):" 1 2 nil 0))

(add-to-list 'compilation-error-regexp-alist 'kibit)

(defun kibit ()
  "Run kibit on the current project.
Display the results in a hyperlinked *compilation* buffer."
  (interactive)
  (compile "lein kibit"))
---------------------------------------------------------------
  • Loading branch information
tsdh committed May 31, 2012
1 parent 7f9c528 commit abf4979
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/kibit/check.clj
Expand Up @@ -226,5 +226,5 @@
:rules rules
:guard guard
:resolution resolution)]
(reporter simplify-map)))))
(reporter (assoc simplify-map :file source-file))))))

6 changes: 3 additions & 3 deletions src/kibit/reporters.clj
Expand Up @@ -28,9 +28,9 @@
(defn cli-reporter
"Print a check-map to `*out*`"
[check-map]
(let [{:keys [line expr alt]} check-map]
(do
(printf "[%s] Consider:\n" line)
(let [{:keys [file line expr alt]} check-map]
(do
(printf "At %s:%s:\nConsider using:\n" file line)
(pprint-code alt)
(println "instead of:")
(pprint-code expr)
Expand Down
19 changes: 9 additions & 10 deletions src/leiningen/kibit.clj
Expand Up @@ -11,15 +11,14 @@
(let [paths (or (:source-paths project) [(:source-path project)])
source-files (mapcat #(-> % io/file clj-ns/find-clojure-sources-in-dir) paths)]
(doseq [source-file source-files]
(with-open [reader (io/reader source-file)]
(printf "== %s ==\n" (or (second (clj-ns/read-file-ns-decl source-file)) source-file))
(try
(->> (kibit/check-reader reader)
#_(filter #(contains? % :alt))
(map reporters/cli-reporter)
doall)
(catch Exception e
(println "Check failed -- skipping rest of file")
(println (.getMessage e))))))))
(printf "== %s ==\n" (or (second (clj-ns/read-file-ns-decl source-file)) source-file))
(try
(->> (kibit/check-file source-file)
#_(filter #(contains? % :alt))
(map reporters/cli-reporter)
doall)
(catch Exception e
(println "Check failed -- skipping rest of file")
(println (.getMessage e)))))))


0 comments on commit abf4979

Please sign in to comment.