I would like to run the jshint
task twice in GruntJS
, but with different options each time.
How would I go about doing something like that?
Currently, my Gruntfile.js
looks like this:
'use strict';
module.exports = function(grunt) {
var opts = {
pkg: grunt.file.readJSON('package.json'),
jasmine_node: {
matchall: true,
forceExit: true
},
jshint: {
files: [
'gruntfile.js',
'src/**/*.js', '!src/static/bin', '!src/static/js/libs/*.js',
'test/spec/**/*.js'
],
options: {
jshintrc: '.jshintrc'
}
}
};
grunt.initConfig(opts);
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-jasmine-node');
grunt.registerTask('default', ['jshint', 'jasmine_node']);
grunt.registerTask('travis', ['jshint', 'jasmine_node']);
};
And I would probably want it to be something like this:
var jshint: {
files: [
'gruntfile.js',
'src/**/*.js', '!src/static/**',
'test/spec/**/*.js'
],
options: {
jshintrc: '.jshintrc'
}
}
var jshint2 = {
files: [
'src/static/**/*.js',
'!src/static/bin',
'!src/static/js/libs/*.js'
],
options: {
jshintrc: '.jshintrc-browser'
}
};
So that I can pick different options for the front-end javascript and the NodeJS javascript, since linting should be different for each of those environments
jshint
is a multitask. So it is possible to have to following config:
jshint: {
browser: {
files: [
'src/static/**/*.js',
'!src/static/bin',
'!src/static/js/libs/*.js'
],
options: {
jshintrc: '.jshintrc-browser'
}
},
node: {
files: [
'gruntfile.js',
'src/**/*.js', '!src/static/**',
'test/spec/**/*.js'
],
options: {
jshintrc: '.jshintrc'
}
}
}
To run the browser version:
grunt jshint:browser
.
To run to node version:
grunt jshint:node
.
Running just:
grunt jshint
will run both.
Of course, you probably will want to trigger them via another task, e.g:
grunt.registerTask('build', ['clean:all', 'jshint:browser', ...]);
You want want to read the section Specifying JSHint options and globals for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With