diff --git a/.travis.yml b/.travis.yml index 6e5919de39..777b8a6b35 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +sudo: false language: node_js node_js: - "0.10" diff --git a/gulpfile.js b/gulpfile.js index 930ea3a40a..1fbd27b154 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,11 +1,39 @@ -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 jscs = require('gulp-jscs'); -var replace = require('gulp-replace'); +var path = require('path'); +var util = require('util'); -var jsHintOptions = { +var gulp = require('gulp'); +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. + + 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, @@ -13,111 +41,161 @@ var jsHintOptions = { "latedef": 'nofunc', "freeze": true, - "immed": true, "undef": true, - // style - "smarttabs": true, - "trailing": true, - "newcap": true, - "sub": true, "evil": true, "esnext": true, "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"], - - "preset": "google", +var jscsOptions = {}; +jscsOptions.base = { + "preset": "yandex", "requireCurlyBraces": null, - "requireCamelCaseOrUpperCaseIdentifiers": null, + "maximumLineLength": null, - "validateIndentation": "\t", + "validateIndentation": '\t', "validateQuoteMarks": null, + "disallowYodaConditions": null, + "disallowQuotedKeysInObjects": null, + "requireDotNotation": null, + + "disallowMultipleVarDecl": null, + "disallowImplicitTypeConversion": null, + "requireSpaceAfterLineComment": null, + "validateJSDoc": null, "disallowMixedSpacesAndTabs": "smart", - "disallowMultipleVarDecl": null, - "requireSpaceAfterKeywords": true, - "requireSpaceBeforeBinaryOperators": true, - "disallowSpacesInAnonymousFunctionExpression": null, - "requireSpacesInAnonymousFunctionExpression": { - "beforeOpeningRoundBrace": true - }, - "validateJSDoc": null, + "disallowSpacesInFunctionDeclaration": null, + "requireSpacesInFunctionDeclaration": { + "beforeOpeningCurlyBrace": true + }, + "requireSpacesInAnonymousFunctionExpression": { + "beforeOpeningRoundBrace": true, + "beforeOpeningCurlyBrace": true + }, + "disallowSpacesInNamedFunctionExpression": null, + "requireSpacesInNamedFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, + "validateParameterSeparator": ", ", "requireBlocksOnNewline": 1, "disallowPaddingNewlinesInBlocks": true, - "disallowEmptyBlocks": true, - "disallowNewlineBeforeBlockStatements": true, - "requireCommaBeforeLineBreak": true, "requireOperatorBeforeLineBreak": true, + "disallowTrailingComma": true, + + "requireCapitalizedConstructors": true, + + "validateLineBreaks": 'CI' in process.env ? 'LF' : null, + "disallowMultipleLineBreaks": null, + + "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, + + "validateLineBreaks": 'CI' in process.env ? 'LF' : null, + "requireLineFeedAtFileEnd": true, + "requireSpaceAfterBinaryOperators": ["="], + "requireSpaceBeforeBinaryOperators": ["="], + + "validateQuoteMarks": "\"", + "disallowQuotedKeysInObjects": "allButReserved", "disallowSpaceAfterObjectKeys": true, - "disallowSpaceAfterPrefixUnaryOperators": true, - "disallowSpaceBeforePostfixUnaryOperators": true, - - "disallowTrailingComma": true, - "validateLineBreaks": require('os').EOL.replace(/\r/g, 'CR').replace(/\n/g, 'LF'), - "validateParameterSeparator": ", ", - - "requireCapitalizedConstructors": true + "disallowSpaceBeforeObjectValues": true, + "disallowSpacesInsideBrackets": true, + "disallowSpacesInsideArrayBrackets": true, + "disallowSpacesInsideObjectBrackets": true, + "disallowSpacesInsideParentheses": true, + "disallowSpaceAfterBinaryOperators": [","], + "disallowSpaceBeforeBinaryOperators": [","] }; - -gulp.task('data', function () { - var directories = ['./data/*.js', './mods/*/*.js']; - jsHintOptions['es3'] = true; - - // 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. - - 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)); +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 + } +]; - return gulp.src(directories) - .pipe(jscs(jscsOptions)) - .pipe(replace(/\bvar\b/g, 'let')) - .pipe(jshint(jsHintOptions)) +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')) + ); +}; + +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); diff --git a/mods/gen4/pokedex.js b/mods/gen4/pokedex.js index ad33b7c9e0..cffc9c535a 100644 --- a/mods/gen4/pokedex.js +++ b/mods/gen4/pokedex.js @@ -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"] } }; diff --git a/package.json b/package.json index c844abf7c9..49f0598f04 100644 --- a/package.json +++ b/package.json @@ -49,12 +49,13 @@ ], "private": true, "devDependencies": { - "gulp-util": "~2.2.14", "gulp": "~3.8.7", - "gulp-jshint": "~1.9.2", - "gulp-jscs": "~1.3.1", + "gulp-jshint": "git://github.com/spalger/gulp-jshint#c18df3a11", + "gulp-jscs": "~1.4.0", "gulp-replace": "~0.5.1", - "jshint-stylish": "~0.1.5", - "mocha": "~2.1.0" + "jshint-stylish": "~1.0.0", + "mocha": "~2.1.0", + "lazypipe": "~0.2.2", + "merge-stream": "~0.1.7" } } diff --git a/test/application/users.js b/test/application/users.js index 162161c91d..e74850fd14 100644 --- a/test/application/users.js +++ b/test/application/users.js @@ -63,7 +63,7 @@ describe('Users features', function () { user.disconnectAll(); for (var i = 0; i < totalConnections; i++) { assert.strictEqual(Users.connections[connections[i].id], undefined); - } + } }); it('should clear `user` property for all ' + totalConnections + ' connection(s)', function () { diff --git a/test/main.js b/test/main.js index 5e2a5c2ca5..5963cb72c1 100644 --- a/test/main.js +++ b/test/main.js @@ -4,7 +4,7 @@ before('initialization', function () { this.timeout(0); // Remove timeout limitation require('./../app.js'); - process.listeners('uncaughtException').forEach(function (listener) { + process.listeners('uncaughtException').forEach(function (listener) { process.removeListener('uncaughtException', listener); }); diff --git a/test/simulator/abilities/intimidate.js b/test/simulator/abilities/intimidate.js index 6812e4953d..f6e0a4cdef 100644 --- a/test/simulator/abilities/intimidate.js +++ b/test/simulator/abilities/intimidate.js @@ -37,7 +37,7 @@ describe('Intimidate', function () { battle.join('p2', 'Guest 2', 1, [ {species: "Greninja", ability: 'protean', moves: ['uturn']}, {species: "Mew", ability: 'synchronize', moves: ['softboiled']}, - {species: "Gyarados", ability: 'intimidate', moves: ['splash']}, + {species: "Gyarados", ability: 'intimidate', moves: ['splash']} ]); battle.commitDecisions(); assert.strictEqual(battle.p1.active[0].boosts['atk'], -1); diff --git a/test/simulator/misc/typechange.js b/test/simulator/misc/typechange.js index 3e2394eb2e..b8682375ee 100644 --- a/test/simulator/misc/typechange.js +++ b/test/simulator/misc/typechange.js @@ -34,7 +34,7 @@ describe('Type addition', function () { battle.join('p1', 'Guest 1', 1, [{species: "Gourgeist", ability: 'frisk', moves: [moveData.name]}]); battle.join('p2', 'Guest 2', 1, [{species: "Arceus", ability: 'multitype', moves: ['extremespeed']}]); battle.commitDecisions(); - assert.deepEqual(battle.p2.active[0].getTypes(), ['Normal', moveData.type]); + assert.deepEqual(battle.p2.active[0].getTypes(), ['Normal', moveData.type]); }); adderMoves.forEach(function (moveData2) { diff --git a/test/simulator/moves/roost.js b/test/simulator/moves/roost.js index f882edbd34..8117c6f7a6 100644 --- a/test/simulator/moves/roost.js +++ b/test/simulator/moves/roost.js @@ -52,7 +52,7 @@ describe('Roost', function () { battle = BattleEngine.Battle.construct('battle-roost-latency', 'doublescustomgame'); battle.join('p1', 'Guest 1', 1, [ {species: "Pidgeot", item: 'laggingtail', ability: 'victorystar', moves: ['aircutter']}, - {species: "Gligar", item: 'laggingtail', ability: 'immunity', moves: ['earthquake']}, + {species: "Gligar", item: 'laggingtail', ability: 'immunity', moves: ['earthquake']} ]); battle.join('p2', 'Guest 2', 1, [ {species: "Kecleon", ability: 'colorchange', moves: ['roost']},