Skip to content
A Leiningen plugin for running javascript code through JSHint
Clojure JavaScript
Latest commit 013c4db May 7, 2016 @vbauer Update jshint
Failed to load latest commit information.
example
src
test/lein_jshint
.gitignore
.travis.yml
LICENSE
README.md
project.clj

README.md

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 Dependencies Status

Pre-requirements

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

  • On Ubuntu: sudo apt-get install nodejs
  • On Mac OS X: brew install node

Installation

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

  • Use NPM to install JSHint globally: npm install jshint -g
  • You can also install JSHint in the current directory: npm install jshint
  • Use lein-npm plugin: lein npm install
  • Use just Leiningen: lein deps

Setup

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

latest-version

Configuration

lien-jshint will create two files in runtime to setup configuration:

You can specify place, where JS files will be located with:

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

You can also specify JS files that should be excluded from checking:

: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:

; It specifies which JSHint options to turn on or off
:config {:globals {:angular true
                   :console true
                   "$" true}
         :node true
         :es5 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:

: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
           :immed      true    ; Require immediate invocations to be wrapped in parens
           :latedef    true    ; Prohibit variable use before definition
           :newcap     true    ; Require capitalization of all constructor functions
           :noarg      true    ; Prohibit use of arguments.caller and arguments.callee
           :noempty    true    ; Prohibit use of empty blocks
           :nonew      true    ; Prohibit use of constructors for side-effects
           :plusplus   true    ; Prohibit use of "++" & "--"
           :regexp     true    ; Prohibit "." and ""[^...]"" in regular expressions
           :undef      true    ; Require all non-global vars be declared before usage
           :strict     true    ; Require "use strict" pragma in every file
           :trailing   true    ; Prohibit trailing whitespaces
           }}

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/

Thanks to

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

Might also like

  • lein-asciidoctor - A Leiningen plugin for generating documentation using Asciidoctor.
  • lein-plantuml - a Leiningen plugin for generating UML diagrams using PlantUML.
  • lein-coffeescript - a Leiningen plugin for running CoffeeScript compiler.
  • lein-typescript - a Leiningen plugin for running TypeScript compiler.
  • lein-jslint - a Leiningen plugin for running javascript code through JSLint.
  • jabberjay - a simple framework for creating Jabber bots.
  • coderwall-clj - a tiny CoderWall client for Clojure.

License

Copyright © 2014 Vladislav Bauer

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

Something went wrong with that request. Please try again.