kibit/README.md

98 lines
2.9 KiB
Markdown
Raw Normal View History

2012-03-04 16:41:53 +00:00
# kibit
*There's a function for that!*
2012-04-01 16:44:26 +00:00
`kibit` is a static code analyzer for Clojure which uses
[`core.logic`](https://github.com/clojure/core.logic) to search for
patterns of code for which there might exist a more idiomatic function
or macro. For example if kibit finds the code
2012-03-04 16:41:53 +00:00
(if (some test)
(some action)
nil)
2012-03-05 08:54:31 +00:00
it will make the suggestion to use the `when` macro instead of `if`.
2012-03-04 16:41:53 +00:00
## Usage
2012-05-20 05:20:25 +00:00
Add `[jonase/kibit "0.0.4"]` to your `:plugins` vector in your `:user`
2012-03-04 22:09:59 +00:00
profile (Leiningen 2) or if you are using Leiningen 1:
2012-03-04 16:41:53 +00:00
2012-05-20 05:20:25 +00:00
$ lein plugin install jonase/kibit 0.0.4
2012-03-04 16:41:53 +00:00
2012-03-04 22:09:59 +00:00
Then you can run
2012-03-04 16:41:53 +00:00
2012-03-04 22:09:59 +00:00
$ lein kibit
2012-03-04 16:41:53 +00:00
to analyze your namespaces.
2012-05-31 13:38:50 +00:00
### Usage from inside Emacs
2012-06-11 04:43:23 +00:00
If you use Emacs for hacking Clojure, here's a way to use kibit from
inside Emacs with all the fancyness you are used from `M-x compile`.
Put the following into your `~/.emacs`:
2012-05-31 13:38:50 +00:00
```
;; Teach compile the syntax of the kibit output
(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)
2012-06-11 04:43:23 +00:00
;; A convenient command to run "lein kibit" in the project to which
;; the current emacs buffer belongs to.
2012-05-31 13:38:50 +00:00
(defun kibit ()
"Run kibit on the current project.
Display the results in a hyperlinked *compilation* buffer."
(interactive)
(compile "lein kibit"))
2012-06-11 04:43:23 +00:00
``` This will give you a new command `M-x kibit RET`, and the properly
highlighted and hyperlinked kibit output is presented in a
`*compilation*` buffer.
## Known limitations
Kibit
[reads](http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/read)
source code without any macro expansion or evaluation. A macro can
therefor easily invalidate a rule. Also, kibit will not know if the
symbol `+` in the form `(+ x 1)` actually refers to a local or to a
function in a namespace other than `clojure.core`. Expect
some false positives.
2012-05-31 13:38:50 +00:00
2012-03-04 16:41:53 +00:00
## Contributing
2012-03-04 18:42:20 +00:00
It is very easy to write new patterns for `kibit`. Take a look at
2012-04-01 18:56:28 +00:00
[`control-structures.clj`](https://github.com/jonase/kibit/blob/master/src/kibit/rules/control_structures.clj)
2012-03-04 19:01:33 +00:00
to see how new patterns are created. If you know of a recurring
2012-03-04 18:42:20 +00:00
pattern of code that can be simplified, please consider sending me a
pull request.
2012-03-04 16:41:53 +00:00
Bugs can be reported using the github bug tracker.
## Contributors
* Jonas Enlund
* Phil Hagelberg
2012-05-30 12:55:12 +00:00
* Tassilo Horn
* Alan Malloy
* Paul deGrandis
* Kevin Lynagh
2012-03-04 16:41:53 +00:00
## TODO
* Rules for function definitions (make this more of a lint tool)
* Rules for collection lookup; "2 is a bad smell" [see this blog post](http://tech.puredanger.com/2011/10/12/2-is-a-smell/)
* Extract the "when to use" rules from [Joy of Clojure](http://joyofclojure.com/)
* Leiningen project.clj setting for rule exclusion
* Leiningen project.clj setting for a directory of rules to include
2012-03-22 01:32:34 +00:00
* Analyse ClojureScript files
2012-03-04 16:41:53 +00:00
## License
2012-03-04 22:09:59 +00:00
Copyright © 2012 Jonas Enlund
2012-03-04 16:41:53 +00:00
Distributed under the Eclipse Public License, the same as Clojure.