Skip to content

Commit

Permalink
Lint: Add miscellaneous extra rules
Browse files Browse the repository at this point in the history
Among the newly added rules, there are quite a few intended to enforce
compliance of CONTRIBUTING.md-blessed idioms, as well as ensure
safe usage of classes and constant bindings.

We are also now enforcing usage of early return in commands.js,
which has 100% compliance as of fd2c45c.
  • Loading branch information
Slayer95 committed Apr 26, 2016
1 parent fd2c45c commit 2277910
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 45 deletions.
55 changes: 42 additions & 13 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
"comma-dangle": [2, "always-multiline"],
"no-cond-assign": [2, "except-parens"],
"no-console": 0,
"no-constant-condition": 0,
"no-constant-condition": 2,
"no-control-regex": 0,
"no-debugger": 2,
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty-character-class": 2,
"no-empty": 0,
"no-empty": [2, {"allowEmptyCatch": true}],
"no-ex-assign": 2,
"disallow-extra-boolean-casts": 0,
"no-extra-boolean-cast": 2,
"no-extra-parens": 0,
"no-extra-semi": 2,
"no-func-assign": 2,
"no-inner-declarations": 2,
"no-inner-declarations": [2, "functions"],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-negated-in-lhs": 2,
Expand All @@ -45,6 +45,7 @@
"valid-jsdoc": 0,
"valid-typeof": 2,

"array-callback-return": 2,
"block-scoped-var": 2,
"complexity": 0,
"consistent-return": 0,
Expand All @@ -53,6 +54,7 @@
"dot-location": [2, "property"],
"dot-notation": 0,
"eqeqeq": 2,
"guard-for-in": 0,
"no-caller": 2,
"no-case-declarations": 0,
"no-div-regex": 2,
Expand All @@ -63,30 +65,34 @@
"no-implied-eval": 2,
"no-extend-native": 2,
"no-extra-bind": 1,
"no-extra-label": 2,
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-implicit-coercion": 0,
"no-invalid-this": 0,
"no-iterator": 2,
"no-lone-blocks": 0,
"no-loop-func": 0,
"no-magic-numbers": 0,
"no-multi-spaces": 0,
"no-multi-spaces": 1,
"no-multi-str": 2,
"no-native-reassign": 2,
"no-new-func": 2,
"no-new-wrappers": 2,
"no-new": 2,
"no-octal-escape": 2,
"no-octal": 1,
"no-octal": 2,
"no-param-reassign": 0,
"no-process-env": 0,
"no-proto": 2,
"no-redeclare": 2,
"no-return-assign": [2, "except-parens"],
"no-self-assign": 2,
"no-self-compare": 2,
"no-sequences": 1,
"no-sequences": 2,
"no-throw-literal": 2,
"no-unmodified-loop-condition": 2,
"no-unused-expressions": 2,
"no-unused-labels": 2,
"no-useless-call": 2,
"no-useless-concat": 0,
"no-void": 0,
Expand All @@ -96,23 +102,32 @@
"vars-on-top": 0,
"wrap-iife": [2, "inside"],
"yoda": 0,

"strict": [2, "global"],

"init-declarations": 0,
"no-catch-shadow": 0,
"no-delete-var": 2,
"no-label-var": 2,
"no-restricted-globals": [2, "Proxy", "Reflect", "Symbol", "WeakSet"],
"no-shadow-restricted-names": 2,
"no-shadow": 0,
"no-undef-init": 0,
"no-undef-init": 1,
"no-undef": [2, {"typeof": true}],
"no-undefined": 0,
"no-unused-vars": [1, {"args": "none"}],
"no-use-before-define": [2, "nofunc"],
"no-use-before-define": [2, {"functions": false, "classes": false}],

"callback-return": [2, ["callback", "cb", "done"]],
"no-mixed-requires": 2,
"no-new-require": 2,
"no-path-concat": 0,
"no-process-env": 0,
"no-process-exit": 0,
"no-restricted-modules": [2, "moment", "request", "sugar"],
"no-sync": 0,

"array-bracket-spacing": [2, "never"],
"arrow-parens": [2, "as-needed"],
"arrow-spacing": [2, {"before": true, "after": true}],
"block-spacing": 0,
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
"camelcase": 0,
Expand All @@ -128,9 +143,11 @@
"key-spacing": 0,
"lines-around-comment": 0,
"max-nested-callbacks": 0,
"max-statements-per-line": 0,
"new-cap": [2, {"newIsCap": true, "capIsNew": false}],
"new-parens": 2,
"newline-after-var": 0,
"newline-before-return": 0,
"no-array-constructor": 2,
"no-continue": 0,
"no-inline-comments": 0,
Expand All @@ -145,7 +162,6 @@
"no-trailing-spaces": 2,
"no-underscore-dangle": 0,
"no-unneeded-ternary": 2,
"no-var": 2,
"object-curly-spacing": [2, "never"],
"one-var": 0,
"operator-assignment": 0,
Expand All @@ -166,6 +182,19 @@
"spaced-comment": 0,
"wrap-regex": 0,

"arrow-parens": [2, "as-needed"],
"arrow-spacing": [2, {"before": true, "after": true}],
"constructor-super": 2,
"no-class-assign": 2,
"no-confusing-arrow": 0,
"no-const-assign": 2,
"no-dupe-class-members": 2,
"no-this-before-super": 2,
"no-var": 2,
"require-yield": 2,
"template-curly-spacing": [2, "never"],
"no-restricted-syntax": [2, "TaggedTemplateExpression", "ObjectPattern", "ArrayPattern"],

"validate-conditionals": 2,
}
}
2 changes: 1 addition & 1 deletion chat-plugins/datasearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ function runDexsearch(target, cmd, canAll, message) {
for (let i = 0; i < moveGroups[group].length; i++) {
let problem = TeamValidator('anythinggoes').checkLearnset(moveGroups[group][i], mon, lsetData);
if (!problem) break;
if (i === moveGroups[group].length - 1) return;
if (i === moveGroups[group].length - 1) return false;
}
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion chat-plugins/jeopardy.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ let Jeopardy = (() => {
let checks = Array.prototype.slice.call(arguments, 2);

let currentCheck = '';
while (!!(currentCheck = checks.pop())) {
while ((currentCheck = checks.pop())) {
switch (currentCheck) {
case 'started':
if (this.isStarted) break;
Expand Down
2 changes: 1 addition & 1 deletion chat-plugins/mafia.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ class Mafia extends Rooms.RoomGame {
this.timer = setTimeout(() => {
this.progress();
}, 10000);
}, ((mins - 0.167) * 60000));
}, ((mins - 0.167) * 60000));
}

// Meetings:
Expand Down
2 changes: 1 addition & 1 deletion chat-plugins/tcgtabletop.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ function wikiaSearch(subdomain, query, callback) {
return callback(null, result.items[0]);
});
}).once('error', function (err) {
callback(err);
this.on('error', noop);
callback(err);
});
}

Expand Down
3 changes: 2 additions & 1 deletion commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

'use strict';

/* eslint no-else-return: "error" */

const crypto = require('crypto');
const fs = require('fs');

Expand Down Expand Up @@ -378,7 +380,6 @@ exports.commands = {
if (Rooms.search(roomid)) return this.errorReply("A group chat named '" + title + "' already exists.");
// Tab title is prefixed with '[G]' to distinguish groupchats from
// registered chatrooms
title = title;

if (Monitor.countGroupChat(connection.ip)) {
this.errorReply("Due to high load, you are limited to creating 4 group chats every hour.");
Expand Down
21 changes: 13 additions & 8 deletions data/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,15 @@ exports.BattleScripts = {
}

// Make sure forme/item combo is correct
while ((poke === 'Giratina' && item === 'griseousorb') ||
(poke === 'Arceus' && item.substr(-5) === 'plate') ||
(poke === 'Genesect' && item.substr(-5) === 'drive')) {
item = items[this.random(items.length)];
switch (poke) {
case 'Giratina':
while (item === 'griseousorb') item = items[this.random(items.length)];
break;
case 'Arceus':
while (item.substr(-5) === 'plate') item = items[this.random(items.length)];
break;
case 'Genesect':
while (item.substr(-5) === 'drive') item = items[this.random(items.length)];
}

// Random ability
Expand Down Expand Up @@ -917,12 +922,12 @@ exports.BattleScripts = {

// Random unique moves
let m = [];
while (true) {
do {
let moveid = this.sampleNoReplace(movePool);
if (!this.data.Movedex[moveid].isNonstandard && (moveid === 'hiddenpower' || moveid.substr(0, 11) !== 'hiddenpower')) {
if (m.push(moveid) >= 4) break;
m.push(moveid);
}
}
} while (m.length < 4);

// Random EVs
let evs = {hp: 0, atk: 0, def: 0, spa: 0, spd: 0, spe: 0};
Expand Down Expand Up @@ -1311,7 +1316,7 @@ exports.BattleScripts = {
if (counter.setupType || !!counter['speedsetup'] || (hasMove['rest'] && hasMove['sleeptalk'])) rejected = true;
break;
case 'healbell':
if (!!counter['speedsetup']) rejected = true;
if (counter['speedsetup']) rejected = true;
break;
case 'healingwish': case 'memento':
if (counter.setupType || !!counter['recovery'] || hasMove['substitute']) rejected = true;
Expand Down
7 changes: 3 additions & 4 deletions dnsbl.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ function queryDnsblLoop(ip, callback, reversedIpDot, index) {
if (!err) {
// blocked
dnsblCache.set(ip, blocklist);
callback(blocklist);
} else {
// not blocked, try next blocklist
queryDnsblLoop(ip, callback, reversedIpDot, index + 1);
return callback(blocklist);
}
// not blocked, try next blocklist
queryDnsblLoop(ip, callback, reversedIpDot, index + 1);
});
}

Expand Down
1 change: 1 addition & 0 deletions mods/gen5/moves.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ exports.BattleMovedex = {
if (move.id !== 'conversion' && !target.hasType(move.type)) {
return move.type;
}
return '';
}).filter(type => type);
if (!possibleTypes.length) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion mods/seasonal/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ exports.BattleScripts = {
species: 'Mr. Mime', ability: 'Prankster', item: 'Leftovers', gender: 'M',
moves: ['batonpass', ['substitute', 'milkdrink'][this.random(2)], 'encore'],
signatureMove: "Meme Mime",
evs: {hp:252, def:4, spe:252}, ivs: {atk:0, spa:0}, nature: 'Timid',
evs: {hp:252, def:4, spe:252}, ivs: {atk:0, spa:0}, nature: 'Timid',
},
'ih8ih8sn0w': {
species: 'Deoxys-Speed', ability: 'Pressure', item: 'Leftovers', gender: 'N', shiny: true,
Expand Down
4 changes: 2 additions & 2 deletions repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ exports.start = function (prefix, suffix, evalFunction) {
output: socket,
eval: (cmd, context, filename, callback) => {
try {
callback(null, evalFunction(cmd));
return callback(null, evalFunction(cmd));
} catch (e) {
callback(e);
return callback(e);
}
},
}).on('exit', () => socket.end());
Expand Down
6 changes: 3 additions & 3 deletions test/simulator/items/shedshell.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Shed Shell', function () {
battle.join('p1', 'Guest 1', 1, [{species: "Gothitelle", ability: 'shadowtag', moves: ['calmmind']}]);
battle.join('p2', 'Guest 2', 1, [
{species: "Starmie", ability: 'naturalcure', item: 'shedshell', moves: ['recover']},
{species: "Heatran", ability: 'flashfire', moves: ['rest']},
{species: "Heatran", ability: 'flashfire', moves: ['rest']},
]);
battle.choose('p2', 'switch 2');
battle.commitDecisions();
Expand All @@ -25,7 +25,7 @@ describe('Shed Shell', function () {
battle.join('p1', 'Guest 1', 1, [{species: "Gengar", ability: 'levitate', moves: ['meanlook']}]);
battle.join('p2', 'Guest 2', 1, [
{species: "Venusaur", ability: 'overgrow', item: 'shedshell', moves: ['ingrain']},
{species: "Heatran", ability: 'flashfire', moves: ['rest']},
{species: "Heatran", ability: 'flashfire', moves: ['rest']},
]);
battle.commitDecisions();
battle.choose('p2', 'switch 2');
Expand All @@ -38,7 +38,7 @@ describe('Shed Shell', function () {
battle.join('p1', 'Guest 1', 1, [{species: "Dragonite", ability: 'multiscale', moves: ['skydrop']}]);
battle.join('p2', 'Guest 2', 1, [
{species: "Magnezone", ability: 'sturdy', item: 'shedshell', moves: ['sleeptalk']},
{species: "Heatran", ability: 'flashfire', moves: ['rest']},
{species: "Heatran", ability: 'flashfire', moves: ['rest']},
]);
battle.commitDecisions();
battle.choose('p2', 'switch 2');
Expand Down
4 changes: 2 additions & 2 deletions test/simulator/misc/eventemitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ describe('Battle#on', function () {
battle.join('p2', 'Guest 2', 1, [{species: 'Talonflame', ability: 'galewings', moves: ['peck']}]);
battle.commitDecisions(); // Team Preview
let eventCount = 0;
let callback = function (count) {
let modHandler = function (count) {
return function () {
assert.strictEqual(eventCount, count);
eventCount++;
};
};
for (let i = 0; i < 9; i++) {
battle.on('ModifyDamage', battle.getFormat(), -i, callback(i));
battle.on('ModifyDamage', battle.getFormat(), -i, modHandler(i));
}
battle.commitDecisions();
assert.strictEqual(eventCount, 9);
Expand Down
2 changes: 1 addition & 1 deletion tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ module.exports = (() => {
if (!this.data.Pokedex[id]) {
if (id.startsWith('mega') && this.data.Pokedex[id.slice(4) + 'mega']) {
id = id.slice(4) + 'mega';
} else if (id.startsWith('m') && this.data.Pokedex[id.slice(1) + 'mega']) {
} else if (id.startsWith('m') && this.data.Pokedex[id.slice(1) + 'mega']) {
id = id.slice(1) + 'mega';
} else if (id.startsWith('primal') && this.data.Pokedex[id.slice(6) + 'primal']) {
id = id.slice(6) + 'primal';
Expand Down
14 changes: 8 additions & 6 deletions users.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ function getUser(name, exactName) {
if (name && name.userid) return name;
let userid = toId(name);
let i = 0;
while (!exactName && userid && !users.has(userid) && i < 1000) {
userid = prevUsers.get(userid);
i++;
if (!exactName) {
while (userid && !users.has(userid) && i < 1000) {
userid = prevUsers.get(userid);
i++;
}
}
return users.get(userid);
}
Expand Down Expand Up @@ -631,7 +633,7 @@ class User {

for (let i = 0; i < this.connections.length; i++) {
// console.log('' + name + ' renaming: connection ' + i + ' of ' + this.connections.length);
let initdata = '|updateuser|' + this.name + '|' + (false ? '1' : '0') + '|' + this.avatar;
let initdata = '|updateuser|' + this.name + '|' + ('0' /* not named */) + '|' + this.avatar;
this.connections[i].send(initdata);
}
this.named = false;
Expand Down Expand Up @@ -916,7 +918,7 @@ class User {

for (let i = 0; i < this.connections.length; i++) {
//console.log('' + name + ' renaming: socket ' + i + ' of ' + this.connections.length);
let initdata = '|updateuser|' + this.name + '|' + (true ? '1' : '0') + '|' + this.avatar;
let initdata = '|updateuser|' + this.name + '|' + ('1' /* named */) + '|' + this.avatar;
this.connections[i].send(initdata);
}
let joining = !this.named;
Expand Down Expand Up @@ -972,7 +974,7 @@ class User {
this.connected = true;
this.connections.push(connection);
//console.log('' + this.name + ' merging: connection ' + connection.socket.id);
let initdata = '|updateuser|' + this.name + '|' + (true ? '1' : '0') + '|' + this.avatar;
let initdata = '|updateuser|' + this.name + '|' + ('1' /* named */) + '|' + this.avatar;
connection.send(initdata);
connection.user = this;
for (let i in connection.rooms) {
Expand Down

0 comments on commit 2277910

Please sign in to comment.