JsLint for Grails

0 vote
Dependency:
compile ":jslint:0.6"

 Documentation  Source  Issues

Summary

A Grails command line script to run JsLint on javascript files.There is also an option to produce html reports.

Installation

To install the plugin add the plugin dependency:

grails-app/conf/BuildConfig.groovy

plugins {
    compile ':jslint:0.6'
}

Description

JsLint for Grails

A Grails command line script to run JsLint on javascript files. This plugin will add a command jslint to the grails command line, which will run jslint on the web-app/js directory when you type in grails jslint. The plugin utilizes the jslint4java library and exposes the configuration through a grails config file. The output is configurable via the jslint.reports you must send the output somewhere.

Installation

To install the plugin add the plugin dependency:

plugins {
    compile ':jslint:0.6'
}

Configuration

You can configure the plugin by creating a JsLintConfig.groovy file. For more information on the jslint configuration options see the jslint4java ant task documentation.

One difference is to define global variables that JSLint shouldn't complain about you need to pass them in via jslint.preDef not with the other options in jslint.options

grails-app/conf/JsLintConfig.groovy

jslint.options = "white"
jslint.directory = "web-app/js"
jslint.includes = "**/*.js"
jslint.excludes = "**/*.min.js, **/i18n/**/*.js, **/prototype/*.js,**/*-min.js,**/*.pack.js"
jslint.haltOnFailure = false
jslint.preDef= "\$"
jslint.reports = {

MyXmlReport('xml') { // The report name "MyXmlReport" is user-defined; Report type is 'xml' destfile = 'target/test-reports/jslint.xml' // Set the 'outputFile' property of the (XML) Report } MyHtmlReport('report') { // Report type is 'html' destfile = 'target/test-reports/jslint.html' } }

Example Usage

1 Create a JsLintConfig config file. This example file will run jslint on all js files in the web-app/js directory and exclude the prototype director.

jslint.options = "white"
jslint.directory = "web-app/js"
jslint.includes = "**/*.js"
jslint.excludes = "**/*.min.js, **/i18n/**/*.js, **/prototype/*.js,**/*-min.js,**/*.pack.js"
jslint.haltOnFailure = false
jslint.preDef = "\$"
jslint.reports = {

MyXmlReport('xml') { // The report name "MyXmlReport" is user-defined; Report type is 'xml' destfile = 'target/test-reports/jslint.xml' // Set the 'outputFile' property of the (XML) Report } MyHtmlReport('report') { // Report type is 'html' destfile = 'target/test-reports/jslint.html' } }

2 Run jslint from the command line

grails jslint

3 View output from jslint. The example above is set up to output a HTML report and a XML report. The HTML report is human readable and with the above set up will so up in the tagert/test-reports directory. The xml report can be used by other system for example the Jenkins Violations plugin.