JSLint integration...

57 views
Skip to first unread message

Alberto Santini

unread,
Apr 9, 2008, 10:31:10 AM4/9/08
to scite-interest
Hello.

If you are writing javascript code and you are looking for a
javascript validation, I suggest the following solution:

- Download JSLint (http://www,jslint.com): http://www.jslint.com/fulljslint.js

- Add at the end of the file 'fulljslint.js' the code:

------------------------------- cut --------------------------------
/*members Arguments, Count, StdErr, WriteLine, Quit, OpenTextFile,
Close, ReadAll*/
(function () {
if (WScript.Arguments.Count() != 1) {
WScript.StdErr.WriteLine("Usage: cscript fulljslint.js
{javascript_file}");
WScript.Quit(1);
}

var filename = WScript.Arguments(0);
var objFSO = new ActiveXObject("Scripting.FileSystemObject");
var objTextFile = objFSO.OpenTextFile(filename);
var sReadAll = objTextFile.ReadAll();
objTextFile.Close();

// Customize the options to change the behaviour of JSLint
validation
// See allOptions about the options available
var options = {
passfail: false
};
if (!JSLINT(sReadAll, options)) {
var e = JSLINT.errors;
for (i = 0; i < e.length; i++) {
// Customize the output to integrate JSlint in your editor or
ide
// See JSLINT.errors about object members
WScript.StdErr.WriteLine(filename + ':' + (e[i].line + 1) + ': '
+ e[i].reason);
}
WScript.Quit(1);
}
})();
------------------------------- cut --------------------------------

- Copy the file 'fulljslint.js' to the User Options directory.

- Add to your User Options file the following line:

command.go.*.js=cscript /nologo "$(SciteUserHome)\fulljslint.js" $
(FileNameExt)

- Open a javascript file (.js), press F5 to validate and navigate
between the errors, if any, with F4.

- Tested with JSLint Edition 2008-04-08 and SciTe 1.76.


Thanks Mr. D. Crockford (JSLint creator) and, of course, Mr. N.
Hodgson (SciTe creator).

Enjoy,
Alberto Santini

Alberto Santini

unread,
Apr 9, 2008, 11:29:31 AM4/9/08
to scite-interest
Hello.

Because JSLint works fine with javascript embedded in a html page I
suggest to add to your User Options file the following lines:

command.name.5.*=JSLint
command.5.*=cscript /nologo "$(SciteUserHome)\fulljslint.js" $
(FileNameExt)
command.subsystem.5.*=0
command.mode.5.*=savebefore:yes

So, with a html page, F5 will open the browser and CTRL-5 will execute
JSLint.

I paste again the code with the hope the formatting is not
destroyed...
-------------------------- snippet ---------------------
/*members Arguments, Count, StdErr, WriteLine, Quit,
OpenTextFile, Close, ReadAll*/
(function () {
if (WScript.Arguments.Count() != 1) {
WScript.StdErr.WriteLine(
"Usage: cscript fulljslint.js {javascript_file}");
WScript.Quit(1);
}

var filename = WScript.Arguments(0);
var objFSO = new ActiveXObject(
"Scripting.FileSystemObject");
var objTextFile = objFSO.OpenTextFile(filename);
var sReadAll = objTextFile.ReadAll();
objTextFile.Close();

// Customize the options to change the behaviour
// See allOptions about the options available
var options = {
passfail: false
};
if (!JSLINT(sReadAll, options)) {
var e = JSLINT.errors;
for (i = 0; i < e.length; i++) {
// Customize the output to integrate JSlint in your ide
// See JSLINT.errors about object members
WScript.StdErr.WriteLine(filename + ':'
+ (e[i].line + 1) + ': ' + e[i].reason);
}
WScript.Quit(1);
}
})();
-------------------------- snippet ---------------------

Regards,
Alberto Santini
Reply all
Reply to author
Forward
0 new messages