567ac015 by Adam Heath

Refactor jshint block, to make it easier to add jscs block.

1 parent 1821b5a1
......@@ -209,24 +209,22 @@ module.exports = function (grunt) {
});
}
function jshintAddExtra(src, container, dest) {
function jscheckerAddExtra(src, container, dest) {
if (src) {
container[dest] = container[dest].concat(src);
}
}
if (mpConfig.jshint) {
initConfig.jshint = {
options: mpConfig.jshint.options,
function createJschecker(name, browserOptions, modelOptions, viewOptions) {
if (!mpConfig[name]) {
return;
}
initConfig[name] = {
options: mpConfig[name].options,
all: [
'Gruntfile.js',
],
main: {
options: _.extend({}, mpConfig.jshint.browserOptions, {
globals: {
define: false,
require: false,
},
}),
options: _.extend({}, mpConfig[name].browserOptions, browserOptions),
files: {
src: [
mpConfig.base + '/scripts/*.js',
......@@ -234,12 +232,7 @@ module.exports = function (grunt) {
},
},
model: {
options: _.extend({}, mpConfig.jshint.modelOptions || mpConfig.jshint.browserOptions, {
globals: {
define: false,
require: false,
},
}),
options: _.extend({}, mpConfig[name].modelOptions, modelOptions, mpConfig[name].browserOptions, browserOptions),
files: {
src: [
mpConfig.base + '/scripts/model/**/*.js',
......@@ -247,12 +240,7 @@ module.exports = function (grunt) {
},
},
view: {
options: _.extend({}, mpConfig.jshint.viewOptions || mpConfig.jshint.browserOptions, {
globals: {
define: false,
require: false,
},
}),
options: _.extend({}, mpConfig[name].viewOptions, viewOptions, mpConfig[name].browserOptions, browserOptions),
files: {
src: [
mpConfig.base + '/scripts/view/**/*.js',
......@@ -260,13 +248,23 @@ module.exports = function (grunt) {
},
},
};
jshintAddExtra(mpConfig.jshint.all, initConfig.jshint, 'all');
jshintAddExtra(mpConfig.jshint.main, initConfig.jshint.main.files, mpConfig.base);
jshintAddExtra(mpConfig.jshint.model, initConfig.jshint.model.files, mpConfig.base);
jshintAddExtra(mpConfig.jshint.view, initConfig.jshint.view.files, mpConfig.base);
checkList.push('jshint');
jscheckerAddExtra(mpConfig[name].all, initConfig[name], 'all');
jscheckerAddExtra(mpConfig[name].main, initConfig[name].main.files, mpConfig.base);
jscheckerAddExtra(mpConfig[name].model, initConfig[name].model.files, mpConfig.base);
jscheckerAddExtra(mpConfig[name].view, initConfig[name].view.files, mpConfig.base);
checkList.push(name);
}
createJschecker(
'jshint',
{
globals: {
define: false,
require: false,
},
},
null,
null
);
if (mpConfig.csslint) {
initConfig.csslint = {
};
......