Configure grunt-contrib-jshint options with multiple targets

When linting, different JSHint options are needed for front-end and back-end
JavaScript. We can specify different targets in grunt-contrib-jshint. But
there is something to be careful:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
jshint: {
// Task level options
options: {
jshintrc: './.jshintrc'
},
node: {
// Target level options
options: {
node: true
}
},
jquery: {
// Target level options
options: {
globals: {
jQuery: true
}
}
}
}

I thought the target level options will merge with the task level, but it does
not happen. Need to dig deeper to figure out why jshintrc option is not merged
with JSHint options. A quick fix is to load the JSHint JSON file directly:

1
2
3
4
5
6
7
8
9
10
jshint: {
// Task level options
options: grunt.file.readJSON('./.jshintrc'),
node: {
// Target level options
options: {
node: true
}
}
}

In this case, if jshint:node target was run, the merged options will be parsed
to JSHint.