Validate files with jsbint.
This plugin requires Grunt ~0.4.0
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-jsbint --save-dev
One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-jsbint');
Run this task with the grunt jsbint
command.
Task targets, files and options may be specified according to the grunt Configuring tasks guide.
Any specified option will be passed through directly to jsbint, thus you can specify any option that jsbint supports. See the jsbint documentation for a list of supported options.
A few additional options are supported:
Type: Object
Default value: null
A map of global variables, with keys as names and a boolean value to determine if they are assignable. This is not a standard jsbint option, but is passed into the jsbint
function as its third argument. See the jsbint documentation for more information.
Type: String
Default value: null
If this filename is specified, options and globals defined therein will be used. The jshintrc
file must be valid JSON and looks something like this:
{
"curly": true,
"eqnull": true,
"eqeqeq": true,
"undef": true,
"globals": {
"jQuery": true
}
}
In this example, running grunt jsbint:all
(or grunt jsbint
because jsbint
is a [multi task][]) will lint the project's Gruntfile as well as all JavaScript files in the lib
and test
directories and their subdirectores, using the default jsbint options.
// Project configuration.
grunt.initConfig({
jsbint: {
all: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js']
}
});
In this example, running grunt jsbint
will lint both the "beforeconcat" set and "afterconcat" sets of files. This is not ideal, because dist/output.js
may get linted before it gets created via the grunt-contrib-concat plugin concat
task.
In this case, you should lint the "beforeconcat" files first, then concat, then lint the "afterconcat" files, by running grunt jsbint:beforeconcat concat jsbint:afterconcat
.
// Project configuration.
grunt.initConfig({
concat: {
dist: {
src: ['src/foo.js', 'src/bar.js'],
dest: 'dist/output.js'
}
},
jsbint: {
beforeconcat: ['src/foo.js', 'src/bar.js'],
afterconcat: ['dist/output.js']
}
});
In this example, custom jsbint options are specified. Note that when grunt jsbint:uses_defaults
is run, those files are linted using the default options, but when grunt jsbint:with_overrides
is run, those files are linted using merged task/target options.
// Project configuration.
grunt.initConfig({
jsbint: {
options: {
curly: true,
eqeqeq: true,
eqnull: true,
browser: true,
globals: {
jQuery: true
},
},
uses_defaults: ['dir1/**/*.js', 'dir2/**/*.js'],
with_overrides: {
options: {
curly: false,
undef: true,
},
files: {
src: ['dir3/**/*.js', 'dir4/**/*.js']
},
}
},
});