JSLint External Tool for Intellij

This post describes the steps necessary to integrate JSLint into Intellij (v10.5.2) since they do not have a plug-in for it.  Intellij is pretty good, but JSLint is the standard!

  1. Download jslint4java from: http://code.google.com/p/jslint4java/ (select the latest jslint4java-x.x.x-dist.zip link)
  2. Extract to a local folder (Ex. C:\Program Files (x86)\jslint4java-2.0.1)
  3. Open the Intellij settings dialog and select “External Tools”
  4. Select “Add” and enter the following values:
  5. Select “Output Filters”, select “Add” and enter the following values:
  6. Select “OK” to all dialogs and open a JavaScript file
  7. In the code editor, right-click and select “JavaScript | JSLint”:
  8. In the Run window, you’ll be able to navigate to the code issue via the hyperlink:

Custom Settings

JSLint provides many settings for JavaScript analysis.  See http://www.jslint.com/ for all of them.  The only problem with this external tool is that there is not an easy way to change the options.  You could probably wrap the command line in a batch file with options or just create a couple of JSLint external tool entries with customized parameters.  Here are all the options from the command prompt:

C:\Program Files (x86)\jslint4java-2.0.1>java -jar jslint4java-2.0.1.jar --help
Usage: jslint4java [options] file.js ...
  Options:
        --adsafe       If adsafe rules should be enforced
        --bitwise      If bitwise operators should be allowed
        --browser      If the standard browser globals should be predefined
        --cap          If upper case html should be allowed
        --confusion    If types can be used inconsistently
        --continue     If the continuation statement should be tolerated
        --css          If css workarounds should be tolerated
        --debug        If debugger statements should be allowed
        --devel        If logging should be allowed (console, alert, etc.)
        --encoding     Specify the input encoding
        --eqeq         If == should be allowed
        --es5          If es5 syntax should be allowed
        --evil         If eval should be allowed
        --forin        If for in statements need not filter
        --fragment     If html fragments should be allowed
        --help         Display usage information
                       Default: false
        --indent       The indentation factor
        --jslint       Specify an alternative version of jslint.js
        --maxerr       The maximum number of errors to allow
        --maxlen       The maximum length of a source line
        --newcap       If constructor names capitalization is ignored
        --node         If node.js globals should be predefined
        --nomen        If names may have dangling _
        --on           If html event handlers should be allowed
        --passfail     If the scan should stop on first error
        --plusplus     If increment/decrement should be allowed
        --predef       The names of predefined global variables
        --properties   If all property names must be declared with
                       /*properties*/
        --regexp       If the . should be allowed in regexp literals
        --report       Display report in different formats: plain, xml, junit,
                       checkstyle and report
        --rhino        If the rhino environment globals should be predefined
        --safe         If use of some browser features should be restricted
        --sloppy       If the 'use strict'; pragma is optional
        --sub          If all forms of subscript notation are tolerated
        --timeout      Maximum number of seconds JSLint can run for
                       Default: 0
        --undef        If variables can be declared out of order
        --unparam      If unused parameters should be tolerated
        --vars         If multiple var statements per function should be allowed

        --version      Show the version of JSLint in use.
                       Default: false
        --white        If sloppy whitespace is tolerated
        --widget       If the yahoo widgets globals should be predefined
        --windows      If ms windows-specific globals should be predefined

using jslint version 2011-10-17

Commented Custom Settings

JSLint supports adding options via commented in the JavaScript file like this:

/*jslint sloppy: true, vars: true, browser: true */

This is also supported in the command line version and is an alternate method of controlling JSLint parameters on a file by file basis.  You can create custom options like about by going to http://www.jslint.com/, selecting your desired options, copying them from the bottom of the page, and pasting them into the desired JavaScript file.

Advertisements
This entry was posted in Java and tagged , , . Bookmark the permalink.

One Response to JSLint External Tool for Intellij

  1. progys says:

    Nice tip! Works great 🙂 Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s