Here is the definition of JSLint as per Wikipedia JSLint page:
Installing Jslint on Ubuntu Linux
We’ll be using the node.js version of JSLint (node-jslint) for running jslint on command line. Here are the steps to install it on Ubuntu Linux:
- First install nodejs and npm on Ubuntu Linux.
- Using npm, install jslint using the following command:
sudo npm install -g jslint
-gis for global install which installs jslint in
- Now run jslint on command line without any argument. You should see the help message.
No files specified. Usage: /usr/local/bin/jslint [--indent] [--maxerr] [--maxlen] [--predef] [--anon] [--bitwise] [--browser] [--cap] [--continue] [--css] [--debug] [--devel] [--eqeq] [--es5] [--evil] [--forin] [--fragment] [--newcap] [--node] [--nomen] [--on] [--passfail] [--plusplus] [--properties] [--regexp] [--rhino] [--undef] [--unparam] [--sloppy] [--stupid] [--sub] [--vars] [--white] [--widget] [--windows] [--json] [--color] [--terse] [--] <scriptfile>...
- To run jslint on foo.js, run this command:
- If you get “Missing ‘use strict’ statement.” error message, then add the following line to your code:
- If you are using a global variable (e.g. jQuery), you may get this eror:
'jQuery' was used before it was defined.
To fix this add
/*global jQuery */somewhere at the top of your js file.
- JSLint assumes an indentation of 4 spaces. In case you are using a 2 space indent, run jslint with –indent 2. Here is how it will look like:
jslint --indent 2 foo.js
or alternatively you can add
/*jslint indent: 2 */line at the top of your file.
- In case you are using a bash script to push your code to development or production server, you can use
set -eand do a jslint before the code push line. That way if there is a jslint error, the script will exit instead of continuing. Here is how the bash script code will look like:
#!/bin/bash set -e jslint foo.js ## Commands to push code to server ...