Fix some bugs caught by LGTM

This commit is contained in:
Guangcong Luo 2018-09-05 16:48:27 -05:00
parent 099fe28151
commit a133ee8c5e
15 changed files with 45 additions and 108 deletions

View File

@ -1,7 +1,5 @@
'use strict';
const os = require('os');
module.exports = {
"root": true,
"parserOptions": {

View File

@ -441,8 +441,8 @@ var BattleTooltips = (function () {
}
text += '</p>';
} else if (pokemonData.item) {
item = Tools.getItem(pokemonData.item).name;
text += '<p>Item: ' + item + '</p>';
var itemName = Tools.getItem(pokemonData.item).name;
text += '<p>Item: ' + itemName + '</p>';
}
text += '<p>' + pokemonData.stats['atk'] + '&nbsp;Atk /&nbsp;' + pokemonData.stats['def'] + '&nbsp;Def /&nbsp;' + pokemonData.stats['spa'];
if (this.battle.gen === 1) {
@ -868,28 +868,20 @@ var BattleTooltips = (function () {
}
// Weather and pseudo-weather type changes.
if (move.id === 'weatherball' && this.battle.weather) {
var noWeatherAbility = false;
// Check if your side has an anti weather ability to skip this.
if (!noWeatherAbility) {
for (var i = 0; i < this.battle.mySide.active.length; i++) {
if (this.battle.mySide.active[i] && this.battle.mySide.active[i].ability in {'Air Lock': 1, 'Cloud Nine': 1}) {
noWeatherAbility = true;
break;
}
}
}
// If you don't, check if the opponent has it afterwards.
if (!noWeatherAbility) {
for (var i = 0; i < this.battle.yourSide.active.length; i++) {
if (this.battle.yourSide.active[i] && this.battle.yourSide.active[i].ability in {'Air Lock': 1, 'Cloud Nine': 1}) {
noWeatherAbility = true;
break;
var antiWeatherAbility = false;
// Check if there's an anti weather ability to skip this.
abilitySearch: for (var i = 0; i < this.battle.sides.length; i++) {
var side = this.battle.sides[i];
for (var j = 0; j < side.active.length; j++) {
if (side.active[j] && ['Air Lock', 'Cloud Nine'].includes(side.active[j].ability)) {
antiWeatherAbility = true;
break abilitySearch;
}
}
}
// If the weather is indeed active, check it to see what move type weatherball gets.
if (!noWeatherAbility) {
if (!antiWeatherAbility) {
if (this.battle.weather === 'sunnyday' || this.battle.weather === 'desolateland') moveType = 'Fire';
if (this.battle.weather === 'raindance' || this.battle.weather === 'primordialsea') moveType = 'Water';
if (this.battle.weather === 'sandstorm') moveType = 'Rock';
@ -989,26 +981,18 @@ var BattleTooltips = (function () {
if (move.id in table.overrideBP) basePower = table.overrideBP[move.id];
}
var basePowerComment = '';
var noWeatherAbility = false;
// Check if your side has an anti weather ability to skip this.
if (!noWeatherAbility) {
for (var i = 0; i < this.battle.mySide.active.length; i++) {
if (this.battle.mySide.active[i] && this.battle.mySide.active[i].ability in {'Air Lock': 1, 'Cloud Nine': 1}) {
noWeatherAbility = true;
break;
var antiWeatherAbility = false;
// Check if there's an anti weather ability to skip this.
abilitySearch2: for (var i = 0; i < this.battle.sides.length; i++) {
var side = this.battle.sides[i];
for (var j = 0; j < side.active.length; j++) {
if (side.active[j] && ['Air Lock', 'Cloud Nine'].includes(side.active[j].ability)) {
antiWeatherAbility = true;
break abilitySearch2;
}
}
}
// If you don't, check if the opponent has it afterwards.
if (!noWeatherAbility) {
for (var i = 0; i < this.battle.yourSide.active.length; i++) {
if (this.battle.yourSide.active[i] && this.battle.yourSide.active[i].ability in {'Air Lock': 1, 'Cloud Nine': 1}) {
noWeatherAbility = true;
break;
}
}
}
var thereIsWeather = !!this.battle.weather && !noWeatherAbility;
var thereIsWeather = !!this.battle.weather && !antiWeatherAbility;
if (move.id === 'acrobatics') {
if (!pokemonData.item) {
basePower *= 2;

View File

@ -323,11 +323,7 @@
},
controlsShown: false,
updateControlsForPlayer: function () {
var battle = this.battle;
this.callbackWaiting = true;
var active = this.battle.mySide.active[0];
if (!active) active = {};
var act = '';
var switchables = [];
@ -904,7 +900,6 @@
return;
}
request.requestType = 'move';
var notifyObject = null;
if (request.forceSwitch) {
request.requestType = 'switch';
} else if (request.teamPreview) {
@ -998,7 +993,6 @@
e.stopPropagation();
},
switchSides: function () {
var paused = this.battle.paused;
this.battle.switchSides();
},
pause: function () {
@ -1060,10 +1054,8 @@
var isZMove = !!(this.$('input[name=zmove]')[0] || '').checked;
var isUltraBurst = !!(this.$('input[name=ultraburst]')[0] || '').checked;
var move = e.getAttribute('data-move');
var target = e.getAttribute('data-target');
var choosableTargets = {normal: 1, any: 1, adjacentAlly: 1, adjacentAllyOrSelf: 1, adjacentFoe: 1};
var spreadTargets = {allAdjacentFoes: 1, allAdjacent: 1};
this.choice.choices.push('move ' + pos + (isMega ? ' mega' : '') + (isZMove ? ' zmove' : '') + (isUltraBurst ? ' ultra' : ''));
if (myActive.length > 1 && target in choosableTargets) {

View File

@ -804,7 +804,7 @@
initialize: function (data) {
this.$el.html('<ul class="popupmenu">' + data.users.map(function (user) {
var escapedUser = Tools.escapeHTML(user);
return '<li><button name="selectUser" value="' + Tools.escapeQuotes(escapedUser) + '"' + (user === data.user ? ' class="sel"' : '') + '>' + escapedUser + '</button></li>';
return '<li><button name="selectUser" value="' + escapedUser + '"' + (user === data.user ? ' class="sel"' : '') + '>' + escapedUser + '</button></li>';
}).join('') + '</ul>');
},
selectUser: function (user) {

View File

@ -860,14 +860,13 @@
case 'join':
case 'j':
if (noSpace) return text;
var room = toRoomid(target);
if (app.rooms[target]) {
app.focusRoom(target);
return false;
}
room = toId(target);
if (app.rooms[room]) {
app.focusRoom(room);
var roomid = toId(target);
if (app.rooms[roomid]) {
app.focusRoom(roomid);
return false;
}
return text; // Send the /join command through to the server.
@ -1182,7 +1181,7 @@
}
},
addRow: function (line) {
var name, name2, room, action, silent, oldid;
var name, name2, silent;
if (line && typeof line === 'string') {
if (line.charAt(0) !== '|') line = '||' + line;
var row = line.substr(1).split('|');
@ -1229,7 +1228,7 @@
if (!matches) {
return; // bogus room ID could be used to inject JavaScript
}
var format = Tools.escapeFormat(matches ? matches[1] : '');
var format = Tools.escapeFormat(matches[1]);
if (silent && !Tools.prefs('showbattles')) return;
@ -1621,7 +1620,7 @@
return self.comparator(a, b);
});
}
for (var i = 0, len = users.length; i < users.length; i++) {
for (var i = 0; i < users.length; i++) {
var userid = users[i];
buf += this.constructItem(userid);
}

View File

@ -27,7 +27,6 @@
app.send('/leave ' + this.id);
},
addRow: function (line) {
var name, name2, room, action, silent, oldid;
if (!line || typeof line !== 'string') return;
if (line.charAt(0) !== '|') line = '||' + line;
var pipeIndex = line.indexOf('|', 1);

View File

@ -657,7 +657,6 @@
if (atLeastOneGen5 && !Tools.loadedSpriteData['bw']) Tools.loadSpriteData('bw');
},
openChallenge: function (name, $pmWindow) {
var userid = toId(name);
if (!$pmWindow) $pmWindow = this.openPM(name, true);
var $challenge = $pmWindow.find('.challenge');
if (!$challenge.length) {
@ -693,7 +692,6 @@
},
updateTeams: function () {
if (!window.BattleFormats) return;
var teams = Storage.teams;
var self = this;
this.$('button[name=team]').each(function (i, el) {
@ -942,7 +940,6 @@
var curSection = '';
for (var i in BattleFormats) {
var format = BattleFormats[i];
var selected = false;
if (selectType === 'teambuilder') {
if (!format.isTeambuilderFormat) continue;
} else {

View File

@ -283,6 +283,7 @@
buf += '<div class="folder"><h3>Gen ' + gen + '</h3></div>';
}
}
var formatName;
if (gen === '/') {
formatName = format.slice(1);
format = formatName + '/';
@ -295,7 +296,7 @@
buf += '<div class="folder' + (this.curFolder === format ? ' cur"><div class="folderhack3"><div class="folderhack1"></div><div class="folderhack2"></div>' : '">') + '<div class="selectFolder" data-value="' + format + '"><i class="fa ' + (this.curFolder === format ? 'fa-folder-open' : 'fa-folder') + (format === '/' ? '-o' : '') + '"></i>' + formatName + '</div></div>' + (this.curFolder === format ? '</div>' : '');
continue;
}
var formatName = format.slice(1);
formatName = format.slice(1);
if (formatName === '~') formatName = '';
format = 'gen' + newGen + formatName;
if (format.length === 4) formatName = '(uncategorized)';
@ -768,7 +769,6 @@
e.currentTarget.className = 'team';
},
dragStartTeam: function (e) {
var target = e.currentTarget;
var dataTransfer = e.originalEvent.dataTransfer;
dataTransfer.effectAllowed = 'copyMove';
@ -836,7 +836,6 @@
this.$('.teamlist').css('pointer-events', 'none');
$(teamEl).parent().removeClass('dragging');
var format = this.curFolder;
if (app.draggingFolder) {
var $folder = $(app.draggingFolder);
app.draggingFolder = null;
@ -848,7 +847,7 @@
var count = Number($plusOneFolder.text().substr(1)) + 1;
$plusOneFolder.text('+' + count);
}
format = $folder.data('value');
var format = $folder.data('value');
if (format.slice(-1) === '/') {
team.folder = format.slice(0, -1);
} else {
@ -1873,9 +1872,6 @@
this.plus = '';
this.minus = '';
for (var i in stats) {
var width = stats[i] * 200 / 504;
if (i == 'hp') width = stats[i] * 200 / 704;
if (width > 200) width = 200;
var val;
if (this.curTeam.gen > 2) {
val = '' + (set.evs[i] || '');
@ -2426,7 +2422,6 @@
var val = entry.slice(entry.indexOf("|") + 1);
if (this.curChartType === 'move' && e.currentTarget.className === 'cur') {
// clicked a move, remove it if we already have it
var $emptyEl;
var moves = [];
for (var i = 1; i <= 4; i++) {
var $inputEl = this.$('input[name=move' + i + ']');
@ -2606,7 +2601,6 @@
},
chartSet: function (val, selectNext) {
var inputName = this.curChartName;
var id = toId(val);
var input = this.$('input[name=' + inputName + ']');
if (this.chartSetCustom(input.val())) return;
input.val(val).removeClass('incomplete');
@ -2770,7 +2764,6 @@
setPokemon: function (val, selectNext) {
var set = this.curSet;
var template = Tools.getTemplate(val);
var newPokemon = !set.species;
if (!template.exists || set.species === template.species) {
if (selectNext) this.$('input[name=item]').select();
return;
@ -3040,7 +3033,6 @@
else if (stats.atk > stats.spa && moveCount['Physical'] > 1) offenseBias = 'Physical';
else if (moveCount['Special'] > moveCount['Physical']) offenseBias = 'Special';
else offenseBias = 'Physical';
var offenseStat = stats[offenseBias === 'Special' ? 'spa' : 'atk'];
if (moveCount['Stall'] + moveCount['Support'] / 2 <= 2 && bulk < 135000 && moveCount[offenseBias] >= 1.5) {
if (isFast) {

View File

@ -1527,7 +1527,6 @@
var leftMin = (this.curRoom.minWidth || this.curRoom.bestWidth);
var leftMinMain = (this.curRoom.minMainWidth || leftMin);
var rightMin = (this.sideRoom.minWidth || this.sideRoom.bestWidth);
var rightMinMain = (this.sideRoom.minMainWidth || leftMin);
var available = $(window).width();
if (this.curRoom.isSideRoom) {
// we're trying to focus a side room

View File

@ -897,7 +897,7 @@
var abilities = [];
if (template.isMega) {
if (format === 'almostanyability') abilitySet.unshift(['html', '<p>Will be <strong>' + Tools.escapeHTML(template.abilities['0']) + '</strong> after Mega Evolving.</p>']);
template = Tools.getTemplate(template.baseSpecies);
// template is unused after this, so no need to replace
}
for (var i in BattleAbilities) {
if (BattleAbilities[i].isNonstandard) continue;

View File

@ -176,7 +176,6 @@ Storage.bg = {
var s;
var l = (max + min) / 2;
if (max === min) {
h = s = 0;
return '0, 0%';
} else {
var d = max - min;
@ -1260,7 +1259,7 @@ Storage.exportTeam = function (team) {
}
if (defaultIvs && !hpType) {
for (var stat in BattleStatNames) {
if (curSet.ivs[stat] !== 31 && typeof curSet.ivs[stat] !== undefined) {
if (curSet.ivs[stat] !== 31 && curSet.ivs[stat] !== undefined) {
defaultIvs = false;
break;
}
@ -1282,7 +1281,7 @@ Storage.exportTeam = function (team) {
if (!first) {
text += " \n";
}
if (curSet.moves && curSet.moves) for (var j = 0; j < curSet.moves.length; j++) {
if (curSet.moves) for (var j = 0; j < curSet.moves.length; j++) {
var move = curSet.moves[j];
if (move.substr(0, 13) === 'Hidden Power ') {
move = move.substr(0, 13) + '[' + move.substr(13) + ']';
@ -1506,19 +1505,16 @@ Storage.nwDeleteAllTeams = function (callback) {
};
Storage.nwDeleteTeamFile = function (filename, callback) {
var self = this;
var line = filename;
if (line.substr(line.length - 4).toLowerCase() === '.txt') {
line = line.substr(0, line.length - 4);
} else {
if (filename.slice(-4).toLowerCase() !== '.txt') {
// not a team file
self.nwTeamsLeft--;
if (!self.nwTeamsLeft) {
this.nwTeamsLeft--;
if (!this.nwTeamsLeft) {
if (callback) callback();
Storage.fsReady.load();
}
return;
}
var self = this;
fs.unlink(this.dir + 'Teams/' + filename, function (err) {
var directory = filename.split('/').slice(0, -1).join('/');
fs.rmdir(directory, function () {});
@ -1627,7 +1623,6 @@ Storage.nwStopLoggingChat = function () {
};
Storage.nwLogChat = function (roomid, line) {
roomid = toRoomid(roomid);
var self = this;
if (!this.loggingChat) return;
var chatLogFdMonth = this.getLogMonth();
if (chatLogFdMonth !== this.chatLogFdMonth) {

View File

@ -6,7 +6,6 @@ const CLIENT_ID = '912270888098-jjnre816lsuhc5clj3vbcn4o2q7p4qvk.apps.googleuser
const token = process.argv[2];
var auth = new gal.GoogleAuth();
var client = new gal.OAuth2Client(CLIENT_ID, '', '');
client.verifyIdToken({
idToken: token,
@ -17,7 +16,7 @@ client.verifyIdToken({
function(e, login) {
if (e) return console.log(e);
var payload = login.getPayload();
var userid = payload['sub'];
// var userid = payload['sub'];
console.log(JSON.stringify(payload));
// If request specified a G Suite domain:
//var domain = payload['hd'];

View File

@ -320,7 +320,6 @@ class BattleScene {
left = 210;
top = 245;
scale = 1;
scale = 1.5 - 0.5 * ((loc.z!) / 200);
if (scale < .1) scale = .1;

View File

@ -415,7 +415,7 @@ const Tools = {
escapeHTML(str: string, jsEscapeToo?: boolean) {
str = getString(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
if (jsEscapeToo) str = str.replace(/'/g, '\\\'');
if (jsEscapeToo) str = str.replace(/\\/g, '\\\\').replace(/'/g, '\\\'');
return str;
},
@ -428,12 +428,6 @@ const Tools = {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
},
escapeQuotes(str: string) {
str = (str ? '' + str : '');
str = str.replace(/'/g, '\\\'');
return str;
},
sanitizeHTML: (function () {
if (!('html4' in window)) {
return function () {

View File

@ -250,7 +250,6 @@ class Pokemon {
delete this.volatiles[volatile];
}
addVolatile(volatile: ID, ...args: any[]) {
let battle = this.side.battle;
if (this.hasVolatile(volatile) && !args.length) return;
this.volatiles[volatile] = [volatile, ...args] as EffectState;
this.sprite.addEffect(volatile);
@ -265,7 +264,6 @@ class Pokemon {
}
addTurnstatus(volatile: ID) {
volatile = toId(volatile);
let battle = this.side.battle;
this.sprite.addEffect(volatile);
if (this.hasTurnstatus(volatile)) return;
this.turnstatuses[volatile] = [volatile];
@ -633,7 +631,7 @@ class Side {
this.spriteid = spriteid;
}
setName(name: string, spriteid?: string | number) {
if (name) this.name = (name || '');
if (name) this.name = name;
this.id = toId(this.name);
if (spriteid) {
this.spriteid = spriteid;
@ -652,7 +650,6 @@ class Side {
return "the opposing team";
}
addSideCondition(effect: Effect) {
let elem, curelem;
let condition = effect.id;
if (this.sideConditions[condition]) {
if (condition === 'spikes' || condition === 'toxicspikes') {
@ -709,7 +706,6 @@ class Side {
this.battle.scene.removeSideCondition(this.n, id);
}
newPokemon(data: any, replaceSlot = -1) {
let pokeobj;
let poke = new Pokemon(data, this);
if (!poke.ability && poke.baseAbility) poke.ability = poke.baseAbility;
poke.reset();
@ -1306,7 +1302,9 @@ class Battle {
if (!this.fastForward) {
this.scene.upkeepWeather();
}
if (newWeather && newWeather.upkeepMessage) this.message('<div><small>' + newWeather.upkeepMessage + '</small></div>');
if (newWeather && newWeather.upkeepMessage) {
this.message('<div><small>' + newWeather.upkeepMessage + '</small></div>');
}
return;
}
if (newWeather) {
@ -1322,10 +1320,6 @@ class Battle {
}
this.weatherTimeLeft = (this.gen <= 5 || isExtremeWeather) ? 0 : 8;
this.weatherMinTimeLeft = (this.gen <= 5 || isExtremeWeather) ? 0 : 5;
} else if (isUpkeep) {
this.scene.log('<div><small>' + newWeather.upkeepMessage + '</small></div>');
this.weatherTimeLeft = 0;
this.weatherMinTimeLeft = 0;
} else if (isExtremeWeather) {
this.message('<small>' + newWeather.startMessage + '</small>');
this.weatherTimeLeft = 0;
@ -4577,7 +4571,6 @@ class Battle {
newSpecies = args[2].substr(0, commaIndex);
}
let template = Tools.getTemplate(newSpecies);
let spriteData = {'shiny': poke.sprite.sp.shiny};
poke.species = newSpecies;
poke.ability = poke.baseAbility = (template.abilities ? template.abilities['0'] : '');
@ -4890,12 +4883,9 @@ class Battle {
if (this.endCallback) this.endCallback(this);
return;
}
let ret;
if (this.paused && !this.fastForward) return;
if (!ret) {
this.run(this.activityQueue[this.activityStep]);
this.activityStep++;
}
this.run(this.activityQueue[this.activityStep]);
this.activityStep++;
animations = this.scene.finishAnimations();
}