If you are using maven to build an application which contains JavaScript, you can arrange for JSLint to run automatically.
Here's an example configuration.
<project> … <build> … <plugins> … <plugin> <groupId>com.googlecode.jslint4java</groupId> <artifactId>jslint4java-maven-plugin</artifactId> <version>2.0.2</version> <executions> <execution> <id>lint</id> <phase>process-resources</phase> <goals> <goal>lint</goal> </goals> <configuration> <failOnError>true</failOnError> <options> <undef>true</undef> </options> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
This will arrange for the jslint4java-maven-plugin to execute before
the rest of your build. If you would prefer to execute it afterwards,
choose <phase>verify</phase>
instead.
If you would prefer to run the linter on an ad-hoc basis, you can call the plugin from the command line.
$ mvn jslint4java:lint
In order to support this, you should still configure the plugin as part of your project, but not bind it to the lifecycle. e.g.
<project> … <build> … <plugins> … <plugin> <groupId>com.googlecode.jslint4java</groupId> <artifactId>jslint4java-maven-plugin</artifactId> <version>2.0.2</version> <configuration> <failOnError>true</failOnError> <options> <undef>true</undef> </options> </configuration> </plugin> </plugins> </build> </project>
The plugin is mainly controlled via the
<configuration>
element.
It supports these children.
Element | Description | Default |
---|---|---|
<encoding> |
What encoding to read the source files in. |
<encoding>UTF-8</encoding> |
<excludes> |
A comma separated list of patterns to exclude from linting. |
<excludes> <!-- no excludes by default --> </excludes> |
<includes> |
A comma separated list of filename patterns lint. |
<includes> <include>**/*.js</include> </includes> |
<jslintSource> |
An alternative jslint.js to use, in case the builtin version is insufficient. |
<!-- The builtin version. --> <jslintSource></jslintSource> |
<options> |
Which options to pass to JSLint. Each option must be specified as
child element, e.g.
<maxlen>72</maxlen> <predef>console, jQuery</predef> <undef>true</undef>Please see Option for the full list of Options that can be specified. |
<options> <!-- no options enabled by default --> </options> |
<outputDirectory> |
Where to write the report files. JSLint generates the same report in several
different formats.
|
<outputDirectory>/Users/hdm/work/jslint4java/target/checkout/jslint4java-docs/target/jslint4java</outputDirectory> |
<sourceFolders> |
One or more folders to find the JavaScript files to lint. |
<sourceFolders> <sourceFolder>/Users/hdm/work/jslint4java/target/checkout/jslint4java-docs/src/main/webapp</sourceFolder> </sourceFolders> |
<timeout> |
How many seconds JSLint is allowed to run for. |
<!-- infinite --> <timeout>0</timeout> |