Validates JavaScript files with JSLint as a grunt task.
Install this grunt plugin next to your project's grunt.js gruntfile with: npm install grunt-jslint
Then add this line to your project's gruntfile:
grunt.loadNpmTasks('grunt-jslint');A single-task to validate your JavaScript files with JSLint.
Supports the following options:
- files An array of files or wildcards which you want to be validated by JSLint
- exclude An array of files or wildcards which you do not want to be validated by JSLint
- directives Configuration options/settings to pre-define in JSLint. Pre-defined globals are included within this object as
predef: ['myglobal'] - options
- errorsOnly A Boolean option which tells the plugin to only display errors when set to
true - log A String/filepath option which, when provided, tells the plugin where to write a verbose log to
- junit A String/filepath option which, when provided, tells the plugin where to write a JUnit-style XML file to
- failOnError A Boolean option - defaults to
true; when set tofalse, grunt will not fail if JSLint detects an error - checkstyle A String/filepath option which, when provided, tells the plugin where to write a CheckStyle-XML file to
- shebang Ignore shebang lines (
#!/usr/bin/whatever) from files
- errorsOnly A Boolean option which tells the plugin to only display errors when set to
/*jslint node:true*/
module.exports = function (grunt) {
'use strict';
grunt.loadNpmTasks('grunt-jslint'); // load the task
grunt.initConfig({
watch: {
files: '<config:jslint.files>',
tasks: 'jslint'
},
jslint: { // configure the task
files: [ // some example files
'grunt.js',
'src/**/*.js'
],
exclude: [
'**/ignore-*.js',
'bananas.js'
],
directives: { // example directives
browser: true,
unparam: true,
todo: true,
predef: [ // array of pre-defined globals
'jQuery'
]
},
options: {
junit: 'out/junit.xml', // write the output to a JUnit XML
log: 'out/lint.log',
jslintXml: 'out/jslint_xml.xml',
errorsOnly: true, // only display errors
failOnError: false, // defaults to true
shebang: true, // ignore shebang lines
checkstyle: 'out/checkstyle.xml' // write a checkstyle-XML
}
}
});
grunt.registerTask('default', 'watch');
};All files should be validated with JSLint. Bug fixes and/or new features must be accompanied by a passing test. Tests are written with vows.
Run grunt jslint in the root of your repository.
Run ./test.sh in the root of your repository.
- better test coverage
- test-runner for Windows
- Make grunt a devDependency to speed up
npm installtime
- Fixed
failOnErrorbug (@glan) - Fixed JSLint XML bug (@glan)
- Another grunt 0.4.x support bug (@glan)
- Bug fix for XML reports (non-escaped characters)
- Added checkstyle XML reporting
- Added
shebangoption - Improved test coverage
- Re-factor everything, allowing for a test suite to be created
- Updated the outputted JUnit-style XML for better intergration with Jenkins per @sbrandwoo
- Removed unecessary dependencies
- Fix for bad template processing; thanks to @sbrandwoo
- Adding support for Grunt 0.4.x by using underscore's templating engine, rather than Grunt's version of it
- Updated JSLint to edition 2012-12-04
- Updating JSLint to "edition" 2012-11-17
- Adding option to not cause Grunt to fail if a violation is detected
- Added JSLint XML output for Jenkins Violations Plugin
- Cleaned up your
grunt.jsfile for you - moved all options into thejslintobject
- Updating README.md to contain more verbose documentation
- Adding keywords to package.json
- Added an option to only report on errors
- Added an exclude option
- Added number of files in violation to standard output
Copyright (c) 2012 Stephen Mathieson Licensed under the WTFPL license.