JSLint in Programmer’s Notepad, Revisited

This is an update to my previous post, Programmer’s Notepad and JSLint. After a few dev versions where the tools didn’t work they’re back in fighting shape. There were a few annoyances with my previous version around the actual running of JSLint. The WSH build of JSLint on www.jslint.com is set to return after only a single error & reads from Standard Input.

I finally got fed up enough with these limitations to figure out how to fix them.

  1. Grab the fulljslint.js from the very bottom of http://www.jslint.com/lint.html
  2. Grab wsh.js
  3. Concatenate the files together, I saved mine as C:\Users\Pcavit\tools\jslint.js for easy referencing via the %USERPROFILE% environment variable
  4. Then I had to modify the wsh.js portion to read in the file from disk instead of Standard Input & output multiple errors. Here’s my version:
(function () {
	var fso = new ActiveXObject("Scripting.FileSystemObject"),
            f = fso.OpenTextFile(WScript.Arguments(0), 1),
            contents = "";
 
	while(!f.AtEndOfStream) {
		contents += f.ReadAll();
	}
 
	if (!JSLINT(contents, { browser: true, css: true, onevar: true, bitwise: true, regexp: true, newcap: true, immed: true })) {
		var e, i, l;
 
		for(i = 0, l = JSLINT.errors.length; i < l; i++) {
			e = JSLINT.errors[i];
 
			WScript.StdErr.WriteLine('Lint at line ' + e.line + ' character ' + e.character + ': ' + e.reason);
			WScript.StdErr.WriteLine((e.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
			WScript.StdErr.WriteLine("");
		}
 
		WScript.Quit(1);
       }
}());

Once you’ve done that you’ll want to change a few tools settings.

And now you can get multiple error output, with clickable errors. It’s totally awesome.

Comments are closed.