diff --git a/.eslintrc.json b/.eslintrc.json index 5ea8287780..b51915202c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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", diff --git a/ui/analyse/src/control.ts b/ui/analyse/src/control.ts index c988f99e10..6556847adc 100644 --- a/ui/analyse/src/control.ts +++ b/ui/analyse/src/control.ts @@ -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); } diff --git a/ui/analyse/src/crazy/crazyView.ts b/ui/analyse/src/crazy/crazyView.ts index 0c9a55f113..c884dd59a3 100644 --- a/ui/analyse/src/crazy/crazyView.ts +++ b/ui/analyse/src/crazy/crazyView.ts @@ -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; diff --git a/ui/analyse/src/study/studyCtrl.ts b/ui/analyse/src/study/studyCtrl.ts index a8be4e2f61..b48a4fc623 100644 --- a/ui/analyse/src/study/studyCtrl.ts +++ b/ui/analyse/src/study/studyCtrl.ts @@ -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) { diff --git a/ui/analyse/src/study/studyMembers.ts b/ui/analyse/src/study/studyMembers.ts index 475e6048b7..6597ee3b16 100644 --- a/ui/analyse/src/study/studyMembers.ts +++ b/ui/analyse/src/study/studyMembers.ts @@ -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(opts.initDict); const confing = prop(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; }, }; diff --git a/ui/challenge/src/view.ts b/ui/challenge/src/view.ts index d65b453dc3..4c0ea3b0b6 100644 --- a/ui/challenge/src/view.ts +++ b/ui/challenge/src/view.ts @@ -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()]; } diff --git a/ui/dasher/src/dasher.ts b/ui/dasher/src/dasher.ts index 587455069e..bded43ae90 100644 --- a/ui/dasher/src/dasher.ts +++ b/ui/dasher/src/dasher.ts @@ -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 = prop(defaultMode as Mode); + const mode: Prop = prop(defaultMode as Mode); function setMode(m: Mode) { mode(m); diff --git a/ui/dgt/src/play.ts b/ui/dgt/src/play.ts index 3d4f38d42d..f4c7b43227 100644 --- a/ui/dgt/src/play.ts +++ b/ui/dgt/src/play.ts @@ -123,7 +123,7 @@ export default function (token: string) { return new Promise(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; diff --git a/ui/lobby/src/setup.ts b/ui/lobby/src/setup.ts index b2eae98dcb..1abe629599 100644 --- a/ui/lobby/src/setup.ts +++ b/ui/lobby/src/setup.ts @@ -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) diff --git a/ui/lobby/src/view/realTime/chart.ts b/ui/lobby/src/view/realTime/chart.ts index f1c7b9dab6..51d10dd0a4 100644 --- a/ui/lobby/src/view/realTime/chart.ts +++ b/ui/lobby/src/view/realTime/chart.ts @@ -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) { diff --git a/ui/msg/src/view/interact.ts b/ui/msg/src/view/interact.ts index 972115b152..9c7adbdb63 100644 --- a/ui/msg/src/view/interact.ts +++ b/ui/msg/src/view/interact.ts @@ -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, () => { diff --git a/ui/nvui/src/chess.ts b/ui/nvui/src/chess.ts index ebd11df5d5..3f925e8f08 100644 --- a/ui/nvui/src/chess.ts +++ b/ui/nvui/src/chess.ts @@ -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()); diff --git a/ui/palantir/src/main.ts b/ui/palantir/src/main.ts index 5150fc68bc..e57d047a8e 100644 --- a/ui/palantir/src/main.ts +++ b/ui/palantir/src/main.ts @@ -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); } diff --git a/ui/puzzle/src/ctrl.ts b/ui/puzzle/src/ctrl.ts index 018150a28c..61b58f64b6 100644 --- a/ui/puzzle/src/ctrl.ts +++ b/ui/puzzle/src/ctrl.ts @@ -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(), } as Vm; let data: PuzzleData, tree: TreeWrapper, ceval: CevalCtrl; diff --git a/ui/round/src/plugins/keyboardMove.ts b/ui/round/src/plugins/keyboardMove.ts index e83ab7fb7a..5f5693bc50 100644 --- a/ui/round/src/plugins/keyboardMove.ts +++ b/ui/round/src/plugins/keyboardMove.ts @@ -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; } diff --git a/ui/round/src/plugins/nvui.ts b/ui/round/src/plugins/nvui.ts index a32c310322..a405c24da4 100644 --- a/ui/round/src/plugins/nvui.ts +++ b/ui/round/src/plugins/nvui.ts @@ -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; } diff --git a/ui/round/src/util.ts b/ui/round/src/util.ts index 6c474c7e8d..b3c978b18d 100644 --- a/ui/round/src/util.ts +++ b/ui/round/src/util.ts @@ -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++; diff --git a/ui/site/src/captcha.ts b/ui/site/src/captcha.ts index 096a41a136..8b82d2b8c4 100644 --- a/ui/site/src/captcha.ts +++ b/ui/site/src/captcha.ts @@ -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: { diff --git a/ui/site/src/checkout.ts b/ui/site/src/checkout.ts index 1931dd0e33..0ade0556a8 100644 --- a/ui/site/src/checkout.ts +++ b/ui/site/src/checkout.ts @@ -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); diff --git a/ui/site/src/coachForm.ts b/ui/site/src/coachForm.ts index d28e9c81b5..afbeda1af7 100644 --- a/ui/site/src/coachForm.ts +++ b/ui/site/src/coachForm.ts @@ -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; diff --git a/ui/site/src/component/pubsub.ts b/ui/site/src/component/pubsub.ts index dbca4a77f4..a44d7afdcb 100644 --- a/ui/site/src/component/pubsub.ts +++ b/ui/site/src/component/pubsub.ts @@ -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); }, }; diff --git a/ui/tournament/src/sound.ts b/ui/tournament/src/sound.ts index d21f306ae5..198091b1dc 100644 --- a/ui/tournament/src/sound.ts +++ b/ui/tournament/src/sound.ts @@ -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))); } diff --git a/ui/tournamentCalendar/src/view.ts b/ui/tournamentCalendar/src/view.ts index 125c78c489..651a07b00e 100644 --- a/ui/tournamentCalendar/src/view.ts +++ b/ui/tournamentCalendar/src/view.ts @@ -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]); }); diff --git a/ui/tree/src/ops.ts b/ui/tree/src/ops.ts index 1a0b5db141..4f0918a87c 100644 --- a/ui/tree/src/ops.ts +++ b/ui/tree/src/ops.ts @@ -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; } diff --git a/ui/tree/src/tree.ts b/ui/tree/src/tree.ts index 3926a55049..3794eb6bb4 100644 --- a/ui/tree/src/tree.ts +++ b/ui/tree/src/tree.ts @@ -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);