In a previous article I told you about the existence of the violation plugin for Jenkins which can take in consideration the output generated by jslint4java.
jslint4java has an ant plugin which can be easily integrated in your environment and you need just to configure it for your javascript.
Let’s suppose you have a javascript file, in my case user-extensions.js coming from Selenium, in your repository.
At the same level create a folder named “jslint”. Under this folder place the jslint4java-2.0.1.jar file that you can find inside the zip file of jslint4java and create a build.xml file with the following content:
<project name="proj" default="main" basedir="."> <target name="main" depends="jslint"/> <taskdef name="jslint" classname="com.googlecode.jslint4java.ant.JSLintTask" classpath="jslint4java-2.0.1.jar" /> <target name="jslint"> <jslint haltOnFailure="false" options="sloppy"> <predef>selenium,Selenium,storedVars,LOG,Assert</predef> <formatter type="xml" destfile="jslint.xml"/> <fileset dir="../" includes="user-extensions.js"/> </jslint> </target> </project>
In practice in the taskdef tag we say where the jar file is located (same folder), in the jslint tag I specified:
- haltOnFailure=”false”, to not make stop and fail the plugin if a violation is found (in this way the entire job in Jenkins will not fail)
- options=”sloppy”, to disable the strict control in the file (used for ECMAScript 5)
- using predefined variables like “selenium” with the predef tag
- specifying the output file (in the same folder) in xml format (useful for the violation plugin)
- specifying just the input file that I have (which is in the top folder)
Once the folder is created with the 2 files (build.xml and jslint4java jar file) in the repository let’s go to the Jenkins job to install the violation plugin and configure the job.
First let’s configure the ant task in the Job (my directory is under trunk/test):
Then we configure the Violation plugin in the Job:
Let’s save and run the build and we should see a graph the following in the Job page:
If you click on the left menu on Violations (or in the graph) you will see the same graph with the number of violations per file:
If you click on the filename you will see all the violations with the respective row numbers:
If you click on the row number you can see the line of the code (just below):
Enjoy fixing your javascript file :-)