Skip to content

A Leiningen plugin for running javascript code through JSHint

License

Notifications You must be signed in to change notification settings

vbauer/lein-jshint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

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

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

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

  • 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.

About

A Leiningen plugin for running javascript code through JSHint

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published