1. Linux

1.1. Installation

sudo npm install -g jshint
sudo npm update -g jshint
which jshint
jshint -v                               # v2.9.2        # v2.12.0
jshint --help

1.2. Update

npm -v
sudo npm install -g npm
sudo npm update -g npm
npm -v

jshint -v
sudo npm install -g jshint
sudo npm update -g jshint
jshint -v

1.3. Configuration

  • Contents of the ~<user>/.jshintrc file.

// See http://www.jshint.com/docs for explanation of options.

{
  // Enforcing options.
  "bitwise" : true,
  //"camelcase" : true,
  "curly" : true,
  "eqeqeq" : true,
  "forin" : true,
  "immed" : true,
  //"indent" : 2,
  "latedef" : true,
  "newcap" : true,
  "noarg" : true,
  "noempty" : true,
  "nonew" : true,
  "plusplus" : true,
  "quotmark" : "single",
  "regexp" : true,
  "undef" : true,
  //"unused" : true,
  "strict" : true,
  "trailing" : true,
  "maxparams" : 10,
  "maxdepth" : 10,
  "maxstatements" : 100,
  "maxcomplexity" : 50,
  "maxlen" : 237,       // Set max length of lines.

  // Relaxing options.
  "asi" : false,        // Disallow automatic semicolon insertion.
  //"es5" : true,       // Allow ECMAScript 5 syntax.
  "laxcomma" : true,    // Allow comma-first coding style.

  // Environments.
  "browser" : true,     // Allow browser globals.
  "devel" : true,       // Allow alert, console, etc.
  "jquery" : true,      // Allow jquery globals.
  "node" : true         // Allow node globals.
}
sudo chown <user>:<user> ~<user>/.jshintrc
  • Append the following lines to the ~<user>/.bashrc_aliases file.

# Exclude Git repository, Node.js modules, Bootstrap, Bootbox, Cordova and jQuery libraries.
alias jsdiff='diff --exclude=.git --exclude=node_modules --exclude=bootstrap* --exclude=bootbox* --exclude=cordova* --exclude=*jquery* --exclude=*.min.css --exclude=*.min.js'
alias jsgrep='grep --exclude-dir=.git --exclude-dir=node_modules --exclude=bootstrap* --exclude=bootbox* --exclude=cordova* --exclude=*jquery* --exclude=*.min.css --exclude=*.min.js'
alias jslint='jslint --browser --indent=2 --maxerr=999 --nomen --white --windows'
alias jshint-all='find . -path "*node_modules*" -prune -o ! -iname "*.min.js" ! -iname "bootstrap*" ! -iname "bootbox*" ! -iname "cordova*" ! -iname "*jquery*" ! -size 0 -iname "*.js" -exec jshint {} \;'
alias jslint-all='find . -path "*node_modules*" -prune -o ! -iname "*.min.js" ! -iname "bootstrap*" ! -iname "bootbox*" ! -iname "cordova*" ! -iname "*jquery*" ! -size 0 -iname "*.js" -exec jslint --browser --indent=2 --maxerr=999 --nomen --white --windows {} \;'

1.4. Usage

jshint <file>
jshint .
jshint-all

2. macOS

2.1. Installation

sudo npm install -g jshint
sudo npm update -g jshint
jshint -v
which jshint
jshint --help

2.2. Configuration

  • Contents of the ~delta/.jshintrc file.

// See http://www.jshint.com/docs for explanation of options.

{
  // Enforcing options.
  "bitwise" : true,
  //"camelcase" : true,
  "curly" : true,
  "eqeqeq" : true,
  "forin" : true,
  "immed" : true,
  //"indent" : 2,
  "latedef" : true,
  "newcap" : true,
  "noarg" : true,
  "noempty" : true,
  "nonew" : true,
  "plusplus" : true,
  "quotmark" : "single",
  "regexp" : true,
  "undef" : true,
  //"unused" : true,
  "strict" : true,
  "trailing" : true,
  "maxparams" : 10,
  "maxdepth" : 10,
  "maxstatements" : 100,
  "maxcomplexity" : 50,
  "maxlen" : 237,       // Set max length of lines.

  // Relaxing options.
  "asi" : false,        // Disallow automatic semicolon insertion.
  "es5" : true,         // Allow ECMAScript 5 syntax.
  "laxcomma" : true,    // Allow comma-first coding style.

  // Environments.
  "browser" : true,     // Allow browser globals.
  "devel" : true,       // Allow alert, console, etc.
  "jquery" : true,      // Allow jquery globals.
  "node" : true         // Allow node globals.
}
  • Append the following lines to the ~/.bashrc file.

# Exclude Git repository, Node.js modules, Bootstrap, Bootbox, Cordova and jQuery libraries.
alias jsdiff='diff --exclude=.git --exclude=node_modules --exclude=bootstrap* --exclude=bootbox* --exclude=cordova* --exclude=*jquery* --exclude=*.min.css --exclude=*.min.js'
alias jsgrep='grep --exclude-dir=.git --exclude-dir=node_modules --exclude=bootstrap* --exclude=bootbox* --exclude=cordova* --exclude=*jquery* --exclude=*.min.css --exclude=*.min.js'
alias jslint='jslint --browser --indent=2 --maxerr=999 --nomen --white --windows'
alias jshint-all='find . -path "*node_modules*" -prune -o ! -iname "*.min.js" ! -iname "bootstrap*" ! -iname "bootbox*" ! -iname "cordova*" ! -iname "*jquery*" ! -size 0 -iname "*.js" -exec jshint {} \;'
alias jslint-all='find . -path "*node_modules*" -prune -o ! -iname "*.min.js" ! -iname "bootstrap*" ! -iname "bootbox*" ! -iname "cordova*" ! -iname "*jquery*" ! -size 0 -iname "*.js" -exec jslint --browser --indent=2 --maxerr=999 --nomen --white --windows {} \;'

2.3. Usage

jshint <file>
jshint .
jshint-all

3. Windows

3.1. Installation

npm install -g jshint
npm update -g jshint
jshint -v
jshint --help
  • Open Control Panel > User Accounts.

  • Click Change my environment variables.

  • Click New.

Variable name:          PATH
Variable value:         C:\Users\<User>\AppData\Roaming\npm\
  • Click OK.

  • Click OK.

  • Close User Accounts.

3.2. Configuration

  • Contents of the .jshintrc file.

// See http://www.jshint.com/docs for explanation of options.

{
  // Enforcing options.
  "bitwise" : true,
  //"camelcase" : true,
  "curly" : true,
  "eqeqeq" : true,
  "forin" : true,
  "immed" : true,
  //"indent" : 2,
  "latedef" : true,
  "newcap" : true,
  "noarg" : true,
  "noempty" : true,
  "nonew" : true,
  "plusplus" : true,
  "quotmark" : "single",
  "regexp" : true,
  "undef" : true,
  //"unused" : true,
  "strict" : true,
  "trailing" : true,
  "maxparams" : 10,
  "maxdepth" : 10,
  "maxstatements" : 100,
  "maxcomplexity" : 50,
  "maxlen" : 237,       // Set max length of lines.

  // Relaxing options.
  "asi" : false,        // Disallow automatic semicolon insertion.
  "es5" : true,         // Allow ECMAScript 5 syntax.
  "laxcomma" : true,    // Allow comma-first coding style.

  // Environments.
  "browser" : true,     // Allow browser globals.
  "devel" : true,       // Allow alert, console, etc.
  "jquery" : true,      // Allow jquery globals.
  "node" : true         // Allow node globals.
}
  • Contents of the C:\Program Files\Git\bin\jsdiff.bat file.

@echo off
:: Exclude Git repository, Node.js modules, Bootstrap, Bootbox, Cordova and jQuery libraries.
diff -x=.git -x=node_modules -x=bootstrap* -x=bootbox* -x=cordova* -x=*jquery* -x=*.min.css -x=*.min.js %*
  • Contents of the C:\Program Files\Git\bin\jsgrep.bat file.

@echo off
:: Exclude Git repository, Node.js modules, Bootstrap, Bootbox, Cordova and jQuery libraries.
:: Todo: Fix issue that git grep does not recognize --exclude option.
grep --exclude-dir=.git --exclude-dir=node_modules --exclude=bootstrap* --exclude=bootbox* --exclude=cordova* --exclude=*jquery* --exclude=*.min.css --exclude=*.min.js %*
  • Contents of the C:\Program Files\Git\bin\jshint-all.bat file.

@echo off
:: Exclude Git repository, Node.js modules, Bootstrap, Bootbox, Cordova and jQuery libraries.
find . -path "*node_modules*" -prune -o ! -iname "*.min.js" ! -iname "bootstrap*" ! -iname "bootbox*" ! -iname "cordova*" ! -iname "*jquery*" ! -size 0 -iname "*.js" -exec jshint {} ;
  • Contents of the C:\Program Files\Git\bin\jslint-all.bat file.

@echo off
:: Exclude Git repository, Node.js modules, Bootstrap, Bootbox, Cordova and jQuery libraries.
find . -path "*node_modules*" -prune -o ! -iname "*.min.js" ! -iname "bootstrap*" ! -iname "bootbox*" ! -iname "cordova*" ! -iname "*jquery*" ! -size 0 -iname "*.js" -exec jslint --browser --indent=2 --maxerr=999 --nomen --white --windows {} ;
  • Contents of the C:\Program Files\Git\bin\jslint-one.bat file.

@echo off
jslint --browser --indent=2 --maxerr=999 --nomen --white --windows %*

3.3. Usage

jshint <file>
jshint .
jshint-all