21

Javascript code can be tough to maintain.
I am looking for tools that will help me ensure a reasonable quality level.
So far I have found JsUNit, a very nice unit test framework for javascript. Tests can be run automatically from ant on any browser available.
I have not found yet some javascript equivalent of PMD, checkstyle, Findbug...

Do you know any static code analysis tool for javascript ?

Rob W
  • 341,306
  • 83
  • 791
  • 678
Alexandre Victoor
  • 3,104
  • 2
  • 27
  • 27
  • Your title doesn't seem to make sense. What does maven have to do with JavaScript quality control? – SCdF Sep 18 '08 at 20:05
  • 2
    Fixed the title. Also, Maven has a lot to do with quality control over any source code and because it can automatically and consistently pump out builds and synchronized quality reports for developers from desktops and CI servers. – Dave Feb 09 '12 at 20:15

10 Answers10

13

This is an old thread, but if you're interested in running Jasmine for BDD testing in your maven project, I wrote this jasmine-maven-plugin for exactly this purpose (that is, improving JS quality by encouraging TDD of it).

http://github.com/searls/jasmine-maven-plugin

Justin Searls
  • 4,789
  • 4
  • 45
  • 56
11

I've used the following code to run JSLint as part of the COMPILE phase in Maven.

It downloads jslint4java from maven repository so you don't need anything else.

If JSLint found problems in javascript files, the build will fail.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <target>
                            <taskdef name="jslint" classname="com.googlecode.jslint4java.ant.JSLintTask" classpath="${settings.localRepository}/com/googlecode/jslint4java/jslint4java-ant/1.4.2/jslint4java-ant-1.4.2.jar" />
                            <jslint options="white,browser,devel,undef,eqeqeq,plusplus,bitwise,regexp,strict,newcap,immed">
                                <predef>Ext,Utils</predef>
                                <formatter type="plain" />
                                <fileset dir="${basedir}/src/main/resources/META-INF/resources/js" includes="**/*.js" />
                            </jslint>
                        </target>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>com.googlecode.jslint4java</groupId>
                    <artifactId>jslint4java-ant</artifactId>
                    <version>1.4.2</version>
                </dependency>
            </dependencies>
        </plugin>
Gian Marco
  • 22,140
  • 8
  • 55
  • 44
6

Wro4j-maven-plugin provides several goals for static code analysis for JavaScript and CSS resources as well, like: jslint, jshint and csslint

Here is a link to the official Wro4j-maven-plugin documentation.

aaron
  • 39,695
  • 6
  • 46
  • 102
Alex Objelean
  • 3,893
  • 2
  • 27
  • 36
4

A couple of plugins I've submitted at Codehaus may also be of interest:

http://mojo.codehaus.org/js-import-maven-plugin/

http://mojo.codehaus.org/jslint-maven-plugin/

The first one brings Maven dependency management to JavaScript. The second one allows the rapid and efficient invocation of JSLint.

Barend
  • 17,296
  • 2
  • 61
  • 80
Christopher Hunt
  • 2,071
  • 1
  • 16
  • 20
1

This project looks close:

http://dev.abiss.gr/mvn-jstools/index.html

It generates a report with JsLint. It doesn't look like it hooks into the test phase of the build lifecycle, so I don't think it will reject a build if jslint finds issues (which is what I'd like to do on my projects).

James Cooper
  • 2,320
  • 2
  • 23
  • 23
1

A quick Google for "jslint ant task" reveals jslint4java, which apparently includes an Ant task.

Hank Gay
  • 70,339
  • 36
  • 160
  • 222
1

jslint4java has been mentioned a few times, I can't recall which version they added it, but there's actually a built in Maven task.

Traditionally with jslint4java and Maven, folks have used the antrun plugin to run the jslint4java ant task, however you can now configure it all in Maven and avoid that extra step.

http://docs.jslint4java.googlecode.com/git/2.0.2/maven.html

Ghosty
  • 3,203
  • 2
  • 18
  • 13
0

I've worked on the SweetDEV RIA project which is a Java tag library composed of several "Web 2.0/Ajax/JavaScript" components.

The maven 2 build process includes some in-house plugins which launches JSLint (code verifier), JsMin (code minifier), JsDoc generation (JavaDoc like documentation), JsUnit (unit tests) and Selenium (in browser) tests .

You may take a look on the SweetDEV RIA maven plugins repository.

paulgreg
  • 18,493
  • 18
  • 46
  • 56
  • Could you edit your answer and fix the broken link at the end? And replace `jsunit.net` link with https://github.com/pivotal/jsunit (the jsunit.net domain has been taken by an ad company) – Rob W Jun 08 '13 at 14:12
0

The new jslint-maven-plugin looks useful. It wraps jslint4java, executing JSLint during the test phase of your build.

wachunga
  • 231
  • 3
  • 10
-1

Sonar and the JavaScript Plugin: http://docs.codehaus.org/display/SONAR/JavaScript+Plugin

  • Welcome to SO. Please be more specific with you answer quoting and reasoning about the provided link. – Tony Rad Nov 13 '12 at 16:28