fix trivial cases of prefer-const

pull/8592/head
Niklas Fiekas 2021-04-07 19:18:28 +02:00
parent c55086b6e6
commit 51f6736d3f
25 changed files with 38 additions and 39 deletions

View File

@ -20,7 +20,6 @@
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }],
"eqeqeq": "off",
"prefer-const": "off",
"no-var": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",

View File

@ -24,7 +24,7 @@ export function first(ctrl: AnalyseCtrl): void {
}
export function enterVariation(ctrl: AnalyseCtrl): void {
let child = ctrl.node.children[1];
const child = ctrl.node.children[1];
if (child) ctrl.userJump(ctrl.path + child.id);
}

View File

@ -13,7 +13,7 @@ export default function (ctrl: AnalyseCtrl, color: Color, position: Position) {
if (!ctrl.node.crazy) return;
const pocket = ctrl.node.crazy.pockets[color === 'white' ? 0 : 1];
const dropped = ctrl.justDropped;
let captured = ctrl.justCaptured;
const captured = ctrl.justCaptured;
if (captured) captured.role = captured.promoted ? 'pawn' : captured.role;
const activeColor = color === ctrl.turnColor();
const usable = !ctrl.embed && activeColor;

View File

@ -631,7 +631,7 @@ export default function (
nextChapter(): StudyChapterMeta | undefined {
const chapters = data.chapters,
currentId = currentChapter().id;
for (let i in chapters) if (chapters[i].id === currentId) return chapters[parseInt(i) + 1];
for (const i in chapters) if (chapters[i].id === currentId) return chapters[parseInt(i) + 1];
return undefined;
},
setGamebookOverride(o) {

View File

@ -21,7 +21,7 @@ interface Opts {
function memberActivity(onIdle: () => void) {
let timeout: Timeout;
let schedule = () => {
const schedule = () => {
if (timeout) clearTimeout(timeout);
timeout = setTimeout(onIdle, 100);
};
@ -32,7 +32,7 @@ function memberActivity(onIdle: () => void) {
export function ctrl(opts: Opts) {
const dict = prop<StudyMemberMap>(opts.initDict);
const confing = prop<string | undefined>(undefined);
let active: { [id: string]: () => void } = {};
const active: { [id: string]: () => void } = {};
let online: { [id: string]: boolean } = {};
let spectatorIds: string[] = [];
const max = 30;
@ -150,7 +150,7 @@ export function ctrl(opts: Opts) {
},
hasOnlineContributor() {
const members = dict();
for (let i in members) if (online[i] && members[i].role === 'w') return true;
for (const i in members) if (online[i] && members[i].role === 'w') return true;
return false;
},
};

View File

@ -12,7 +12,7 @@ export function loading(): VNode {
}
function renderContent(ctrl: Ctrl): VNode[] {
let d = ctrl.data();
const d = ctrl.data();
const nb = d.in.length + d.out.length;
return nb ? [allChallenges(ctrl, d, nb)] : [empty(), create()];
}

View File

@ -50,7 +50,7 @@ export interface DasherOpts {
export function makeCtrl(opts: DasherOpts, data: DasherData, redraw: Redraw): DasherCtrl {
const trans = lichess.trans(data.i18n);
let mode: Prop<Mode> = prop(defaultMode as Mode);
const mode: Prop<Mode> = prop(defaultMode as Mode);
function setMode(m: Mode) {
mode(m);

View File

@ -123,7 +123,7 @@ export default function (token: string) {
return new Promise<void>(resolve => {
var output = '';
for (let i = 0; i < arguments.length; i++) {
let arg = arguments[i];
const arg = arguments[i];
if (arg == '*' || arg == ':') {
output += arg;
} else {
@ -137,7 +137,7 @@ export default function (token: string) {
}
}
//Added to keep on-screen log small
let maxLogBytes = verbose ? -1048576 : -8192;
const maxLogBytes = verbose ? -1048576 : -8192;
let isScrolledToBottom = false;
if (autoScroll) {
isScrolledToBottom =
@ -416,7 +416,7 @@ export default function (token: string) {
//sleep 5 seconds and just listen to events
await sleep(5000);
//Check if any started games are disconnected
for (let [gameId, networkState] of gameConnectionMap) {
for (const [gameId, networkState] of gameConnectionMap) {
if (!networkState.connected && gameStateMap.get(gameId).status == 'started') {
//Game is not conencted and has not finished, reconnect
if (verbose) console.log(`Started game is disconnected. Attempting reconnection for gameId: ${gameId}`);
@ -468,7 +468,7 @@ export default function (token: string) {
let index = -1;
for (let i = 0; i < playableGames.length; i++) {
//makeBoardFen return only the board, ideal for comparison
let tmpFEN = fen.makeBoardFen(gameChessBoardMap.get(playableGames[i].gameId)!.board);
const tmpFEN = fen.makeBoardFen(gameChessBoardMap.get(playableGames[i].gameId)!.board);
if (verbose) console.log(`GameId: ${playableGames[i].gameId} FEN: ${tmpFEN}`);
if (tmpFEN == lastLiveChessBoard) {
index = i;
@ -1152,7 +1152,7 @@ export default function (token: string) {
*/
function padBeforeNumbers(moveString: string) {
var paddedMoveString = '';
for (let c of moveString) {
for (const c of moveString) {
Number.isInteger(+c) ? (paddedMoveString += ` ${c} `) : (paddedMoveString += c);
}
return paddedMoveString;

View File

@ -115,7 +115,7 @@ export default class Setup {
private hookToPoolMember = (color: string, form: HTMLFormElement) => {
const data = Array.from(new FormData(form).entries());
const hash: any = {};
for (let i in data) hash[data[i][0]] = data[i][1];
for (const i in data) hash[data[i][0]] = data[i][1];
const valid = color == 'random' && hash.variant == 1 && hash.mode == 1 && hash.timeMode == 1,
id = parseFloat(hash.time) + '+' + parseInt(hash.increment);
return valid && this.root.pools.find(p => p.id === id)

View File

@ -10,7 +10,7 @@ const ratingLog = (a: number) => Math.log(a / 150 + 1);
function ratingY(e: number) {
const rating = Math.max(1000, Math.min(2200, e || 1500));
let ratio: number;
let mid = 2 / 5;
const mid = 2 / 5;
if (rating == 1500) {
ratio = mid;
} else if (rating > 1500) {

View File

@ -64,7 +64,7 @@ function setupTextarea(area: HTMLTextAreaElement, contact: string, ctrl: MsgCtrl
// hack to automatically resize the textarea based on content
area.value = '';
let baseScrollHeight = area.scrollHeight;
const baseScrollHeight = area.scrollHeight;
area.addEventListener(
'input',
throttle(500, () => {

View File

@ -304,7 +304,7 @@ export function renderBoard(
return h('th', { attrs: { scope: 'row' } }, rank);
};
const doFileHeaders = (): VNode => {
let ths = files.map(file => h('th', { attrs: { scope: 'col' } }, file));
const ths = files.map(file => h('th', { attrs: { scope: 'col' } }, file));
if (pov === 'black') ths.reverse();
return h('tr', [h('td'), ...ths, h('td')]);
};
@ -344,14 +344,14 @@ export function renderBoard(
}
};
const doRank = (pov: Color, rank: Rank): VNode => {
let rankElements = [];
const rankElements = [];
if (boardStyle === 'table') rankElements.push(doRankHeader(rank));
rankElements.push(...files.map(file => doPiece(rank, file)));
if (boardStyle === 'table') rankElements.push(doRankHeader(rank));
if (pov === 'black') rankElements.reverse();
return h(boardStyle === 'table' ? 'tr' : 'div', rankElements);
};
let ranks: VNode[] = [];
const ranks: VNode[] = [];
if (boardStyle === 'table') ranks.push(doFileHeaders());
ranks.push(...invRanks.map(rank => doRank(pov, rank)));
if (boardStyle === 'table') ranks.push(doFileHeaders());

View File

@ -145,7 +145,7 @@ export function palantir(opts: PalantirOpts) {
}
function closeDisconnectedCalls() {
if (peer) {
for (let otherPeer in peer.connections) {
for (const otherPeer in peer.connections) {
peer.connections[otherPeer].forEach(c => {
if (c.peerConnection && c.peerConnection.connectionState == 'disconnected') {
log(`close disconnected call to ${c.peer}`);
@ -159,7 +159,7 @@ export function palantir(opts: PalantirOpts) {
function allOpenConnections() {
if (!peer) return [];
const conns: any[] = [];
for (let peerId in peer.connections) {
for (const peerId in peer.connections) {
const c = findOpenConnectionTo(peerId);
if (c) conns.push(c);
}

View File

@ -24,7 +24,7 @@ import { Role, Move, Outcome } from 'chessops/types';
import { storedProp } from 'common/storage';
export default function (opts: PuzzleOpts, redraw: Redraw): Controller {
let vm: Vm = {
const vm: Vm = {
next: defer<PuzzleData>(),
} as Vm;
let data: PuzzleData, tree: TreeWrapper, ceval: CevalCtrl;

View File

@ -122,7 +122,7 @@ function makeBindings(opts: any, submit: Submit, clear: () => void) {
function sanToUci(san: string, legalSans: SanToUci): Uci | undefined {
if (san in legalSans) return legalSans[san];
const lowered = san.toLowerCase();
for (let i in legalSans) if (i.toLowerCase() === lowered) return legalSans[i];
for (const i in legalSans) if (i.toLowerCase() === lowered) return legalSans[i];
return;
}

View File

@ -368,7 +368,7 @@ function destsToUcis(dests: Dests) {
function sanToUci(san: string, legalSans: SanToUci): Uci | undefined {
if (san in legalSans) return legalSans[san];
const lowered = san.toLowerCase();
for (let i in legalSans) if (i.toLowerCase() === lowered) return legalSans[i];
for (const i in legalSans) if (i.toLowerCase() === lowered) return legalSans[i];
return;
}

View File

@ -80,7 +80,7 @@ export const noChecks: CheckCount = {
export function countChecks(steps: Step[], ply: Ply): CheckCount {
const checks: CheckCount = { ...noChecks };
for (let step of steps) {
for (const step of steps) {
if (ply < step.ply) break;
if (step.check) {
if (step.ply % 2 === 1) checks.white++;

View File

@ -11,7 +11,7 @@ lichess.load.then(() => {
fen = cg.getFen(),
destsObj = $board.data('moves'),
dests = new Map();
for (let k in destsObj) dests.set(k, destsObj[k].match(/.{2}/g));
for (const k in destsObj) dests.set(k, destsObj[k].match(/.{2}/g));
cg.set({
turnColor: cg.state.orientation,
movable: {

View File

@ -67,8 +67,8 @@ export default function (publicKey: string) {
$checkout.find('.service').html(lichess.spinnerHtml);
});
let stripe = window.Stripe(publicKey);
let showError = (error: string) => {
const stripe = window.Stripe(publicKey);
const showError = (error: string) => {
// TODO: consider a more sophisticated error handling mechanism,
// for now, this should work just fine.
alert(error);

View File

@ -28,7 +28,7 @@ lichess.load.then(() => {
{
html: 'Fill in basic information',
check() {
for (let name of ['profile.headline', 'languages']) {
for (const name of ['profile.headline', 'languages']) {
if (!$editor.find('[name="' + name + '"]').val()) return false;
}
return true;

View File

@ -1,4 +1,4 @@
let subs: Array<() => void> = [];
const subs: Array<() => void> = [];
const pubsub: Pubsub = {
on(name: string, cb) {
@ -7,7 +7,7 @@ const pubsub: Pubsub = {
},
off(name: string, cb) {
if (subs[name])
for (let i in subs[name]) {
for (const i in subs[name]) {
if (subs[name][i] === cb) {
subs[name].splice(i);
break;
@ -15,7 +15,7 @@ const pubsub: Pubsub = {
}
},
emit(name: string, ...args: any[]) {
if (subs[name]) for (let i in subs[name]) subs[name][i].apply(null, args);
if (subs[name]) for (const i in subs[name]) subs[name][i].apply(null, args);
},
};

View File

@ -7,14 +7,14 @@ function doCountDown(targetTime: number) {
let started = false;
return function curCounter() {
let secondsToStart = (targetTime - performance.now()) / 1000;
const secondsToStart = (targetTime - performance.now()) / 1000;
// always play the 0 sound before completing.
let bestTick = Math.max(0, Math.round(secondsToStart));
const bestTick = Math.max(0, Math.round(secondsToStart));
if (bestTick <= 10) lichess.sound.play('countDown' + bestTick);
if (bestTick > 0) {
let nextTick = Math.min(10, bestTick - 1);
const nextTick = Math.min(10, bestTick - 1);
countDownTimeout = setTimeout(curCounter, 1000 * Math.min(1.1, Math.max(0.8, secondsToStart - nextTick)));
}

View File

@ -69,7 +69,7 @@ function fitLane(lane: Tournament[], tour2: Tournament) {
function makeLanes(tours: Tournament[]): Lanes {
const lanes: Lanes = [];
tours.forEach(t => {
let lane = lanes.find(l => fitLane(l, t));
const lane = lanes.find(l => fitLane(l, t));
if (lane) lane.push(t);
else lanes.push([t]);
});

View File

@ -41,7 +41,7 @@ export function nodeAtPly(nodeList: Tree.Node[], ply: number): Tree.Node | undef
export function takePathWhile(nodeList: Tree.Node[], predicate: (node: Tree.Node) => boolean): Tree.Path {
let path = '';
for (let i in nodeList) {
for (const i in nodeList) {
if (predicate(nodeList[i])) path += nodeList[i].id;
else break;
}

View File

@ -68,7 +68,7 @@ export function build(root: Tree.Node): TreeWrapper {
function getCurrentNodesAfterPly(nodeList: Tree.Node[], mainline: Tree.Node[], ply: number): Tree.Node[] {
var node,
nodes = [];
for (let i in nodeList) {
for (const i in nodeList) {
node = nodeList[i];
if (node.ply <= ply && mainline[i].id !== node.id) break;
if (node.ply > ply) nodes.push(node);