|
JSLintAntTask
A custom task for ant which invokes jslint4java
IntroductionJSLint is a lint-like tool for JavaScript files. It finds problematic constructs and warns you about them. jslint4java wraps it, so it's callable from Java. In addition, it provides an ant task so that it can be invoked automatically as part of your build procedure. For more detail on precisely what is checked, please see the original documentation. Presently, jslint4java requires Java 5 and ant 1.6.5. Parameters
The valid list of options is defined by the Option enum, and comprises of:
Parameters specified as nested elementsfilesetOne or more filesets may be specified in order to identify javascript files to check. This uses the standard ant fileset data type. formatterZero or more formatter elements may be specified in order to control output from jslint. Each formatter element has two attributes.
If no formatter elements are present, then no output will be produced. However, the build will still fail if the validation fails. ExamplesFirst, you need to define the task in your build file. <taskdef name="jslint"
classname="net.happygiraffe.jslint.ant.JSLintTask"
classpath="/path/to/jslint4java-1.2+rhino.jar" />If you already have rhino in your classpath, you may use the jslint4java-1.2.jar instead. You may also use the antlibs facility to pull in JSLint. <project xmlns:jsl="antlib:net.happygiraffe.jslint">
…
</project>Doing so will require you to access the jslint task as jsl:jslint. To check a directory for all .js files, and emit all errors to the console: <jslint>
<formatter type="plain" />
<fileset dir="web/js" includes="*.js" />
</jslint>To check a directory for all .js files, excluding packed files. Send any problems to a file jslint.out. <jslint>
<formatter type="plain" destfile="${build.dir}/jslint.out" />
<fileset dir="web/js" includes="**/*.js" excludes="**/*.pack.js" />
</jslint>To check a directory of JavaScript files, whilst warning about whitespace issues and undefined variables. Send the errors to the console, and also emit an XML report to the build directory. <jslint options="undef,white">
<formatter type="plain" />
<formatter type="xml" destfile="${build.dir}/jslint.xml" />
<fileset dir="web/js" includes="**/*.js" excludes="**/*.pack.js" />
</jslint>
|
Sign in to add a comment
JSLint doesn't seem to support redirecting the standard out to capture the report.
hi is there any way I can capture the output to write it to a file?
Guys i have added support for logging to a text file, if you are interested, i can send you the jar files & the source files.
Yeah, if you can please send them
Thanks.
Chathu, the latest source from svn has reporting capability. Just download the sources and build them.
I work on a project that is still in Java 1.4, so i backported this to work with jdk 1.4. So what i have is my own version of the sources & it has different options.
I have created the jars for the latest version from svn. You can download them from here http://www.4shared.com/dir/7430194/d2e639ac/JSLint.html
Just follow the instructions on the wiki
Praveen, the link you specified is not valid. Can you send me the latest files.?
I recently upgraded to 1.2.1 and have no problems. But, in case that's not possible; a cheap and easy workaround to log the output is to create an ant task that calls another ant task. Like so:
<target name="jslint" description="Checks JavaScript files for problems."> <echo message="Linting JavaScript..." /> <ant antfile="build.xml" target="jslint-actual" output="${reports}/jslint.txt" /> </target>Then, just create your "jslint-actual" task as normal.
Is there any way to pass the "predef" option to define custom global variables?