Ivor O’Connor

May 2, 2009

JavaScriptLint, Vim, And Ubuntu

Filed under: debugging, Firefox, Lint — Tags: , , , , , , — ioconnor @ 7:30 pm

In my blog http://ioconnor.wordpress.com/2009/04/24/javascript-testing/ I looked into some tools to help in my JavaScript development. I haven’t had the time, (or urge?), to do anything until this morning. This morning though I got JavaScriptLint working. The documentation at the site is less than adequate so I’m adding notes here to help me if I need to install it again in the future.

  1. The Linux download is here: http://www.javascriptlint.com/download.htm
  2. After decompressing it you’ll notice there is only a single horribly wrong README.html file. To get things working compile it by going to the src directory and typing:
    make -f Makefile.ref
  3. A jsl will now be found in jsl-0.3.0/src/Linux_All_DBG.OBJ/jsl. To make it generally accessible do something like:
    ln -s /whatever/jsl-0.3.0/src/Linux_All_DBG.OBJ /my/bin/jsl
  4. Running jsl will show the parameters that are needed. If you are like me you’ll wonder where the configuration file is that they mention. It’s not on their website and it certainly is nowhere on my disk. So I googled around until I found it, or close to what it should probaly be, and have copied it down below. I called the file “jsl.conf” and stuck it in /my/bin/jsl.conf.
  5. It’s all fine and good running it on the command line. It even looks at the javascript code in html files. I found quite a few questionable pieces of code and one clear mistake on my part that fortunately was not causing any problems. From the command line type something like:
    jsl -conf /my/bin/jsl.conf -process /my/dev/taxes2.html
    The -conf /my/bin/jsl.conf is optional.
  6. To run it from within vim by pressing the <F9> key edit the vimrc file and include something like:
    map <F9> : call JavaScriptLint()<CR>
    func! JavaScriptLint()
    exec “w” “Save the file
    exec “!jsl -conf /my/bin/jsl.conf -process % “
    endfunc

I might change this so the editor dumps me on the line that’s bad with an error message. Or into an error file that can be toggled back and forth from. However it is usable enough for me in it’s current form.

The conf file I’m using looks like this:

#
# Configuration File for JavaScript Lint 0.3.0
# Developed by Matthias Miller (http://www.JavaScriptLint.com)
#
# This configuration file can be used to lint a collection of scripts, or to enable
# or disable warnings for scripts that are linted via the command line.
#

### Warnings
# Enable or disable warnings based on requirements.
# Use “+WarningName” to display or “-WarningName” to suppress.
#
+no_return_value # function {0} does not always return a value
+duplicate_formal # duplicate formal argument {0}
+equal_as_assign # test for equality (==) mistyped as assignment (=)?{0}
+var_hides_arg # variable {0} hides argument
+redeclared_var # redeclaration of {0} {1}
+anon_no_return_value # anonymous function does not always return a value
+missing_semicolon # missing semicolon
+meaningless_block # meaningless block; curly braces have no impact
+comma_separated_stmts # multiple statements separated by commas (use semicolons?)
+unreachable_code # unreachable code
+missing_break # missing break statement
+missing_break_for_last_case # missing break statement for last case in switch
+comparison_type_conv # comparisons against null, 0, true, false, or an empty string allowing implicit type conversion (use === or !==)
+inc_dec_within_stmt # increment (++) and decrement (–) operators used as part of greater statement
+useless_void # use of the void type may be unnecessary (void is always undefined)
+multiple_plus_minus # unknown order of operations for successive plus (e.g. x+++y) or minus (e.g. x—y) signs
+use_of_label # use of label
+block_without_braces # block statement without curly braces
+leading_decimal_point # leading decimal point may indicate a number or an object member
+trailing_decimal_point # trailing decimal point may indicate a number or an object member
+octal_number # leading zeros make an octal number
+nested_comment # nested comment
+misplaced_regex # regular expressions should be preceded by a left parenthesis, assignment, colon, or comma
+ambiguous_newline # unexpected end of line; it is ambiguous whether these lines are part of the same statement
+empty_statement # empty statement or extra semicolon
-missing_option_explicit # the “option explicit” control comment is missing
+partial_option_explicit # the “option explicit” control comment, if used, must be in the first script tag
+dup_option_explicit # duplicate “option explicit” control comment
+useless_assign # useless assignment
+ambiguous_nested_stmt # block statements containing block statements should use curly braces to resolve ambiguity
+ambiguous_else_stmt # the else statement could be matched with one of multiple if statements (use curly braces to indicate intent)
+missing_default_case # missing default case in switch statement
+duplicate_case_in_switch # duplicate case in switch statements
+default_not_at_end # the default case is not at the end of the switch statement
+legacy_cc_not_understood # couldn’t understand control comment using /*@keyword@*/ syntax
+jsl_cc_not_understood # couldn’t understand control comment using /*jsl:keyword*/ syntax
+useless_comparison # useless comparison; comparing identical expressions
+with_statement # with statement hides undeclared variables; use temporary variable instead
+trailing_comma_in_array # extra comma is not recommended in array initializers
+assign_to_function_call # assignment to a function call
+parseint_missing_radix # parseInt missing radix parameter

### Output format
# Customize the format of the error message.
# __FILE__ indicates current file path
# __FILENAME__ indicates current file name
# __LINE__ indicates current line
# __ERROR__ indicates error message
#
# Visual Studio syntax (default):
+output-format __FILE__(__LINE__): __ERROR__
# Alternative syntax:
#+output-format __FILE__:__LINE__: __ERROR__

### Context
# Show the in-line position of the error.
# Use “+context” to display or “-context” to suppress.
#
-context

### Semicolons
# By default, assignments of an anonymous function to a variable or
# property (such as a function prototype) must be followed by a semicolon.
#
+lambda_assign_requires_semicolon

### Control Comments
# Both JavaScript Lint and the JScript interpreter confuse each other with the syntax for
# the /*@keyword@*/ control comments and JScript conditional comments. (The latter is
# enabled in JScript with @cc_on@). The /*jsl:keyword*/ syntax is preferred for this reason,
# although legacy control comments are enabled by default for backward compatibility.
#
+legacy_control_comments

### JScript Function Extensions
# JScript allows member functions to be defined like this:
# function MyObj() { /*constructor*/ }
# function MyObj.prototype.go() { /*member function*/ }
#
# It also allows events to be attached like this:
# function window::onload() { /*init page*/ }
#
# This is a Microsoft-only JavaScript extension. Enable this setting to allow them.
#
-jscript_function_extensions

### Defining identifiers
# By default, “option explicit” is enabled on a per-file basis.
# To enable this for all files, use “+always_use_option_explicit”
-always_use_option_explicit

# Define certain identifiers of which the lint is not aware.
# (Use this in conjunction with the “undeclared identifier” warning.)
#
# Common uses for webpages might be:
#+define window
#+define document

### Interactive
# Prompt for a keystroke before exiting.
#+pauseatend

### Files
# Specify which files to lint
# Use “+recurse” to enable recursion (disabled by default).
# To add a set of files, use “+process FileName”, “+process Folder\Path\*.js”,
# or “+process Folder\Path\*.htm”.
#
#+process jsl-test.js

About these ads

6 Comments »

  1. [...] — ioconnor @ 10:24 am I’ve been playing with JavaScript looking for QA tools, getting JavaScript Lint in vim on Ubuntu, etc.. Now I’ve got code coverage analysis going for it. Follow these instructions to install [...]

    Pingback by JavaScript Code Coverage On Ubuntu « Ivor O’Connor — May 4, 2009 @ 10:58 am

  2. Thanks for this — it was exactly what I was searching for. I’ve now got JavascriptLint working properly in Geany. :)

    Comment by Barryvan — May 6, 2009 @ 12:14 am

  3. [...] different lint programs out there for JavaScript. I installed and made an entry on how to install JavaScript Lint here. This posting describes how to install the other version of lint, jslint, under ubuntu. I even [...]

    Pingback by How To Install Jslint on Ubuntu « Ivor O’Connor — May 7, 2009 @ 5:30 pm

  4. You should try the JavascriptLint.vim plugin.

    Comment by sotto — March 4, 2010 @ 9:48 pm

  5. HI Ivor,

    Thanks very much for this post. Very useful! Just one typo, in step 3 it should be

    ln -s /whatever/jsl-0.3.0/src/Linux_All_DBG.OBJ/jsl /my/bin/jsl

    (You’re just missing the the ‘jsl’ after ‘Linux_All_DBG.OBJ/’).

    Thanks again for this post. Awesome stuff!

    Dec

    Comment by Declan McGrath — May 5, 2010 @ 9:59 am

  6. By the way, you’re running a debug build. Making an optimized build is

    make -f Makefile.ref BUILD_OPT=1

    (that’s what you get with a linux port of windows software)

    Comment by Leonid Shevtsov — March 2, 2011 @ 11:25 am


RSS feed for comments on this post. TrackBack URI

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

The Silver is the New Black Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: