v8jslint is a command line tool that uses JSLint to verify the quality of other JavaScript programs. v8jslint uses Google’s v8 open source, high performance JavaScript engine. v8jslint supports all JSLint options on the command line.

The v8jslint options are specified by a single dash.

$ ./v8jslint -h

The JSLint options are specified by a double dash.

$ ./v8jslint --evil=false bad.js

The prerequisites required to build v8jslint are FOX reswrap,  v8 static library and the JSLint source code.

Build and run on Ubuntu 11.04.

Get the source.

$ git clone git://reidme.com/v8jslint.git
$ cd v8jslint

Build v8jslint.

$ scons --v8=/home/steven/Source/v8/ --jslint=/home/steven/Source/jslint/
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
reswrap --static --const -o jslint.cc /home/steven/Source/jslint/jslint.js
reswrap --static --const -o lint.cc lint.js
g++ -o v8jslint.o -c -I. -I/home/steven/Source/v8/include v8jslint.cc
g++ -o v8jslint v8jslint.o -L/home/steven/Source/v8 -lv8 -lv8preparser -lpthread
scons: done building targets.

View the source Javascript file to be linted.

$ cat bad.js
if (true) print("1 line");
if (1 == "1") print("same"); // true
if( 1 === "1") print("same"); // false

Run v8jslint

$ ./v8jslint bad.js
/*jslint 2011-06-21*/
Errors:
Problem at line 1 character 5: Weird condition.
if (true) print("1 line");
Problem at line 1 character 11: Expected '{' and instead saw 'print'.
if (true) print("1 line");
Problem at line 1 character 11: 'print' was used before it was defined.
if (true) print("1 line");
Problem at line 2 character 7: Expected '===' and instead saw '=='.
if (1 == "1") print("same"); // true
Problem at line 2 character 7: Weird relation.
if (1 == "1") print("same"); // true
Problem at line 2 character 10: Type confusion: '1': number and '1': string.
if (1 == "1") print("same"); // true
Problem at line 2 character 15: Expected '{' and instead saw 'print'.
if (1 == "1") print("same"); // true
Problem at line 2 character 15: 'print' was used before it was defined.
if (1 == "1") print("same"); // true
Problem at line 3 character 3: Expected exactly one space between 'if' and '('.
if( 1 === "1") print("same"); // false
Problem at line 3 character 5: Unexpected space between '(' and '(number)'.
if( 1 === "1") print("same"); // false
Problem at line 3 character 7: Weird relation.
if( 1 === "1") print("same"); // false
Problem at line 3 character 11: Type confusion: '1': number and '1': string.
if( 1 === "1") print("same"); // false
Problem at line 3 character 16: Expected '{' and instead saw 'print'.
if( 1 === "1") print("same"); // false
Problem at line 3 character 16: 'print' was used before it was defined.
if( 1 === "1") print("same"); // false
/*jslint devel: true browser: true es5: true evil: false maxerr: 50 indent: 4 */

Lint the JSLint Javascript.

$ ./v8jslint ../jslint/jslint.js
/*jslint 2011-06-21*/
../jslint/jslint.js is good!.
/*jslint devel: true browser: true es5: true evil: false maxerr: 50 indent: 4 */

Build and run on Windows 7.

Get the source.

> git clone git://reidme.com/v8jslint.git
>cd v8jslint

Update the system environment to reference Visual C++ 2010.

>"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"

Build v8jslint.

>scons --v8=\users\steven\Source\v8\ --jslint=\users\steven\Source\jslint
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
reswrap --static -o jslint.cc C:\Users\steven\Source\jslint\jslint.js
reswrap --static -o lint.cc lint.js
cl /Fov8jslint.obj /c v8jslint.cc /TP /nologo /I. /IC:\Users\steven\Source\v8\include
v8jslint.cc
link /nologo /OUT:v8jslint.exe /LIBPATH:C:\Users\steven\Source\v8 v8.lib v8prepa
rser.lib Ws2_32.lib WINMM.lib v8jslint.obj
v8.lib(api.obj) : MSIL .netmodule or module compiled with /GL found; restarting
link with /LTCG; add /LTCG to the link command line to improve linker performance
Generating code
Finished generating code
scons: done building targets.

Run v8jslint

>v8jslint bad.js
/*jslint 2011-06-21*/
Errors:
Problem at line 1 character 5: Weird condition.
if (true) print("1 line");
Problem at line 1 character 11: Expected '{' and instead saw 'print'.
if (true) print("1 line");
Problem at line 1 character 11: 'print' was used before it was defined.
if (true) print("1 line");
Problem at line 2 character 7: Expected '===' and instead saw '=='.
if (1 == "1") print("same"); // true
Problem at line 2 character 7: Weird relation.
if (1 == "1") print("same"); // true
Problem at line 2 character 10: Type confusion: '1': number and '1': string.
if (1 == "1") print("same"); // true
Problem at line 2 character 15: Expected '{' and instead saw 'print'.
if (1 == "1") print("same"); // true
Problem at line 2 character 15: 'print' was used before it was defined.
if (1 == "1") print("same"); // true
Problem at line 3 character 3: Expected exactly one space between 'if' and '('.
if( 1 === "1") print("same"); // false
Problem at line 3 character 5: Unexpected space between '(' and '(number)'.
if( 1 === "1") print("same"); // false
Problem at line 3 character 7: Weird relation.
if( 1 === "1") print("same"); // false
Problem at line 3 character 11: Type confusion: '1': number and '1': string.
if( 1 === "1") print("same"); // false
Problem at line 3 character 16: Expected '{' and instead saw 'print'.
if( 1 === "1") print("same"); // false
Problem at line 3 character 16: 'print' was used before it was defined.
if( 1 === "1") print("same"); // false
/*jslint devel: true browser: true es5: true evil: false maxerr: 50 indent: 4 */
Trackback

2 comments

  1. John Fries @ 2011-11-10 02:36

    Thanks for the awesome post, Steve. I was able to follow your instructions on my ubuntu 10.04 box and am now running jslint from the command line using v8! Is there a way to send arguments to jslint through your v8jslint binary? I tried poking around in the your SConstruct file but didn’t see anything there that looked like jslint arguments. Tried ./v8jslint –help but that just brought up a bunch of v8 options. For instance, what if I wanted to set evil to true? -John

  2. John Fries @ 2011-11-10 02:52

    ah, never mind, figured it out, i looked at your code in v8jslint.cc and it’s obvious from there that all i needed to do was specify –evil=True as a value or –indent=2

Add your comment now

You must be logged in to post a comment.

css.php