Skip to content

Commit

Permalink
Gulpfile: no files are exempt from style checks
Browse files Browse the repository at this point in the history
- Streams are merged to make sure that all errors and warnings are reported.
- Adds dev dependencies: `merge-stream` and `lazypipe`.
- Tracks a fork of `gulp-jshint` to fix spalger/gulp-jshint#88
  • Loading branch information
Slayer95 committed Feb 18, 2015
1 parent 6186a6b commit d37c04e
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 59 deletions.
182 changes: 130 additions & 52 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
var path = require('path');
var util = require('util');

var gulp = require('gulp');
var jshintStylish = require('jshint-stylish');
var gutil = require('gulp-util'); // Currently unused, but gulp strongly suggested I install...
var jshint = require('gulp-jshint');
var lazypipe = require('lazypipe');
var merge = require('merge-stream');
var jscs = require('gulp-jscs');
var jshint = require('gulp-jshint');
var replace = require('gulp-replace');
var jshintStylish = require('./' + path.relative(__dirname, require('jshint-stylish')));

var globals = {};
var globalList = [
'Config', 'ResourceMonitor', 'toId', 'toName', 'string', 'LoginServer',
'Users', 'Rooms', 'Verifier', 'CommandParser', 'Simulator', 'Tournaments',
'Dnsbl', 'Cidr', 'Sockets', 'Tools', 'TeamValidator'
];
globalList.forEach(function (identifier) {globals[identifier] = false;});

function transformLet () {
// Replacing `var` with `let` is sort of a hack that stops jsHint from
// complaining that I'm using `var` like `let` should be used, but
// without having to deal with iffy `let` support.

var jsHintOptions = {
return lazypipe()
.pipe(replace.bind(null, /\bvar\b/g, 'let'))();
}

function lint (jsHintOptions, jscsOptions) {
return lazypipe()
.pipe(jshint.bind(jshint, jsHintOptions, {timeout: 150000}))
.pipe(jscs.bind(jscs, jscsOptions))();
}

var jsHintOptions = {};
jsHintOptions.base = {
"nonbsp": true,
"nonew": true,
"noarg": true,
Expand All @@ -21,41 +50,30 @@ var jsHintOptions = {
"node": true,
"eqeqeq": true,

"globals": {
"Config": false,
"ResourceMonitor": false,
"toId": false,
"toName": false,
"string": false,
"LoginServer": false,
"Users": false,
"Rooms": false,
"Verifier": false,
"CommandParser": false,
"Simulator": false,
"Tournaments": false,
"Dnsbl": false,
"Cidr": false,
"Sockets": false,
"Tools": false,
"TeamValidator": false
}
"globals": globals
};
jsHintOptions.legacy = util._extend(util._extend({}, jsHintOptions.base), {
"es3": true
});
jsHintOptions.test = util._extend(util._extend({}, jsHintOptions.base), {
"globals": util._extend(globals, {
"BattleEngine": false
}),
"mocha": true
});

var jscsOptions = {
"excludeFiles": ["./**/pokedex.js", "./**/formats-data.js", "./**/learnsets.js", "./**/learnsets-g6.js", "./config/config.js"],
"esnext": "true",

var jscsOptions = {};
jscsOptions.base = {
"preset": "yandex",

"requireCurlyBraces": null,

"maximumLineLength": null,
"validateIndentation": '\t',
"validateQuoteMarks": null,
"disallowYodaConditions": null,
"disallowQuotedKeysInObjects": null,
"requireDotNotation": null,
"disallowYodaConditions": null,

"disallowMultipleVarDecl": null,
"disallowImplicitTypeConversion": null,
Expand Down Expand Up @@ -88,37 +106,97 @@ var jscsOptions = {
"requireCapitalizedConstructors": true,

"validateLineBreaks": 'CI' in process.env ? 'LF' : null,
"disallowMultipleLineBreaks": null
};

gulp.task('data', function () {
var directories = ['./data/*.js', './mods/*/*.js'];
jsHintOptions['es3'] = true;
"disallowMultipleLineBreaks": null,

// Replacing `var` with `let` is sort of a hack that stops jsHint from
// complaining that I'm using `var` like `let` should be used, but
// without having to deal with iffy `let` support.
"esnext": true
};
jscsOptions.config = util._extend(util._extend({}, jscsOptions.base), {
"disallowTrailingComma": null
});
jscsOptions.dataCompactArr = util._extend(util._extend({}, jscsOptions.base), {
"requireSpaceAfterBinaryOperators": ["="],
"requireSpaceBeforeBinaryOperators": ["="],
"disallowSpaceAfterBinaryOperators": [","],
"disallowSpaceBeforeBinaryOperators": [","]
});
jscsOptions.dataCompactAll = {
"disallowTrailingComma": true,

return gulp.src(directories)
.pipe(jscs(jscsOptions))
.pipe(replace(/\bvar\b/g, 'let'))
.pipe(jshint(jsHintOptions))
.pipe(jshint.reporter(jshintStylish))
.pipe(jshint.reporter('fail'))
.pipe(jscs(jscsOptions));
"validateLineBreaks": 'CI' in process.env ? 'LF' : null,
"requireLineFeedAtFileEnd": true,
"requireSpaceAfterBinaryOperators": ["="],
"requireSpaceBeforeBinaryOperators": ["="],

"validateQuoteMarks": "\"",
"disallowQuotedKeysInObjects": "allButReserved",

"disallowSpaceAfterObjectKeys": true,
"disallowSpaceBeforeObjectValues": true,
"disallowSpacesInsideBrackets": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideObjectBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowSpaceAfterBinaryOperators": [","],
"disallowSpaceBeforeBinaryOperators": [","]
};
jscsOptions.dataCompactAllIndented = util._extend(util._extend({}, jscsOptions.dataCompactAll), {
"validateIndentation": '\t'
});

gulp.task('fastlint', function () {
var directories = ['./*.js', './tournaments/*.js', './chat-plugins/*.js', './config/*.js'];
delete jsHintOptions['es3'];
var lintData = [
{
dirs: ['./*.js', './tournaments/*.js', './chat-plugins/*.js', './config/!(config).js', './**/scripts.js', './**/rulesets.js', './**/statuses.js'],
jsHint: jsHintOptions.base,
jscs: jscsOptions.base
}, {
dirs: ['./config/config*.js'],
jsHint: jsHintOptions.base,
jscs: jscsOptions.config
}, {
dirs: ['./**/abilities.js', './**/items.js', './**/moves.js', './**/typechart.js', './**/aliases.js'],
jsHint: jsHintOptions.legacy,
jscs: jscsOptions.base
}, {
dirs: ['./data/formats-data.js', './mods/*/formats-data.js', './mods/!(gen1)/pokedex.js'],
jsHint: jsHintOptions.legacy,
jscs: jscsOptions.dataCompactArr
}, {
dirs: ['./data/pokedex.js', './mods/gen1/pokedex.js'],
jsHint: jsHintOptions.legacy,
jscs: jscsOptions.dataCompactAll
}, {
dirs: ['./data/learnsets*.js', './mods/*/learnsets.js'],
jsHint: jsHintOptions.legacy,
jscs: jscsOptions.dataCompactAllIndented
}, {
dirs: ['./test/*.js', './test/application/*.js', './test/simulator/*/*.js'],
jsHint: jsHintOptions.test,
jscs: jscsOptions.base
}
];

var linter = function () {
return (
merge.apply(
null,
lintData.map(function (source) {
return gulp.src(source.dirs)
.pipe(transformLet())
.pipe(lint(source.jsHint, source.jscs));
})
).pipe(jshint.reporter(jshintStylish))
.pipe(jshint.reporter('fail'))
);
};

return gulp.src(directories)
.pipe(jscs(jscsOptions))
.pipe(replace(/\bvar\b/g, 'let'))
.pipe(jshint(jsHintOptions))
gulp.task('fastlint', function () {
var source = lintData[0];
return gulp.src(source.dirs)
.pipe(transformLet())
.pipe(lint(source.jsHint, source.jscs))
.pipe(jshint.reporter(jshintStylish))
.pipe(jshint.reporter('fail'));
});

gulp.task('default', ['fastlint', 'data']);
gulp.task('lint', ['fastlint', 'data']);
gulp.task('lint', linter);
gulp.task('default', linter);
10 changes: 5 additions & 5 deletions mods/gen4/pokedex.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
exports.BattlePokedex = {
rotomheat: {
inherit: true,
types: ["Electric", "Ghost"]
types: ["Electric","Ghost"]
},
rotomwash: {
inherit: true,
types: ["Electric", "Ghost"]
types: ["Electric","Ghost"]
},
rotomfrost: {
inherit: true,
types: ["Electric", "Ghost"]
types: ["Electric","Ghost"]
},
rotomfan: {
inherit: true,
types: ["Electric", "Ghost"]
types: ["Electric","Ghost"]
},
rotommow: {
inherit: true,
types: ["Electric", "Ghost"]
types: ["Electric","Ghost"]
}
};
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@
"devDependencies": {
"gulp-util": "~2.2.14",
"gulp": "~3.8.7",
"gulp-jshint": "~1.9.2",
"gulp-jshint": "git://github.com/spalger/gulp-jshint#c18df3a11",
"gulp-jscs": "~1.3.1",
"gulp-replace": "~0.5.1",
"jshint-stylish": "~0.1.5",
"mocha": "~2.1.0"
"mocha": "~2.1.0",
"lazypipe": "~0.2.2",
"merge-stream": "~0.1.7"
}
}

0 comments on commit d37c04e

Please sign in to comment.