Is there an offline version of JSLint for Windows?

前端 未结 16 1740
刺人心
刺人心 2021-02-05 03:05

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

相关标签:
16条回答
  • 2021-02-05 03:12

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

    0 讨论(0)
  • 2021-02-05 03:14

    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.

    0 讨论(0)
  • 2021-02-05 03:15

    There's a decent extension for Visual Studio 2010.

    0 讨论(0)
  • 2021-02-05 03:17

    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.

    0 讨论(0)
  • 2021-02-05 03:18

    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>');
    
    0 讨论(0)
  • 2021-02-05 03:19

    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);
    
    0 讨论(0)
提交回复
热议问题