Skip to content

Commit

Permalink
Merge master into pull/158/head (@jpb's replace changes)
Browse files Browse the repository at this point in the history
Conflicts:
  project.clj
  src/kibit/driver.clj
  • Loading branch information
arrdem committed Mar 21, 2017
2 parents b366ddf + 8ba2e02 commit 2e65947
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 17 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Expand Up @@ -3,10 +3,16 @@
All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com).

## [Unreleased]

## [0.1.3] / 2016-11-21
### Additions
* Automatic replacement of suggestions (`--replace` and `--interactive` cli arguments)
* Enabled Emacs' next error function to go to next Kibit suggestion. See the updated code in the README for the change.

* #172 Kibit can now handle sets without crashing!
* #152 Send exceptions to STDERR instead of STDOUT
* New rules (#154, #165, )
* #168 Bumped to new versions of clojure and tools.cli dependencies
* #171 Update core.logic to avoid exception from spec

## [0.1.2] / 2015-04-21
### Additions
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -25,12 +25,12 @@ it will suggest using `when` instead:

## Usage

Add `[lein-kibit "0.1.2"]` to your `:plugins` vector in your `:user`
Add `[lein-kibit "0.1.3"]` to your `:plugins` vector in your `:user`
profile. Then you can run

$ lein kibit

to analyze a Leiningen project's namespaces. Kibit will automatically pick up source paths from your project.clj from the following keyseqs: [:source-paths], [:cljsbuild :builds], and [:cljx :builds]. You can also run Kibit manually on individual files or folders (even if there is no Leiningen `project.clj`) by running:
to analyze a Leiningen project's namespaces. Kibit will automatically pick up source paths from your project.clj from the following keyseqs: `[:source-paths]`, `[:cljsbuild :builds]`, and `[:cljx :builds]`. You can also run Kibit manually on individual files or folders (even if there is no Leiningen `project.clj`) by running:

$ lein kibit path/to/some/file.clj #or
$ lein kibit path/to/src/ #or
Expand Down
10 changes: 5 additions & 5 deletions project.clj
@@ -1,15 +1,15 @@
(defproject jonase/kibit "0.1.2"
(defproject jonase/kibit "0.1.4-SNAPSHOT"
: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.6.0"]
[org.clojure/core.logic "0.8.10"]
[org.clojure/tools.cli "0.3.1"]
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/core.logic "0.8.11"]
[org.clojure/tools.cli "0.3.5"]
[rewrite-clj "0.4.12"]]
:profiles {:dev {:dependencies [[lein-marginalia "0.8.0"]]
:profiles {:dev {:dependencies [[lein-marginalia "0.9.0"]]
:resource-paths ["test/resources"]}}
:deploy-repositories [["releases" :clojars]]
:warn-on-reflection false)
27 changes: 19 additions & 8 deletions src/kibit/driver.clj
@@ -1,11 +1,14 @@
(ns kibit.driver
"The (leiningen) facing interface for Kibit. Provides helpers for finding files in a project, and
linting a list of files."
(:require [clojure.java.io :as io]
[kibit.rules :refer [all-rules]]
[kibit.check :refer [check-file]]
[kibit.replace :refer [replace-file]]
[kibit.reporters :refer :all]
[clojure.tools.cli :refer [cli]])
(:import [java.io File]))
[clojure.tools.cli :refer [cli]]
[kibit
[check :refer [check-file]]
[replace :refer [replace-file]]
[reporters :refer :all]
[rules :refer [all-rules]]])
(:import java.io.File))

(def cli-specs [["-r" "--reporter"
"The reporter used when rendering suggestions"
Expand Down Expand Up @@ -56,9 +59,17 @@
source-files))

(defn run [source-paths rules & args]
"Runs the kibit checker against the given paths, rules and args.
Paths is expected to be a sequence of io.File objects.
Rules is either a collection of rules or nil. If Rules is nil, all of kibit's checkers are used.
Optionally accepts a :reporter keyword argument, defaulting to \"text\"
If :replace is provided in options, suggested replacements will be performed automatically."
(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))]
source-files (mapcat #(-> % io/file find-clojure-sources-in-dir)
(if (empty? file-args) source-paths file-args))]
(if (:replace options)
(run-replace source-files rules options)
(run-check source-files rules options))))
Expand Down
40 changes: 40 additions & 0 deletions src/kibit/monkeypatch.clj
@@ -0,0 +1,40 @@
(ns kibit.monkeypatch
"Various helpers providing a with-monkeypatches form which wraps"
(:require [clojure.core.logic :as c.c.l])
(:import [clojure.lang
Var
IPersistentSet]
[clojure.core.logic.protocols
ITreeTerm]))

(defn ^:pivate tree-term? [x]
(and (or (coll? x)
(instance? ITreeTerm x))
(not (instance? IPersistentSet x))))

(def kibit-redefs
{#'c.c.l/tree-term? tree-term?})

(defmacro with-monkeypatches
"Builds a try/finally which captures Var bindings (and ^:macro tags) comming in, creates new Var
bindings within the try and in the finally restores the original bindings. This allows users to
establish stack-local patched contexts."
{:style/indent [1]}
[redefs & forms]
(let [redefs (eval redefs)
original-bindings (into {}
(for [k (keys redefs)]
[k (gensym)]))]
`(let [~@(for [[k v] original-bindings
f [v `(deref ~k)]]
f)]
(try ~@(for [[k v] redefs]
`(do (.bindRoot ~k ~v)
~(if (.isMacro ^Var k)
`(.setMacro ~k))))
~@forms
(finally
~@(for [[k v] redefs]
`(do (.bindRoot ~k ~(get original-bindings k))
~(if (.isMacro ^Var k)
`(.setMacro ~k)))))))))
2 changes: 1 addition & 1 deletion src/kibit/reporters.clj
Expand Up @@ -5,7 +5,7 @@
(:import [java.io StringWriter]))

;; Reporters are used with `check-file`, passed in with the `:reporter`
;; keywork argument. For more information, see the [check](#kibit.check)
;; keyword argument. For more information, see the [check](#kibit.check)
;; namespace.
;;
;; There is no limit to a reporter - Clojure Data, JSON, HTML...
Expand Down
1 change: 1 addition & 0 deletions src/kibit/rules/misc.clj
Expand Up @@ -27,6 +27,7 @@
[(filter seq ?coll) (remove empty? ?coll)]
[(filter (fn* [?x] (not (?pred ?x))) ?coll) (remove ?pred ?coll)]
[(filter (fn [?x] (not (?pred ?x))) ?coll) (remove ?pred ?coll)]
[(vec (filter ?pred ?coll)) (filterv ?pred ?coll)]

;; first/next shorthands
[(first (first ?coll)) (ffirst ?coll)]
Expand Down
4 changes: 4 additions & 0 deletions test/kibit/test/driver.clj
Expand Up @@ -13,5 +13,9 @@
(deftest find-clojure-sources-are
(is (= [(io/file "test/resources/first.clj")
(io/file "test/resources/second.cljx")
(io/file "test/resources/sets.clj")
(io/file "test/resources/third.cljs")]
(driver/find-clojure-sources-in-dir (io/file "test/resources")))))

(deftest test-set-file
(is (driver/run ["test/resources/sets.clj"] nil)))
1 change: 1 addition & 0 deletions test/kibit/test/misc.clj
Expand Up @@ -24,6 +24,7 @@
'(remove empty? coll) '(filter seq coll)
'(remove pred coll) '(filter #(not (pred %)) coll)
'(remove pred coll) '(filter (fn [x] (not (pred x))) coll)
'(filterv pred coll) '(vec (filter pred coll))
'(ffirst coll) '(first (first coll))
'(fnext coll) '(first (next coll))
'(nnext coll) '(next (next coll))
Expand Down
4 changes: 4 additions & 0 deletions test/resources/sets.clj
@@ -0,0 +1,4 @@
(ns resources.sets)

(defn killit [coll]
(not-any? #{"string1" "string2"} (map ffirst coll)))

0 comments on commit 2e65947

Please sign in to comment.