You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Emmanouil Batsis <Em...@eurodyn.com> on 2005/07/14 12:23:38 UTC
Use JSLint to validate .js files?
Hello,
This is a shot in the dark but i was wondering whether some other
disturbed individual has thought about validating javascript files in
Ant builds by feeding them to the JSLint [1] script via Rhino or
something. I have never done anything remotely close so any suggestions
would be appreciated.
[1] http://www.crockford.com/javascript/lint.html
Thanks,
Manos
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
[solved] Re: Use JSLint to validate .js files?
Posted by Emmanouil Batsis <Em...@eurodyn.com>.
Emmanouil Batsis wrote:
> This is a shot in the dark but i was wondering whether some other
> disturbed individual has thought about validating javascript files in
> Ant builds by feeding them to the JSLint [1] script via Rhino or
> something.
Ok, here's a usable draft implementation, hope someone finds it handy.
It's the first time i am using ecmascript inside Ant; it really rocks!
<scriptdef name="jslint" language="javascript">
<element name="fileset" type="fileset"/>
<![CDATA[
/**************************
Put JSLint code below this comment!
**************************/
/** used to format JSLint's output for the command line */
function html2text( html ){
var text = html.replace( /<[^>]*>/g, '' );
text = text.replace( /"/g, '"' );
text = text.replace( /</g, '<' );
text = text.replace( /&/g, '&' );
return text;
}
function go(sScript){
jslint.laxLineEnd = false;//!document.forms.mrof.strict.checked;
jslint.plusplus = true;//document.forms.mrof.plusplus.checked;
jslint.cap = false;//document.forms.mrof.cap.checked;
jslint.jscript = false;//document.forms.mrof.jscript.checked;
jslint(sScript);
var r = jslint.report();
if (r.substr(0, 2) != 'ok') {
//r = r.entityify();
}
//output.setHTML(r);
project.log(html2text(r));
}
var filesets = elements.get("fileset");
project.log("Number of filesets = " + filesets.size());
// iterate over given filesets
for (i = 0; i < filesets.size(); ++i) {
var fileset = filesets.get(i);
var fileSetBaseDir = fileset.getDir(project);
project.log("Processing fileset " + i + ", basedir = " +
fileSetBaseDir);
var directoryScanner = fileset.getDirectoryScanner(project);
var filePaths = directoryScanner.getIncludedFiles();
// iterate over files in current fileset
for(i=0; i < filePaths.length; i++){
var file = new java.io.File(fileSetBaseDir, filePaths[i]);
project.log("\nProcessing: "+file.getAbsolutePath());
var bufferedReader = new java.io.BufferedReader(new
java.io.FileReader(file));
var sScript = "";
while ((line = bufferedReader.readLine())){
sScript += (line + "\n");
};
go(sScript)
//project.log("File "+filePaths[i]+" contents:\n"+sScript);
};
};
]]>
</scriptdef>
<jslint>
<!-- accepts any number of filesets -->
<fileset dir="war/jsp/common/js">
<include name="*.js"/>
</fileset>
</jslint>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org