vbauer/lein-jshint


A Leiningen plugin for running javascript code through JSHint

License: EPL-1.0

Language: Clojure

Keywords: clj, clojure, jshint, lein, leiningen


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.

Project Statistics

Sourcerank 4
Repository Size 479 KB
Stars 6
Forks 0
Watchers 0
Open issues 0
Dependencies 2
Contributors 1
Tags 10
Created
Last updated
Last pushed

Top Contributors See all

Vladislav Bauer

Packages Referencing this Repo

lein-jshint
A Leiningen plugin for running JS code through JSHint.
Latest release 0.1.10 - Updated - 6 stars

Recent Tags See all

lein-jshint-0.1.10 March 28, 2015
lein-jshint-0.1.9 January 11, 2015
lein-jshint-0.1.8 November 10, 2014
lein-jshint-0.1.6 November 09, 2014
lein-jshint-0.1.5 October 30, 2014
lein-jshint-0.1.4 September 06, 2014
lein-jshint-0.1.3 May 15, 2014
lein-jshint-0.1.2 May 15, 2014
lein-jshint-0.1.1 May 12, 2014
lein-jshint-0.1.0 May 12, 2014

Something wrong with this page? Make a suggestion

Last synced: 2018-01-16 17:53:07 UTC

Login to resync this repository