Permalink
Browse files

Prepare for 0.0.5 release

  • Loading branch information...
1 parent 453b02a commit 3cfeb78db8eafcb469903aea4ba3817516ebc0dc @jonase committed Nov 11, 2012
Showing with 35 additions and 59 deletions.
  1. +6 −3 README.md
  2. +4 −5 project.clj
  3. +7 −27 src/kibit/check.clj
  4. +18 −0 src/kibit/driver.clj
  5. +0 −24 src/leiningen/kibit.clj
View
@@ -15,16 +15,19 @@ it will make the suggestion to use the `when` macro instead of `if`.
## Usage
-Add `[jonase/kibit "0.0.4"]` to your `:plugins` vector in your `:user`
+Add `[lein-kibit "0.0.5"]` to your `:plugins` vector in your `:user`
profile (Leiningen 2) or if you are using Leiningen 1:
- $ lein plugin install jonase/kibit 0.0.4
+ $ lein plugin install lein-kibit 0.0.5
Then you can run
$ lein kibit
-to analyze your namespaces.
+to analyze your namespaces. You can analyze individual files by
+running
+
+ $ lein kibit path/to/some/file.clj
### Usage from inside Emacs
View
@@ -1,13 +1,12 @@
-(defproject jonase/kibit "0.0.4"
+(defproject jonase/kibit "0.0.5"
:description "There's a function for that!"
:url "https://github.com/jonase/kibit"
:license {:name "Eclipse Public License - v 1.0"
:url "http://www.eclipse.org/legal/epl-v10.html"
:distribution :repo
:comments "Contact if any questions"}
- :dependencies [[org.clojure/clojure "1.3.0"]
- [org.clojure/core.logic "0.7.0"]
- [org.clojure/tools.namespace "0.1.2"]]
+ :dependencies [[org.clojure/clojure "1.5.0-beta1"]
+ [org.clojure/core.logic "0.8.0-beta2"]
+ [org.clojure/tools.namespace "0.2.1"]]
:dev-dependencies [[lein-marginalia "0.7.0"]]
- :eval-in-leiningen true
:warn-on-reflection false)
View
@@ -32,43 +32,22 @@
;; Reading source files
;; --------------------
-;;
-;; TODO Paul - give an overview here
-
-;; ### Handling read errors
-;; TODO Paul - explain this more
-(def ^:dynamic *check-error-handler*
- (fn [ex reader]
- (throw (Exception.
- (str "Kibit's reader crashed; see kibit.check/read-file:"
- (.getMessage ex))
- ex))))
-
-(defn ignore-error-handler
- "This is an error handler that will silently skip over forms
- that cause errors - a work in progress"
- [ex reader] ; TODO We're going to have to (.skip reader n), where n is the number of chars to skip until the next form
- nil)
-
;; ### Extracting forms
;; `read-file` is intended to be used with a Clojure source file,
;; read in by Clojure's LineNumberingPushbackReader *(LNPR)*. Expressions are
;; extracted using the clojure reader (ala `read`), and line numbers
;; are added as `:line` metadata to the forms (via LNPR).
-;; Exceptions are handled using a dynamic handler, `*check-error-handler*`
-;;
-;; See above for more details on how to control error handling
+
+(def eof (Object.))
+
(defn read-file
"Generate a lazy sequence of top level forms from a
LineNumberingPushbackReader"
[^LineNumberingPushbackReader r]
(lazy-seq
- (let [form (try
- (read r false ::eof)
- (catch Exception e
- (*check-error-handler* e r)))]
- (when-not (= form ::eof)
+ (let [form (read r false eof)]
+ (when-not (= form eof)
(cons form (read-file r))))))
;; ### Analyzing the pieces
@@ -222,9 +201,10 @@
(merge default-args
(apply hash-map kw-opts))]
(with-open [reader (io/reader source-file)]
+ (binding [*default-data-reader-fn* (fn [tag val] val)]
(doseq [simplify-map (check-reader reader
:rules rules
:guard guard
:resolution resolution)]
- (reporter (assoc simplify-map :file source-file))))))
+ (reporter (assoc simplify-map :file source-file)))))))
View
@@ -0,0 +1,18 @@
+(ns kibit.driver
+ (: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]]))
+
+(defn run [project & args]
+ (let [source-files (if (empty? args)
+ (mapcat #(-> % io/file find-clojure-sources-in-dir)
+ (or (:source-paths project) [(:source-path project)]))
+ args)]
+ (doseq [file source-files]
+ (try (->> (check-file file)
+ (map cli-reporter)
+ doall)
+ (catch Exception e
+ (println "Check failed -- skipping rest of file")
+ (println (.getMessage e)))))))
View
@@ -1,24 +0,0 @@
-(ns leiningen.kibit
- (:require [clojure.tools.namespace :as clj-ns]
- [clojure.java.io :as io]
- [kibit.check :as kibit]
- [kibit.rules :as rules]
- [kibit.reporters :as reporters]))
-
-(defn kibit
- "Suggest idiomatic replacements for patterns of code."
- [project & opts]
- (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]
- (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 3cfeb78

Please sign in to comment.