29

I would like to check my JavaScript files without going to JSLint web site.
Is there a desktop version of this tool for Windows?

N 1.1
  • 12,418
  • 6
  • 43
  • 61
z-boss
  • 17,111
  • 12
  • 49
  • 81

16 Answers16

13

From http://www.jslint.com/lint.html:

The analysis is done by a script running on your machine. Your script is not sent over the network.

It is also available as a Konfabulator widget. You can check a file by dragging it and dropping it on the widget. You can recheck the file by double-clicking the widget.

It is also available in a WSH Command Line version.

It is also available in a Rhino Command Line version.

Or since JSLint is a JavaScript program running in your browser - you could grab the script and run it locally.

GitaarLAB
  • 14,536
  • 11
  • 60
  • 80
Michael Burr
  • 333,147
  • 50
  • 533
  • 760
  • yes but why would you. he updates fairly regularly. wow just saw how old this thread is lol.. – Justin Bull Mar 21 '11 at 03:24
  • 2
    if you wanted its available on [github](https://github.com/douglascrockford/JSLint) – Justin Bull Mar 21 '11 at 03:25
  • 1
    @Michael S. Scherotter - Crockford abandoned the WSH command-line version, and 404'd the existing URLs! But there's a project with a version that works: http://code.google.com/p/jslint-for-wsh/ . If you prefet jshint, there's a similarly-modified version of jshint there, too. And also a csslint for WSH. – Cheeso Oct 23 '11 at 15:28
  • I took the liberty to replace the dead link wsh-link with the latest archived version (dec 2009) – GitaarLAB Aug 28 '13 at 09:34
  • This information is outdated. Since months, WSH is not supported anymore. Furthermore the link to the Konfabulator widget is dead. I just added [two possible solutions](http://stackoverflow.com/a/18792902/282729). – feklee Sep 15 '13 at 15:58
9

You can also use JavaScript Lint on your machine,
get it from here
JavaScript Lint

There are instructions on how to integrate it into many editors/IDE's on the above site. I use it in UltraEdit and it works great.

From the above site

You can run JavaScript Lint several ways:

You can integrate it into your IDE, such as Visual Studio, SciTE, or any other IDE supporting external tools. When JavaScript Lint finds an error, your IDE takes you directly to the line containing the error.

You can run it through Windows Explorer, which Windows programmers may prefer.

You can use the command line to integrate into your build system, or maybe you're a Linux programmer and simply prefer the command line!

w4ik
  • 1,276
  • 2
  • 19
  • 33
4

Addendum to this old question: The WScript version of jslint.js produces error messages that are very much unlike error messages from any compiler.

If you want them to be similar, and if you want to be able to specify the name of the .js file in the command line, rather than using stdin to read the file, do this:

Download jslint.js, the WScript version.

Edit the jslint.js file. Scroll to the bottom and find this:

 (function(){if(!JSLINT(WScript.StdIn.ReadAll(),.....

Replace that (and everything that follows) with this:

(function(){
    var filename = "stdin";
    var content= "";
    if (WScript.Arguments.length > 0){
        filename = WScript.Arguments(0);
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        //var file = fso.GetFile(filename);
        var fs = fso.OpenTextFile(filename, 1);
        content = fs.ReadAll();
        fs.Close();
        fso = null;
        fs = null;
    } else {
        content = WScript.StdIn.ReadAll();
    }
    if(!JSLINT(content,{passfail:false})){
        WScript.StdErr.WriteLine("JSLINT");
        for (var i=0; i<JSLINT.errors.length; i++) {
            // sample error msg:
            //  sprintf.js(53,42) JSLINT: Use the array literal notation [].
            var e=JSLINT.errors[i];
            if (e !== null){
                var line = (typeof e.line == "undefined")?'0':e.line;
                WScript.StdErr.WriteLine(filename + '(' +line+','+e.character+') JSLINT: '+e.reason);
                WScript.StdErr.WriteLine('    ' + (e.evidence||'').replace(/^\s*(\S*(\s+\S+)*)\s*$/,"$1"));
            }
        }}}());

This change does two things:

  1. allows you to specify the file to run lint on, on the command line, rather than as stdin. Stdin still works if no file is specified at all.
  2. emits the error messages in a format that is more similar to most C/C++ compilers.

Then, in a cmd.exe prompt, you can do:

cscript.exe  jslint.js   MyJavascriptModule.js 

and you will get error messages like so:

JSLINT
MyJavascriptModule.js(7,17) JSLINT: 'xml' is already defined.
    var xml = new ActiveXObject("Microsoft.XMLHTTP");
MyJavascriptModule.js(10,5) JSLINT: 'xml' used out of scope.
    xml.open("GET", url, true);
MyJavascriptModule.js(11,9) JSLINT: 'xml' used out of scope.
    if (xml.overrideMimeType) {
MyJavascriptModule.js(12,9) JSLINT: 'xml' used out of scope.
    xml.overrideMimeType('text/plain; charset=x-user-defined');
MyJavascriptModule.js(14,9) JSLINT: 'xml' used out of scope.
    xml.setRequestHeader('Accept-Charset', 'x-user-defined');
MyJavascriptModule.js(17,5) JSLINT: 'xml' used out of scope.
    xml.onreadystatechange = function() {
MyJavascriptModule.js(28,5) JSLINT: 'xml' used out of scope.
    xml.send('');
MyJavascriptModule.js(34,16) JSLINT: Expected '{' and instead saw 'url'.
    if (proxy) url = proxy + '?url=' + encodeURIComponent(url);
MyJavascriptModule.js(51,16) JSLINT: Expected '{' and instead saw 'url'.
    if (proxy) url = proxy + '?url=' + encodeURIComponent(url);
Cheeso
  • 189,189
  • 101
  • 473
  • 713
4

I know this is an old one, but nobody's mentioned that JSLint is open source and available on github. https://github.com/douglascrockford/JSLint

You can use the HTML page that's included, or create your own interface using:

var options = {
    browser : true,
    plusplus : true,
    unparam : true,
    maxlen : 120,
    indent : 4 // etc
};
if (JSLINT(myCode, options)) {
    document.write('Passed!');
} else {
    document.write('Failed! :(');
}
document.write('<ul>');
for (i = 0; i < JSLINT.errors.length; i++) {
    document.write('<li><b>' + JSLINT.errors[i].line + ':</b> ' + JSLINT.errors[i].reason + '</li>');
}
document.write('</ul>');
Nathan MacInnes
  • 11,033
  • 4
  • 35
  • 50
  • And the only file "missing" (the readme says as much, but doesn't link to the compounded file he has) is currently here: http://jslint.com/web_jslint.js – ruffin May 01 '12 at 15:23
3

Can you just save the page to your hard drive?

swilliams
  • 48,060
  • 27
  • 100
  • 130
2

We've found JSLint4Java very good. If you're using Ant to build your project then the Ant task it provides is particularly useful.

JBert
  • 3,311
  • 24
  • 37
RichH
  • 6,108
  • 1
  • 37
  • 61
1

If you use notepad++, there's a JSLint plugin for you.

JSLint Plugin for Notepad++

You can find it and install from notepad++'s Plugin Manager.

syffinx
  • 351
  • 4
  • 6
1

Some more answers (not all strictly for windows) over at jslint CLI options

Community
  • 1
  • 1
Michael Paulukonis
  • 9,020
  • 5
  • 48
  • 68
1

Just save the html page to your hard drive, and then download the .js files it uses to the same location. That's the beauty of JavaScript.

Chris Pietschmann
  • 29,502
  • 35
  • 121
  • 166
1

You can integrate the tool this guy has made into Visual Studio.

http://jason.diamond.name/weblog/2008/08/09/verifying-javascript-with-jslint-and-visual-studio/#content

Just disable the options you don't need.

ssingh3
  • 125
  • 1
  • 8
1

A Visual Studio addin can be found here.

It is a bit rough but gets the job done.

I have just joined the project and will be bringing it up to date in the next few months.

Sky Sanders
  • 36,396
  • 8
  • 69
  • 90
1

There's a decent extension for Visual Studio 2010.

Matthew Sharpe
  • 3,667
  • 2
  • 25
  • 24
0

JSLint Reporter running with Node.js

Easy to keep up to date.

  1. Install Node.js.

  2. Install jslint-reporter into: C:\jslint-reporter

  3. Download JSLint:

    C:\jslint-reporter>node wrapper.js --upgrade
    
  4. Test:

    C:\Temp>node C:\jslint-reporter\wrapper.js missing_semicolon.js
    missing_semicolon.js:1:10:Expected ';' and instead saw 'console'.
    missing_semicolon.js:2:1:'console' was used before it was defined.
    

JSLint Node.js package

Easy to set up, but you rely on the package author for keeping the included JSLint up to date:

  1. Install Node.js.

  2. Using npm, the package manager of Node.js, install JSLint:

    C:\>npm -g install jslint
    
  3. Test:

    C:\Temp>jslint missing_semicolon.js
    
    missing_semicolon.js
     #1 Expected ';' and instead saw 'console'.
        var x = 5 // Line 1, Pos 10
    

Other solutions

To run JSLint, you may also use Rhino or any other JavaScript implementation that works on Windows, of course.

feklee
  • 7,555
  • 9
  • 54
  • 72
  • Followed the instructions for JSLint Node.js package, and no output appears when executing the command. You show some, so maybe there is some configuration thing missing? – Victoria Feb 04 '15 at 01:53
  • I did get the usage output when running without parameters. So I decided to "fiddle"... Adding quotes around the file name didn't help (but would if there were spaces in it, maybe). Prefixing the file name with .\ was the solution that finally worked. – Victoria Feb 04 '15 at 02:26
  • @Victoria Weird, I don't need to add `.\`. *Did you run `jslint file.js` in `cmd.exe`?* – feklee Feb 05 '15 at 21:27
  • I thought it was weird too. And yes, jslint --options file.js from cmd.exe (jsl.cmd batch file, since I wanted to --predef a fair number of items). – Victoria Feb 05 '15 at 22:02
0

Most browsers have the ability to save an "entire" page, meaning that all external files such as StyleSheets, JavaScripts etc are also downloaded and properly linked into the HTML document (usually placed in a folder next to the HTML file). So, it should definitely be possible to use the tool offline.

0

CSE HTML Validator includes JSLint and runs on Windows Desktop machines.

Albert Wiersch
  • 466
  • 5
  • 11
0

MiniME is an alternative to JSLint that runs native under windows which you might find useful.

Full disclosure, I'm behind this: http://www.toptensoftware.com/minime which does minification, obfuscation and a reasonable set of lint style checks.

Brad Robinson
  • 44,114
  • 19
  • 59
  • 88