From f476c2700ab796e66e893f44eac17b9ec1e67760 Mon Sep 17 00:00:00 2001 From: Ivo Julca Date: Mon, 9 Feb 2015 20:00:52 -0500 Subject: [PATCH 1/6] Gulpfile: remove deprecated or redundant rules - JSCS rule "disallowNewLineBeforeBlockStatements" is already in Google preset. - JSHint rule "immed" is deprecated in favor of JSCS' "requireParenthesesAroundIIFE". - JSHint rule "smarttabs" is deprecated in favor of JSCS' "disallowMixedSpacesAndTabs": "smart". - JSHint rule "trailing" is deprecated in favor of JSCS' "disallowTrailingWhiteSpace". - JSHint rule "newcap" is deprecated in favor of JSCS' "requireCapitalizedConstructors". --- gulpfile.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 930ea3a40a..268ce821fe 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -13,14 +13,8 @@ var jsHintOptions = { "latedef": 'nofunc', "freeze": true, - "immed": true, "undef": true, - // style - "smarttabs": true, - "trailing": true, - "newcap": true, - "sub": true, "evil": true, "esnext": true, @@ -54,6 +48,8 @@ var jscsOptions = { "preset": "google", "requireCurlyBraces": null, + "requireParenthesesAroundIIFE": true, + "requireCamelCaseOrUpperCaseIdentifiers": null, "maximumLineLength": null, "validateIndentation": "\t", From 8f9f681e4e08c9688fbdad8ff44ff794c95e5554 Mon Sep 17 00:00:00 2001 From: Ivo Julca Date: Fri, 13 Feb 2015 05:29:42 -0500 Subject: [PATCH 2/6] Gulpfile: add new JSCS options - Use an ES6 parser. - Disallow "with". - Only validate line breaks when running in CI environments. - Add various missing rules regarding spacing and line breaks. --- gulpfile.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 268ce821fe..feab7c8c72 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -44,6 +44,7 @@ var jsHintOptions = { var jscsOptions = { "excludeFiles": ["./**/pokedex.js", "./**/formats-data.js", "./**/learnsets.js", "./**/learnsets-g6.js", "./config/config.js"], + "esnext": "true", "preset": "google", @@ -59,28 +60,49 @@ var jscsOptions = { "disallowMultipleVarDecl": null, "requireSpaceAfterKeywords": true, + "requireSpaceAfterBinaryOperators": true, "requireSpaceBeforeBinaryOperators": true, "disallowSpacesInAnonymousFunctionExpression": null, "requireSpacesInAnonymousFunctionExpression": { - "beforeOpeningRoundBrace": true + "beforeOpeningRoundBrace": true, + "beforeOpeningCurlyBrace": true }, + "requireSpacesInFunctionDeclaration": { + "beforeOpeningCurlyBrace": true + }, + "requireSpacesInNamedFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, + + "requireSpaceBetweenArguments": true, + "disallowSpaceBeforeBinaryOperators": [ + "," + ], "validateJSDoc": null, "requireBlocksOnNewline": 1, "disallowPaddingNewlinesInBlocks": true, "disallowEmptyBlocks": true, - "disallowNewlineBeforeBlockStatements": true, + + "disallowKeywords": [ + "with" + ], + "disallowKeywordsOnNewLine": [ + "else", + "catch" + ], "requireCommaBeforeLineBreak": true, "requireOperatorBeforeLineBreak": true, + "disallowMultipleLineStrings": true, "disallowSpaceAfterObjectKeys": true, "disallowSpaceAfterPrefixUnaryOperators": true, "disallowSpaceBeforePostfixUnaryOperators": true, "disallowTrailingComma": true, - "validateLineBreaks": require('os').EOL.replace(/\r/g, 'CR').replace(/\n/g, 'LF'), + "validateLineBreaks": 'CI' in process.env ? 'LF' : null, "validateParameterSeparator": ", ", "requireCapitalizedConstructors": true From 6186a6be603b3cd7291c4279dfa2251015453435 Mon Sep 17 00:00:00 2001 From: Ivo Julca Date: Mon, 9 Feb 2015 20:37:49 -0500 Subject: [PATCH 3/6] Gulpfile: rebase JSCS options on Yandex preset --- gulpfile.js | 65 ++++++++++++++++++++--------------------------------- 1 file changed, 24 insertions(+), 41 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index feab7c8c72..02fe5780fe 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -46,66 +46,49 @@ var jscsOptions = { "excludeFiles": ["./**/pokedex.js", "./**/formats-data.js", "./**/learnsets.js", "./**/learnsets-g6.js", "./config/config.js"], "esnext": "true", - "preset": "google", + "preset": "yandex", "requireCurlyBraces": null, - "requireParenthesesAroundIIFE": true, - "requireCamelCaseOrUpperCaseIdentifiers": null, "maximumLineLength": null, - "validateIndentation": "\t", + "validateIndentation": '\t', "validateQuoteMarks": null, + "disallowQuotedKeysInObjects": null, + "requireDotNotation": null, + "disallowYodaConditions": null, + + "disallowMultipleVarDecl": null, + "disallowImplicitTypeConversion": null, + "requireSpaceAfterLineComment": null, + "validateJSDoc": null, "disallowMixedSpacesAndTabs": "smart", - "disallowMultipleVarDecl": null, - "requireSpaceAfterKeywords": true, - "requireSpaceAfterBinaryOperators": true, - "requireSpaceBeforeBinaryOperators": true, - "disallowSpacesInAnonymousFunctionExpression": null, + + "disallowSpacesInFunctionDeclaration": null, + "requireSpacesInFunctionDeclaration": { + "beforeOpeningCurlyBrace": true + }, "requireSpacesInAnonymousFunctionExpression": { "beforeOpeningRoundBrace": true, "beforeOpeningCurlyBrace": true }, - "requireSpacesInFunctionDeclaration": { - "beforeOpeningCurlyBrace": true - }, - "requireSpacesInNamedFunctionExpression": { - "beforeOpeningCurlyBrace": true - }, - - "requireSpaceBetweenArguments": true, - "disallowSpaceBeforeBinaryOperators": [ - "," - ], - - "validateJSDoc": null, + "disallowSpacesInNamedFunctionExpression": null, + "requireSpacesInNamedFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, + "validateParameterSeparator": ", ", "requireBlocksOnNewline": 1, "disallowPaddingNewlinesInBlocks": true, - "disallowEmptyBlocks": true, - "disallowKeywords": [ - "with" - ], - "disallowKeywordsOnNewLine": [ - "else", - "catch" - ], - - "requireCommaBeforeLineBreak": true, "requireOperatorBeforeLineBreak": true, - "disallowMultipleLineStrings": true, - - "disallowSpaceAfterObjectKeys": true, - "disallowSpaceAfterPrefixUnaryOperators": true, - "disallowSpaceBeforePostfixUnaryOperators": true, - "disallowTrailingComma": true, - "validateLineBreaks": 'CI' in process.env ? 'LF' : null, - "validateParameterSeparator": ", ", - "requireCapitalizedConstructors": true + "requireCapitalizedConstructors": true, + + "validateLineBreaks": 'CI' in process.env ? 'LF' : null, + "disallowMultipleLineBreaks": null }; gulp.task('data', function () { From 68aaa48974809c4809a21a2760c8298f1cdf7bbb Mon Sep 17 00:00:00 2001 From: Ivo Julca Date: Wed, 18 Feb 2015 19:51:15 -0500 Subject: [PATCH 4/6] Gulpfile: no files are exempt from style checks - 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 https://github.com/spalger/gulp-jshint/issues/88 --- gulpfile.js | 186 ++++++++++++++++++------- mods/gen4/pokedex.js | 10 +- package.json | 6 +- test/application/users.js | 2 +- test/main.js | 2 +- test/simulator/abilities/intimidate.js | 2 +- test/simulator/misc/typechange.js | 2 +- test/simulator/moves/roost.js | 2 +- 8 files changed, 146 insertions(+), 66 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 02fe5780fe..85f38136d4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,11 +1,40 @@ -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 gutil = require('gulp-util'); // Currently unused, but gulp strongly suggested I install... +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, @@ -21,31 +50,20 @@ 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, @@ -53,9 +71,9 @@ var jscsOptions = { "maximumLineLength": null, "validateIndentation": '\t', "validateQuoteMarks": null, + "disallowYodaConditions": null, "disallowQuotedKeysInObjects": null, "requireDotNotation": null, - "disallowYodaConditions": null, "disallowMultipleVarDecl": null, "disallowImplicitTypeConversion": null, @@ -88,37 +106,97 @@ var jscsOptions = { "requireCapitalizedConstructors": true, "validateLineBreaks": 'CI' in process.env ? 'LF' : null, - "disallowMultipleLineBreaks": 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, -gulp.task('data', function () { - var directories = ['./data/*.js', './mods/*/*.js']; - jsHintOptions['es3'] = true; + "validateLineBreaks": 'CI' in process.env ? 'LF' : null, + "requireLineFeedAtFileEnd": true, + "requireSpaceAfterBinaryOperators": ["="], + "requireSpaceBeforeBinaryOperators": ["="], - // 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. + "validateQuoteMarks": "\"", + "disallowQuotedKeysInObjects": "allButReserved", - 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)); + "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 + } +]; - 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..c580f110e0 100644 --- a/package.json +++ b/package.json @@ -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" } } 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']}, From d6c3058673cecfd2966f6af326eb550232bf442b Mon Sep 17 00:00:00 2001 From: Ivo Julca Date: Fri, 13 Feb 2015 05:59:14 -0500 Subject: [PATCH 5/6] Deps: update dev dependencies - Remove `gulp-util`: it's not used and its installation is no longer recommended in Gulp's documentation. - Next minor version for `gulp-jscs`. Next major for `jshint-stylish`. --- gulpfile.js | 1 - package.json | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 85f38136d4..1fbd27b154 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,7 +2,6 @@ var path = require('path'); var util = require('util'); var gulp = require('gulp'); -var gutil = require('gulp-util'); // Currently unused, but gulp strongly suggested I install... var lazypipe = require('lazypipe'); var merge = require('merge-stream'); var jscs = require('gulp-jscs'); diff --git a/package.json b/package.json index c580f110e0..49f0598f04 100644 --- a/package.json +++ b/package.json @@ -49,12 +49,11 @@ ], "private": true, "devDependencies": { - "gulp-util": "~2.2.14", "gulp": "~3.8.7", "gulp-jshint": "git://github.com/spalger/gulp-jshint#c18df3a11", - "gulp-jscs": "~1.3.1", + "gulp-jscs": "~1.4.0", "gulp-replace": "~0.5.1", - "jshint-stylish": "~0.1.5", + "jshint-stylish": "~1.0.0", "mocha": "~2.1.0", "lazypipe": "~0.2.2", "merge-stream": "~0.1.7" From 715fa48771abadfac1d32b718e67e2731329aba3 Mon Sep 17 00:00:00 2001 From: Ivo Julca Date: Fri, 13 Feb 2015 06:00:43 -0500 Subject: [PATCH 6/6] Travis CI: Use container-based infrastructure --- .travis.yml | 1 + 1 file changed, 1 insertion(+) 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"