vbauer.lein-jshint

https://github.com/vbauer/lein-jshint.git

git clone 'https://github.com/vbauer/lein-jshint.git'

(ql:quickload :vbauer.lein-jshint)
6

lein-jshint

JSHint is a community-driven tool to detect errors and potential problems in JavaScript code. It is very flexible so you can easily adjust it to your particular coding guidelines and the environment you expect your code to execute in.

lein-jshint is a Leiningen plugin that allows to do static analysis for JavaScript files using JSHint.

Build Status Clojars Project

Pre-requirements

Install NodeJS and NPM (package manager for Node) to install JSHint:

Installation

Install JSHint to use lein-jshint plugin. It could be done in few ways:

Setup

To enable lein-jshint for your project, put the following in the :plugins vector of your project.clj file:

; Use latest version instead of "X.X.X"
:plugins [[lein-jshint "X.X.X"]]

Configuration

lien-jshint will create two files in runtime to setup configuration: - .jshintrc - main JSHint configuration - .jshintignore - list of files for ignoring

You can specify place, where JS files will be located with: clojure :jshint { :includes ["resources/public/js/*.js" "resources/js/*.js"] }

You can also specify JS files that should be excluded from checking: clojure :jshint { :excludes ["resources/public/lib/*.js"] }

To specify :includes and :excludes options, it is possible to use Glob Patterns.

JSHint rules could be configured with :config parameter: clojure ; It specifies which JSHint options to turn on or off :config {:globals {:angular true :console true "$" true} :node true :eqeqeq true ...}

You can use both variants to specify keys: string values or keywords.

All available parameters are described in the official documentation here: http://www.jshint.com/docs/options/

Hooks

To enable this plugin in compile stage, use the following hook: clojure :hooks [lein-jshint.plugin]

Examples

Detailed example

:jshint {
  :includes ["resources/public/js/*.js"]
  :excludes ["resources/public/js/directives.js"]

  ; This configuration is used by default
  :config {:bitwise    true    ; Prohibit bitwise operators (&, |, ^, etc.)
           :curly      true    ; Require {} for every new block or scope
           :eqeqeq     true    ; Require triple equals i.e. ===
           :forin      true    ; Tolerate "for in" loops without hasOwnPrototype
           :latedef    true    ; Prohibit variable use before definition
           :noarg      true    ; Prohibit use of arguments.caller and arguments.callee
           :nonew      true    ; Prohibit use of constructors for side-effects
           :plusplus   true    ; Prohibit use of "++" & "--"
           :undef      true    ; Require all non-global vars be declared before usage
           :strict     true    ; Require "use strict" pragma in every file
           }}

Just for Code Maniacs: JSHint Configuration, Strict Edition

Example project

Just clone the current repository and try to play with example project for better understanding how to use lein-jshint.

Invoking JSHint

It is also possible to invoke JSHint directly using “jshint” task: lein jshint "resources/js/*.js" lein jshint -verbose lein jshint --reporter=checkstyle resources/public/js/controllers.js See all CLI commands here: http://www.jshint.com/docs/cli/

Unit testing

To run unit tests:

lein test

Thanks to

JSHint author Anton Kovalyov and other developers who worked on this great project.

Might also like

License

Copyright © 2014 Vladislav Bauer

Distributed under the Eclipse Public License, the same as Clojure.