Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using JSLint in Notepad++

I have seen other text editors use extensions to allow syntax checkers such as JSLint, is this possible with Notepad++?

like image 885
alumb Avatar asked Jun 26 '09 00:06

alumb


3 Answers

I have managed to get two lint programs to run using the notepad++'s NppExec Plugin.

The NppExec plugin is usually installed by default and can be found under plugins -> NppExec. (Using NppExec 0.3 RC1 and Notepad++ 5.1+).

1) JSLint

first download the WSH version of jslint from http://www.jslint.com.
Modify the last part of the file as follows:

(function() {
    if(!JSLINT(WScript.StdIn.ReadAll(),{passfail:false})) {
        var e;
        for(var i in JSLINT.errors) {
            e=JSLINT.errors[i];
            WScript.StdOut.WriteLine('Lint at line '+(e.line+1)+' character '+(e.character+1)+': '+e.reason);
            WScript.StdOut.WriteLine('    '+(e.evidence||'').replace(/^\s*(\S*(\s+\S+)*)\s*$/,"$1"));
        }
        WScript.Quit(1);
    }
}());

(Pre-modified version here)
This causes JSLint to output all of the errors, not just the first one.

Next, Notepad++'s NppExec doesn't allow the use of StdIn so I wrote a batch file to actually execute the command.
This also allowed me to add a config file that is inserted before all javascript files. The options can be seen here. The batch file looks like this:

@copy /b "C:\Program Files\jslint\conf.txt"+%1 "C:\Program Files\jslint\lastoutput.txt" > temp.txt
@cscript /Nologo "C:\Program Files\jslint\jslint.js" < "C:\Program Files\jslint\lastoutput.txt"

You may need to modify the paths depending on where you put the jslint.js file. The conf.txt file looks like this:

/*jslint forin:true*/

Make sure there is no return carriage at the end of this line. If there is a return carriage all the lines counts will be off by one.

Finally, the command I entered into NppExec is:

"C:\Program Files\jslint\jslint.bat" "$(FULL_CURRENT_PATH)" 


2) Javascript Lint

Javascript lint is a slightly less strict parser and was much easier to implement.

First grab a copy of the windows version from http://www.javascriptlint.com/download.htm and unzip it. Then the NppExec command is:

"C:\Program Files\JavascriptLint\jsl.exe" -conf "C:\Program Files\JavascriptLint\jsl.default.conf" -process "$(FULL_CURRENT_PATH)"

(note: Most instructions for Javascript Lint will say to add "pauseatend" to the end of the command, I found this caused problems in Notepad++ so I left it off)

Hope this helps someone,
Cheers,
Andy.

like image 198
alumb Avatar answered Oct 19 '22 05:10

alumb


You may try JSLint Plugin for Notepad++:

https://sourceforge.net/projects/jslintnpp/

like image 41
mvladic Avatar answered Oct 19 '22 05:10

mvladic


After you've installed the plugin you should go to:

Plugins -> JSLint -> JSLint options

and change "Choose JavaScript lint tool:" to JSHint.

JSHint gives alot less meaningless "errors".

like image 4
SHEePYTaGGeRNeP Avatar answered Oct 19 '22 05:10

SHEePYTaGGeRNeP