How to run JSLint in command line on Windows

I use JSLint for JavaScript code quality control.

How to run JSLint in Windows command line?

Windows has it’s own JavaScript build-in engine Windows Script Host. It starts by command line tool cscript. Thus it easy to run JavaScript programs under Widnows, we just need to learn JSLint to get arguments from command line through cscript and send messages back to console.

1. Prepare jslint,js

Lets first download the latest jslint from github.

At the end of jslint.js we have to put this peace of code:

Here options variabel contains parameters to run JSLint. This is a set of parameters that I usually use in my projects.

2. Command file

Lets write a command file that will start cscript with jslint.js and give it an argument – the name of the checking file.

The first line prints the argument – a name of the file to check. It can be helpful as a working indicator when check multiple files. The second line starts jslint.js and sends an argument to it. The weird combination of %~dp0 means current directory (read more about variable substitution in Windows command line here or simply write FOR /? in console).

Name this command file jslint.cmd and place it in the same folder where jslint.js is. Add path to this folder to our system PATH variable.

That’s it. Now we can check JavaScript files with JSLint from Windows command line. If JSLint finds a problem it writes about it to console. For example:

3. ANT Integration

But we need an automated task to check many files in project at once and for continues integration, right? Lets write an ANT-task.

Save file as jslilnt.xml in the project folder. Now we can run from command line: