Skip to content

Commit

Permalink
Fix misc errors found by LGTM
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarel committed Oct 28, 2018
1 parent e92fcc9 commit 24571ea
Show file tree
Hide file tree
Showing 22 changed files with 114 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"no-sequences": "error",
"no-throw-literal": "error",
"no-unmodified-loop-condition": "error",
"no-unused-expressions": "error",
"no-unused-expressions": "off",
"no-useless-call": "error",
"no-useless-concat": "off",
"no-void": "off",
Expand Down
13 changes: 9 additions & 4 deletions chat-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const HOURMUTE_LENGTH = 60 * 60 * 1000;

const MAX_CHATROOM_ID_LENGTH = 225;

/** Require reasons */
const REQUIRE_REASONS = true;

/** @type {ChatCommands} */
const commands = {

Expand Down Expand Up @@ -1703,7 +1706,7 @@ const commands = {
if (!target) {
return this.privateModAction(`(${targetUser.name} would be muted by ${user.name} ${problem}.)`);
}
return this.addModAction(`${targetUser.name} would be muted by ${user.name} ${problem}.${(target ? ` (${target})` : ``)}`);
return this.addModAction(`${targetUser.name} would be muted by ${user.name} ${problem}. (${target})`);
}

if (targetUser in room.users) targetUser.popup(`|modal|${user.name} has muted you in ${room.id} for ${Chat.toDurationString(muteDuration)}. ${target}`);
Expand Down Expand Up @@ -1977,7 +1980,7 @@ const commands = {
if (target.length > MAX_REASON_LENGTH) {
return this.errorReply(`The reason is too long. It cannot exceed ${MAX_REASON_LENGTH} characters.`);
}
if (!target) {
if (!target && REQUIRE_REASONS) {
return this.errorReply("Global bans require a reason.");
}
if (!this.can('ban', targetUser)) return false;
Expand Down Expand Up @@ -2577,7 +2580,7 @@ const commands = {
return this.errorReply(`This user is already blacklisted from this room.`);
}

if (!target) {
if (!target && REQUIRE_REASONS) {
return this.errorReply(`Blacklists require a reason.`);
}
if (target.length > MAX_REASON_LENGTH) {
Expand Down Expand Up @@ -2697,7 +2700,9 @@ const commands = {
}

let [targetStr, reason] = target.split('|').map(val => val.trim());
if (!(targetStr && reason)) return this.errorReply("Usage: /blacklistname name1, name2, ... | reason");
if (!targetStr || (!reason && REQUIRE_REASONS)) {
return this.errorReply("Usage: /blacklistname name1, name2, ... | reason");
}

let targets = targetStr.split(',').map(s => toId(s));

Expand Down
6 changes: 3 additions & 3 deletions chat-plugins/mafia.js
Original file line number Diff line number Diff line change
Expand Up @@ -2304,7 +2304,7 @@ const commands = {
if (isNaN(num)) {
if ((game.hostid === user.userid || game.cohosts.includes(user.userid)) && this.cmdToken === "!") {
const broadcastMessage = this.message.toLowerCase().replace(/[^a-z0-9\s!,]/g, '');
if (room && room.lastBroadcast === broadcastMessage &&
if (room.lastBroadcast === broadcastMessage &&
room.lastBroadcastTime >= Date.now() - 20 * 1000) {
return this.errorReply("You can't broadcast this because it was just broadcasted.");
}
Expand Down Expand Up @@ -2444,7 +2444,7 @@ const commands = {
if (!game.started) return this.errorReply(`The game of mafia has not started yet.`);
if ((game.hostid === user.userid || game.cohosts.includes(user.userid)) && this.cmdToken === "!") {
const broadcastMessage = this.message.toLowerCase().replace(/[^a-z0-9\s!,]/g, '');
if (room && room.lastBroadcast === broadcastMessage &&
if (room.lastBroadcast === broadcastMessage &&
room.lastBroadcastTime >= Date.now() - 20 * 1000) {
return this.errorReply("You can't broadcast this because it was just broadcasted.");
}
Expand All @@ -2465,7 +2465,7 @@ const commands = {
const game = /** @type {MafiaTracker} */ (room.game);
if ((game.hostid === user.userid || game.cohosts.includes(user.userid)) && this.cmdToken === "!") {
const broadcastMessage = this.message.toLowerCase().replace(/[^a-z0-9\s!,]/g, '');
if (room && room.lastBroadcast === broadcastMessage &&
if (room.lastBroadcast === broadcastMessage &&
room.lastBroadcastTime >= Date.now() - 20 * 1000) {
return this.errorReply("You can't broadcast this because it was just broadcasted.");
}
Expand Down
2 changes: 1 addition & 1 deletion chat-plugins/roomsettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ exports.commands = {
if (!user.can('makeroom')) return this.errorReply("Regex banwords are only allowed for leaders or above.");

try {
let test = new RegExp(word); // eslint-disable-line no-unused-vars
new RegExp(word); // eslint-disable-line no-new
} catch (e) {
return this.errorReply(e.message.startsWith('Invalid regular expression: ') ? e.message : `Invalid regular expression: /${word}/: ${e.message}`);
}
Expand Down
2 changes: 1 addition & 1 deletion chat-plugins/scavengers.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ let commands = {
room.game = new ScavengerHunt(room, user, hosts, gameType, params.result);
}
this.privateModAction(`(A new scavenger hunt was created by ${user.name}.)`);
this.modlog('SCAV NEW', null, `${gameType ? gameType.toUpperCase() : ''}: creators - ${hosts.map(h => h.userid)}`);
this.modlog('SCAV NEW', null, `${gameType.toUpperCase()}: creators - ${hosts.map(h => h.userid)}`);
},

status: function (target, room, user) {
Expand Down
2 changes: 1 addition & 1 deletion chat-plugins/trivia.js
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@ const commands = {
name = Chat.escapeHTML(user.name);
userid = user.userid;
} else {
target = this.splitTarget(target, true);
this.splitTarget(target, true);
name = Chat.escapeHTML(this.targetUsername);
userid = toId(name);
}
Expand Down
3 changes: 1 addition & 2 deletions chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -1663,10 +1663,9 @@ Chat.getImageDimensions = function (url) {
Chat.fitImage = async function (url, maxHeight = 300, maxWidth = 300) {
let {height, width} = await Chat.getImageDimensions(url);

let ratio = 1;

if (width <= maxWidth && height <= maxHeight) return [width, height];

let ratio;
if (height * (maxWidth / maxHeight) > width) {
ratio = maxHeight / height;
} else {
Expand Down
6 changes: 3 additions & 3 deletions data/random-teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -1556,9 +1556,10 @@ class RandomTeams extends Dex.ModdedDex {
item = 'Black Sludge';
}

let level = 75;
let level;

if (!isDoubles) {
/** @type {{[tier: string]: number}} */
let levelScale = {
LC: 88,
'LC Uber': 86,
Expand All @@ -1575,6 +1576,7 @@ class RandomTeams extends Dex.ModdedDex {
Uber: 73,
AG: 71,
};
/** @type {{[species: string]: number}} */
let customScale = {
// Banned Abilities
Dugtrio: 77, Gothitelle: 77, Pelipper: 79, Politoed: 79, Wobbuffet: 77,
Expand All @@ -1589,9 +1591,7 @@ class RandomTeams extends Dex.ModdedDex {
if (tier.charAt(0) === '(') {
tier = tier.slice(1, -1);
}
// @ts-ignore
level = levelScale[tier] || 75;
// @ts-ignore
if (customScale[template.name]) level = customScale[template.name];

// Custom level based on moveset
Expand Down
3 changes: 1 addition & 2 deletions data/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,8 @@ let BattleScripts = {
tryMoveHit(target, pokemon, move) {
this.setActiveMove(move, pokemon, target);
move.zBrokeProtect = false;
let hitResult = true;

hitResult = this.singleEvent('PrepareHit', move, {}, target, pokemon, move);
let hitResult = this.singleEvent('PrepareHit', move, {}, target, pokemon, move);
if (!hitResult) {
if (hitResult === false) this.add('-fail', target);
return false;
Expand Down
1 change: 0 additions & 1 deletion mods/gen1/random-teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ class RandomGen1Teams extends RandomGen2Teams {
* @return {RandomTeamsTypes["RandomSet"]}
*/
randomSet(template, slot) {
if (slot === undefined) slot = 1;
template = this.getTemplate(template);
if (!template.exists) template = this.getTemplate('pikachu'); // Because Gen 1.

Expand Down
3 changes: 1 addition & 2 deletions mods/gen2/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,12 @@ let BattleScripts = {
let doSelfDestruct = true;
/**@type {number | false} */
let damage = 0;
let hitResult = true;

if (move.selfdestruct && doSelfDestruct) {
this.faint(pokemon, pokemon, move);
}

hitResult = this.singleEvent('PrepareHit', move, {}, target, pokemon, move);
let hitResult = this.singleEvent('PrepareHit', move, {}, target, pokemon, move);
if (!hitResult) {
if (hitResult === false) this.add('-fail', target);
return false;
Expand Down
4 changes: 2 additions & 2 deletions mods/gen3/random-teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ class RandomGen3Teams extends RandomGen4Teams {
}
if (reqMove) {
// reject a move
for (let move of moves) {
for (let [i, move] of moves.entries()) {
if (move === 'weatherball' || this.getMove(move).type in hasType) continue;
move = reqMove;
moves[i] = reqMove;
let reqMoveIndex = movePool.indexOf(reqMove);
if (reqMoveIndex !== -1) this.fastPop(movePool, reqMoveIndex);
break;
Expand Down
3 changes: 1 addition & 2 deletions mods/gen3/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ let BattleScripts = {
},
tryMoveHit(target, pokemon, move) {
this.setActiveMove(move, pokemon, target);
let hitResult = true;
let naturalImmunity = false;
let accPass = true;

hitResult = this.singleEvent('PrepareHit', move, {}, target, pokemon, move);
let hitResult = this.singleEvent('PrepareHit', move, {}, target, pokemon, move);
if (!hitResult) {
if (hitResult === false) this.add('-fail', target);
return false;
Expand Down
1 change: 0 additions & 1 deletion mods/gen4/random-teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ class RandomGen4Teams extends RandomGen5Teams {
}
}

item = 'Leftovers';
if (template.requiredItems) {
item = this.sample(template.requiredItems);

Expand Down
3 changes: 1 addition & 2 deletions mods/gen4/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ let BattleScripts = {
},
tryMoveHit(target, pokemon, move) {
this.setActiveMove(move, pokemon, target);
let hitResult = true;

hitResult = this.singleEvent('PrepareHit', move, {}, target, pokemon, move);
let hitResult = this.singleEvent('PrepareHit', move, {}, target, pokemon, move);
if (!hitResult) {
if (hitResult === false) this.add('-fail', target);
return false;
Expand Down
2 changes: 1 addition & 1 deletion mods/gennext/moves.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ let BattleMovedex = {
onDamage: function (damage, target, source, effect) {
if (!effect || effect.effectType !== 'Move') return;
if (!source || source.side === target.side) return;
if (effect && effect.effectType === 'Move' && damage >= target.hp) {
if (effect.effectType === 'Move' && damage >= target.hp) {
damage = target.hp - 1;
}
this.effectData.totalDamage += damage;
Expand Down
2 changes: 1 addition & 1 deletion mods/stadium/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ let BattleScripts = {
hitResult = this.singleEvent('TryHit', moveData, {}, target, pokemon, move);

// Partial trapping moves still apply their volatile to Pokémon behind a Sub
let targetHadSub = (target && target.volatiles['substitute']);
const targetHadSub = !!target.volatiles['substitute'];
if (targetHadSub && moveData.volatileStatus && moveData.volatileStatus === 'partiallytrapped') {
target.addVolatile(moveData.volatileStatus, pokemon, move);
}
Expand Down
5 changes: 3 additions & 2 deletions sim/battle-stream-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ const p2spec = {
team: Dex.packTeam(Dex.generateTeam('gen7randombattle')),
};

// eslint-disable-next-line no-unused-vars
const p1 = new RandomPlayerAI(streams.p1);
// eslint-disable-next-line no-unused-vars
const p2 = new RandomPlayerAI(streams.p2);

console.log("p1 is " + p1.constructor.name);
console.log("p2 is " + p2.constructor.name);

(async () => {
let chunk;
while ((chunk = await streams.omniscient.read())) {
Expand Down
1 change: 0 additions & 1 deletion sim/battle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2700,7 +2700,6 @@ class Battle extends Dex.ModdedDex {
*/
prioritizeAction(action, source, sourceEffect) {
if (this.event) {
if (!source) source = this.event.source;
if (!sourceEffect) sourceEffect = this.effect;
}
for (const [i, curAction] of this.queue.entries()) {
Expand Down
Loading

0 comments on commit 24571ea

Please sign in to comment.