Refactor jshint block, to make it easier to add jscs block.
Showing
1 changed file
with
27 additions
and
29 deletions
... | @@ -209,24 +209,22 @@ module.exports = function (grunt) { | ... | @@ -209,24 +209,22 @@ module.exports = function (grunt) { |
209 | }); | 209 | }); |
210 | } | 210 | } |
211 | 211 | ||
212 | function jshintAddExtra(src, container, dest) { | 212 | function jscheckerAddExtra(src, container, dest) { |
213 | if (src) { | 213 | if (src) { |
214 | container[dest] = container[dest].concat(src); | 214 | container[dest] = container[dest].concat(src); |
215 | } | 215 | } |
216 | } | 216 | } |
217 | if (mpConfig.jshint) { | 217 | function createJschecker(name, browserOptions, modelOptions, viewOptions) { |
218 | initConfig.jshint = { | 218 | if (!mpConfig[name]) { |
219 | options: mpConfig.jshint.options, | 219 | return; |
220 | } | ||
221 | initConfig[name] = { | ||
222 | options: mpConfig[name].options, | ||
220 | all: [ | 223 | all: [ |
221 | 'Gruntfile.js', | 224 | 'Gruntfile.js', |
222 | ], | 225 | ], |
223 | main: { | 226 | main: { |
224 | options: _.extend({}, mpConfig.jshint.browserOptions, { | 227 | options: _.extend({}, mpConfig[name].browserOptions, browserOptions), |
225 | globals: { | ||
226 | define: false, | ||
227 | require: false, | ||
228 | }, | ||
229 | }), | ||
230 | files: { | 228 | files: { |
231 | src: [ | 229 | src: [ |
232 | mpConfig.base + '/scripts/*.js', | 230 | mpConfig.base + '/scripts/*.js', |
... | @@ -234,12 +232,7 @@ module.exports = function (grunt) { | ... | @@ -234,12 +232,7 @@ module.exports = function (grunt) { |
234 | }, | 232 | }, |
235 | }, | 233 | }, |
236 | model: { | 234 | model: { |
237 | options: _.extend({}, mpConfig.jshint.modelOptions || mpConfig.jshint.browserOptions, { | 235 | options: _.extend({}, mpConfig[name].modelOptions, modelOptions, mpConfig[name].browserOptions, browserOptions), |
238 | globals: { | ||
239 | define: false, | ||
240 | require: false, | ||
241 | }, | ||
242 | }), | ||
243 | files: { | 236 | files: { |
244 | src: [ | 237 | src: [ |
245 | mpConfig.base + '/scripts/model/**/*.js', | 238 | mpConfig.base + '/scripts/model/**/*.js', |
... | @@ -247,12 +240,7 @@ module.exports = function (grunt) { | ... | @@ -247,12 +240,7 @@ module.exports = function (grunt) { |
247 | }, | 240 | }, |
248 | }, | 241 | }, |
249 | view: { | 242 | view: { |
250 | options: _.extend({}, mpConfig.jshint.viewOptions || mpConfig.jshint.browserOptions, { | 243 | options: _.extend({}, mpConfig[name].viewOptions, viewOptions, mpConfig[name].browserOptions, browserOptions), |
251 | globals: { | ||
252 | define: false, | ||
253 | require: false, | ||
254 | }, | ||
255 | }), | ||
256 | files: { | 244 | files: { |
257 | src: [ | 245 | src: [ |
258 | mpConfig.base + '/scripts/view/**/*.js', | 246 | mpConfig.base + '/scripts/view/**/*.js', |
... | @@ -260,13 +248,23 @@ module.exports = function (grunt) { | ... | @@ -260,13 +248,23 @@ module.exports = function (grunt) { |
260 | }, | 248 | }, |
261 | }, | 249 | }, |
262 | }; | 250 | }; |
263 | jshintAddExtra(mpConfig.jshint.all, initConfig.jshint, 'all'); | 251 | jscheckerAddExtra(mpConfig[name].all, initConfig[name], 'all'); |
264 | jshintAddExtra(mpConfig.jshint.main, initConfig.jshint.main.files, mpConfig.base); | 252 | jscheckerAddExtra(mpConfig[name].main, initConfig[name].main.files, mpConfig.base); |
265 | jshintAddExtra(mpConfig.jshint.model, initConfig.jshint.model.files, mpConfig.base); | 253 | jscheckerAddExtra(mpConfig[name].model, initConfig[name].model.files, mpConfig.base); |
266 | jshintAddExtra(mpConfig.jshint.view, initConfig.jshint.view.files, mpConfig.base); | 254 | jscheckerAddExtra(mpConfig[name].view, initConfig[name].view.files, mpConfig.base); |
267 | checkList.push('jshint'); | 255 | checkList.push(name); |
268 | } | 256 | } |
269 | 257 | createJschecker( | |
258 | 'jshint', | ||
259 | { | ||
260 | globals: { | ||
261 | define: false, | ||
262 | require: false, | ||
263 | }, | ||
264 | }, | ||
265 | null, | ||
266 | null | ||
267 | ); | ||
270 | if (mpConfig.csslint) { | 268 | if (mpConfig.csslint) { |
271 | initConfig.csslint = { | 269 | initConfig.csslint = { |
272 | }; | 270 | }; | ... | ... |
-
Please register or sign in to post a comment