From c55086b6e612c68a87a256a15caa5bf157107610 Mon Sep 17 00:00:00 2001 From: Niklas Fiekas Date: Wed, 7 Apr 2021 18:47:59 +0200 Subject: [PATCH] comply with @typescript-eslint/no-inferrable-types --- .eslintrc.json | 17 ++++++----------- ui/analyse/src/actionMenu.ts | 2 +- ui/analyse/src/ctrl.ts | 10 +++++----- ui/analyse/src/fork.ts | 2 +- ui/analyse/src/practice/practiceCtrl.ts | 2 +- ui/analyse/src/study/description.ts | 2 +- ui/analyse/src/study/multiBoard.ts | 6 +++--- ui/analyse/src/study/relay/relayCtrl.ts | 2 +- ui/analyse/src/util.ts | 4 ++-- ui/common/src/gridHacks.ts | 2 +- ui/dgt/src/play.ts | 2 +- ui/lobby/src/ctrl.ts | 4 ++-- ui/lobby/src/filter.ts | 2 +- ui/lobby/src/setup.ts | 2 +- ui/msg/src/view/scroller.ts | 2 +- ui/palantir/src/main.ts | 2 +- ui/puz/src/clock.ts | 2 +- ui/puz/src/current.ts | 2 +- ui/puzzle/src/streak.ts | 2 +- ui/puzzle/src/view/main.ts | 2 +- ui/round/src/ctrl.ts | 14 +++++++------- ui/round/src/keyboardMove.ts | 2 +- ui/round/src/util.ts | 2 +- ui/round/src/view/button.ts | 4 ++-- ui/round/src/view/main.ts | 2 +- ui/site/src/component/friends.ts | 2 +- ui/site/src/component/socket.ts | 10 +++++----- ui/site/src/component/sound.ts | 2 +- ui/site/src/expandText.ts | 4 ++-- ui/site/src/infiniteScroll.ts | 2 +- ui/site/src/modUser.ts | 2 +- ui/swiss/src/ctrl.ts | 6 +++--- ui/tournament/src/ctrl.ts | 8 ++++---- ui/tournament/src/view/util.ts | 2 +- 34 files changed, 64 insertions(+), 69 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index b2319265ca..5ea8287780 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -9,26 +9,21 @@ "sourceType": "module" }, "plugins": ["@typescript-eslint"], - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:@typescript-eslint/recommended" - ], + "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:@typescript-eslint/recommended"], "rules": { "linebreak-style": ["error", "unix"], "no-duplicate-imports": "error", "@typescript-eslint/no-empty-function": "off", + "@typescript-eslint/no-non-null-assertion": "off", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-this-alias": "off", + "@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }], "eqeqeq": "off", "prefer-const": "off", "no-var": "off", - "@typescript-eslint/explicit-module-boundary-types": "off", - "@typescript-eslint/no-non-null-assertion": "off", - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-inferrable-types": "off", - "@typescript-eslint/no-unused-vars": "off", "@typescript-eslint/no-empty-interface": "off", - "@typescript-eslint/no-this-alias": "off", + "@typescript-eslint/explicit-module-boundary-types": "off", "prefer-spread": "off", "prefer-rest-params": "off", "no-useless-escape": "off", diff --git a/ui/analyse/src/actionMenu.ts b/ui/analyse/src/actionMenu.ts index d4e7ac6e96..1e375a7c3a 100644 --- a/ui/analyse/src/actionMenu.ts +++ b/ui/analyse/src/actionMenu.ts @@ -153,7 +153,7 @@ function studyButton(ctrl: AnalyseCtrl) { } export class ActionMenuCtrl { - open: boolean = false; + open = false; toggle = (): void => { this.open = !this.open; }; diff --git a/ui/analyse/src/ctrl.ts b/ui/analyse/src/ctrl.ts index e642eef011..97d34c825a 100644 --- a/ui/analyse/src/ctrl.ts +++ b/ui/analyse/src/ctrl.ts @@ -76,16 +76,16 @@ export default class AnalyseCtrl { justPlayed?: string; // pos justDropped?: string; // role justCaptured?: JustCaptured; - autoScrollRequested: boolean = false; - redirecting: boolean = false; - onMainline: boolean = true; + autoScrollRequested = false; + redirecting = false; + onMainline = true; synthetic: boolean; // false if coming from a real game ongoing: boolean; // true if real game is ongoing // display flags - flipped: boolean = false; + flipped = false; embed: boolean; - showComments: boolean = true; // whether to display comments in the move tree + showComments = true; // whether to display comments in the move tree showAutoShapes: StoredBooleanProp = storedProp('show-auto-shapes', true); showGauge: StoredBooleanProp = storedProp('show-gauge', true); showComputer: StoredBooleanProp = storedProp('show-computer', true); diff --git a/ui/analyse/src/fork.ts b/ui/analyse/src/fork.ts index 74b1073c51..50d642ad1e 100644 --- a/ui/analyse/src/fork.ts +++ b/ui/analyse/src/fork.ts @@ -18,7 +18,7 @@ export interface ForkCtrl { export function make(root: AnalyseCtrl): ForkCtrl { let prev: Tree.Node | undefined; - let selected: number = 0; + let selected = 0; function displayed() { return root.node.children.length > 1; } diff --git a/ui/analyse/src/practice/practiceCtrl.ts b/ui/analyse/src/practice/practiceCtrl.ts index 61b1faa4d0..06bbde75f5 100644 --- a/ui/analyse/src/practice/practiceCtrl.ts +++ b/ui/analyse/src/practice/practiceCtrl.ts @@ -63,7 +63,7 @@ export function make(root: AnalyseCtrl, playableDepth: () => number): PracticeCt if (root.threatMode()) root.toggleThreatMode(); } - function commentable(node: Tree.Node, bonus: number = 0): boolean { + function commentable(node: Tree.Node, bonus = 0): boolean { if (node.tbhit || root.outcome(node)) return true; const ceval = node.ceval; return ceval ? ceval.depth + bonus >= 15 || (ceval.depth >= 13 && ceval.millis > 3000) : false; diff --git a/ui/analyse/src/study/description.ts b/ui/analyse/src/study/description.ts index 88a10fa861..90723511b8 100644 --- a/ui/analyse/src/study/description.ts +++ b/ui/analyse/src/study/description.ts @@ -5,7 +5,7 @@ import { bind, richHTML, onInsert } from '../util'; export type Save = (string) => void; export class DescriptionCtrl { - edit: boolean = false; + edit = false; constructor(public text: string | undefined, readonly doSave: Save, readonly redraw: () => void) {} diff --git a/ui/analyse/src/study/multiBoard.ts b/ui/analyse/src/study/multiBoard.ts index 97f727e9f7..66ad0ecdf1 100644 --- a/ui/analyse/src/study/multiBoard.ts +++ b/ui/analyse/src/study/multiBoard.ts @@ -7,10 +7,10 @@ import { bind, spinner } from '../util'; import * as domData from 'common/data'; export class MultiBoardCtrl { - loading: boolean = false; - page: number = 1; + loading = false; + page = 1; pager?: Paginator; - playing: boolean = false; + playing = false; constructor(readonly studyId: string, readonly redraw: () => void, readonly trans: Trans) {} diff --git a/ui/analyse/src/study/relay/relayCtrl.ts b/ui/analyse/src/study/relay/relayCtrl.ts index d28d60f341..57cf15f348 100644 --- a/ui/analyse/src/study/relay/relayCtrl.ts +++ b/ui/analyse/src/study/relay/relayCtrl.ts @@ -4,7 +4,7 @@ import { isFinished } from '../studyChapters'; export default class RelayCtrl { log: LogEvent[] = []; - cooldown: boolean = false; + cooldown = false; clockInterval?: number; intro: RelayIntro; diff --git a/ui/analyse/src/util.ts b/ui/analyse/src/util.ts index 8639418eab..4526f9136f 100644 --- a/ui/analyse/src/util.ts +++ b/ui/analyse/src/util.ts @@ -135,7 +135,7 @@ export function innerHTML(a: A, toHtml: (a: A) => string): Hooks { }; } -export function richHTML(text: string, newLines: boolean = true): Hooks { +export function richHTML(text: string, newLines = true): Hooks { return innerHTML(text, t => enrichText(t, newLines)); } @@ -192,7 +192,7 @@ function toLink(url: string) { return `${show}`; } -export function enrichText(text: string, allowNewlines: boolean = true): string { +export function enrichText(text: string, allowNewlines = true): string { let html = autolink(lichess.escapeHtml(text), toLink); if (allowNewlines) html = html.replace(newLineRegex, '
'); return html; diff --git a/ui/common/src/gridHacks.ts b/ui/common/src/gridHacks.ts index 7ab0bb9409..d114d51380 100644 --- a/ui/common/src/gridHacks.ts +++ b/ui/common/src/gridHacks.ts @@ -1,6 +1,6 @@ import throttle from './throttle'; -export const runner = (hacks: () => void, throttleMs: number = 100): void => { +export const runner = (hacks: () => void, throttleMs = 100): void => { let timeout: number | undefined; const runHacks = throttle(throttleMs, () => diff --git a/ui/dgt/src/play.ts b/ui/dgt/src/play.ts index 0b2c24f0fd..3d4f38d42d 100644 --- a/ui/dgt/src/play.ts +++ b/ui/dgt/src/play.ts @@ -164,7 +164,7 @@ export default function (token: string) { * * @param {number} ms - The number of milliseconds to sleep */ - function sleep(ms: number = 0) { + function sleep(ms = 0) { return new Promise(r => setTimeout(r, ms)); } diff --git a/ui/lobby/src/ctrl.ts b/ui/lobby/src/ctrl.ts index 8ba0935ecb..35f468af91 100644 --- a/ui/lobby/src/ctrl.ts +++ b/ui/lobby/src/ctrl.ts @@ -19,8 +19,8 @@ export default class LobbyController { mode: Mode; sort: Sort; stepHooks: Hook[] = []; - stepping: boolean = false; - redirecting: boolean = false; + stepping = false; + redirecting = false; poolMember?: PoolMember; trans: Trans; pools: Pool[]; diff --git a/ui/lobby/src/filter.ts b/ui/lobby/src/filter.ts index 6416b0d30d..66d7cada94 100644 --- a/ui/lobby/src/filter.ts +++ b/ui/lobby/src/filter.ts @@ -15,7 +15,7 @@ interface Filtered { export default class Filter { store: FormStore; data: FilterData | null; - open: boolean = false; + open = false; constructor(storage: LichessStorage, readonly root: LobbyController) { this.store = makeStore(storage); diff --git a/ui/lobby/src/setup.ts b/ui/lobby/src/setup.ts index 826f36e309..b2eae98dcb 100644 --- a/ui/lobby/src/setup.ts +++ b/ui/lobby/src/setup.ts @@ -183,7 +183,7 @@ export default class Setup { const showRating = () => { const timeMode = $timeModeSelect.val(); - let key: string = 'correspondence'; + let key = 'correspondence'; switch ($variantSelect.val()) { case '1': case '3': diff --git a/ui/msg/src/view/scroller.ts b/ui/msg/src/view/scroller.ts index e13e82ceb6..c0ae73c0b0 100644 --- a/ui/msg/src/view/scroller.ts +++ b/ui/msg/src/view/scroller.ts @@ -1,7 +1,7 @@ import throttle from 'common/throttle'; class Scroller { - enabled: boolean = false; + enabled = false; element?: HTMLElement; marker?: HTMLElement; diff --git a/ui/palantir/src/main.ts b/ui/palantir/src/main.ts index 6ab833d438..5150fc68bc 100644 --- a/ui/palantir/src/main.ts +++ b/ui/palantir/src/main.ts @@ -107,7 +107,7 @@ export function palantir(opts: PalantirOpts) { console.log('[palantir]', msg); } - function setState(s: State, msg: string = '') { + function setState(s: State, msg = '') { log(`state: ${state} -> ${s} ${msg}`); state = s; opts.redraw(); diff --git a/ui/puz/src/clock.ts b/ui/puz/src/clock.ts index 5c7beea69d..558000a9f4 100644 --- a/ui/puz/src/clock.ts +++ b/ui/puz/src/clock.ts @@ -5,7 +5,7 @@ export class Clock { startAt: number | undefined; initialMillis: number; - public constructor(readonly config: Config, startedMillisAgo: number = 0) { + public constructor(readonly config: Config, startedMillisAgo = 0) { this.initialMillis = config.clock.initial * 1000 - (startedMillisAgo || 0); } diff --git a/ui/puz/src/current.ts b/ui/puz/src/current.ts index f0e7a2882c..c4e60190b4 100644 --- a/ui/puz/src/current.ts +++ b/ui/puz/src/current.ts @@ -6,7 +6,7 @@ import { getNow } from './util'; export default class CurrentPuzzle { line: Uci[]; startAt: number; - moveIndex: number = 0; + moveIndex = 0; pov: Color; constructor(readonly index: number, readonly puzzle: Puzzle) { diff --git a/ui/puzzle/src/streak.ts b/ui/puzzle/src/streak.ts index 19437e3909..dbd2adb539 100644 --- a/ui/puzzle/src/streak.ts +++ b/ui/puzzle/src/streak.ts @@ -15,7 +15,7 @@ interface StreakData { export default class PuzzleStreak { data: StreakData; - fail: boolean = false; + fail = false; store: StoredJsonProp; constructor(data: PuzzleData) { diff --git a/ui/puzzle/src/view/main.ts b/ui/puzzle/src/view/main.ts index 80b9ce38ee..9ec58d49e2 100644 --- a/ui/puzzle/src/view/main.ts +++ b/ui/puzzle/src/view/main.ts @@ -29,7 +29,7 @@ function dataAct(e: Event): string | null { return target.getAttribute('data-act') || (target.parentNode as HTMLElement).getAttribute('data-act'); } -function jumpButton(icon: string, effect: string, disabled: boolean, glowing: boolean = false): VNode { +function jumpButton(icon: string, effect: string, disabled: boolean, glowing = false): VNode { return h('button.fbt', { class: { disabled, glowing }, attrs: { diff --git a/ui/round/src/ctrl.ts b/ui/round/src/ctrl.ts index 6c14bfa7a2..107ab0fae0 100644 --- a/ui/round/src/ctrl.ts +++ b/ui/round/src/ctrl.ts @@ -61,11 +61,11 @@ export default class RoundController { moveOn: MoveOn; ply: number; - firstSeconds: boolean = true; - flip: boolean = false; - loading: boolean = false; + firstSeconds = true; + flip = false; + loading = false; loadingTimeout: number; - redirecting: boolean = false; + redirecting = false; transientMove: TransientMove; moveToSubmit?: SocketMove; dropToSubmit?: SocketDrop; @@ -74,10 +74,10 @@ export default class RoundController { drawConfirm?: Timeout = undefined; // will be replaced by view layer autoScroll: () => void = () => {}; - challengeRematched: boolean = false; + challengeRematched = false; justDropped?: cg.Role; justCaptured?: cg.Piece; - shouldSendMoveTime: boolean = false; + shouldSendMoveTime = false; preDrop?: cg.Role; lastDrawOfferAtPly?: Ply; nvui?: NvuiPlugin; @@ -615,7 +615,7 @@ export default class RoundController { this.redraw(); }; - setLoading = (v: boolean, duration: number = 1500) => { + setLoading = (v: boolean, duration = 1500) => { clearTimeout(this.loadingTimeout); if (v) { this.loading = true; diff --git a/ui/round/src/keyboardMove.ts b/ui/round/src/keyboardMove.ts index d6c4b91080..aa40b57974 100644 --- a/ui/round/src/keyboardMove.ts +++ b/ui/round/src/keyboardMove.ts @@ -70,7 +70,7 @@ export function ctrl(root: RoundController, step: Step, redraw: Redraw): Keyboar root.chessground.cancelMove(); sendPromotion(root, orig, dest, role, { premove: false }); }, - update(step, yourMove: boolean = false) { + update(step, yourMove = false) { if (handler) handler(step.fen, cgState.movable.dests, yourMove); else preHandlerBuffer = step.fen; }, diff --git a/ui/round/src/util.ts b/ui/round/src/util.ts index 60765aa3fa..6c474c7e8d 100644 --- a/ui/round/src/util.ts +++ b/ui/round/src/util.ts @@ -28,7 +28,7 @@ export const onInsert = (f: (el: HTMLElement) => void): Hooks => ({ }, }); -export const bind = (eventName: string, f: (e: Event) => void, redraw?: Redraw, passive: boolean = true): Hooks => +export const bind = (eventName: string, f: (e: Event) => void, redraw?: Redraw, passive = true): Hooks => onInsert(el => { el.addEventListener( eventName, diff --git a/ui/round/src/view/button.ts b/ui/round/src/view/button.ts index f992d0309e..392ce3ee0b 100644 --- a/ui/round/src/view/button.ts +++ b/ui/round/src/view/button.ts @@ -212,7 +212,7 @@ export function cancelTakebackProposition(ctrl: RoundController) { : null; } -function acceptButton(ctrl: RoundController, klass: string, action: () => void, i18nKey: string = 'accept') { +function acceptButton(ctrl: RoundController, klass: string, action: () => void, i18nKey: I18nKey = 'accept') { const text = ctrl.noarg(i18nKey); return ctrl.nvui ? h( @@ -230,7 +230,7 @@ function acceptButton(ctrl: RoundController, klass: string, action: () => void, hook: util.bind('click', action), }); } -function declineButton(ctrl: RoundController, action: () => void, i18nKey: string = 'decline') { +function declineButton(ctrl: RoundController, action: () => void, i18nKey: I18nKey = 'decline') { const text = ctrl.noarg(i18nKey); return ctrl.nvui ? h( diff --git a/ui/round/src/view/main.ts b/ui/round/src/view/main.ts index 35e4aa96ef..dfd0f9cd99 100644 --- a/ui/round/src/view/main.ts +++ b/ui/round/src/view/main.ts @@ -46,7 +46,7 @@ export function main(ctrl: RoundController): VNode { topColor = d[ctrl.flip ? 'player' : 'opponent'].color, bottomColor = d[ctrl.flip ? 'opponent' : 'player'].color; let material: MaterialDiff, - score: number = 0; + score = 0; if (d.pref.showCaptured) { const pieces = cgState ? cgState.pieces : fenRead(plyStep(ctrl.data, ctrl.ply).fen); material = util.getMaterialDiff(pieces); diff --git a/ui/site/src/component/friends.ts b/ui/site/src/component/friends.ts index a5f1ee1119..2c9345777e 100644 --- a/ui/site/src/component/friends.ts +++ b/ui/site/src/component/friends.ts @@ -14,7 +14,7 @@ interface Friend { export default class OnlineFriends { titleEl: HTMLElement; - loaded: boolean = false; + loaded = false; trans: Trans; users: Map; diff --git a/ui/site/src/component/socket.ts b/ui/site/src/component/socket.ts index 6138e13cf4..0fc3627449 100644 --- a/ui/site/src/component/socket.ts +++ b/ui/site/src/component/socket.ts @@ -54,11 +54,11 @@ export default class StrongSocket { connectSchedule: Timeout; ackable: Ackable = new Ackable((t, d, o) => this.send(t, d, o)); lastPingTime: number = performance.now(); - pongCount: number = 0; - averageLag: number = 0; - tryOtherUrl: boolean = false; - autoReconnect: boolean = true; - nbConnects: number = 0; + pongCount = 0; + averageLag = 0; + tryOtherUrl = false; + autoReconnect = true; + nbConnects = 0; storage: LichessStorage = makeStorage.make('surl15'); private _sign?: string; diff --git a/ui/site/src/component/sound.ts b/ui/site/src/component/sound.ts index ff6b47219c..47236afcc0 100644 --- a/ui/site/src/component/sound.ts +++ b/ui/site/src/component/sound.ts @@ -63,7 +63,7 @@ const sound = new (class { return this.speechStorage.get(); }; - say = (text: any, cut: boolean = false, force: boolean = false) => { + say = (text: any, cut = false, force = false) => { if (!this.speechStorage.get() && !force) return false; const msg = text.text ? (text as SpeechSynthesisUtterance) : new SpeechSynthesisUtterance(text); msg.volume = this.getVolume(); diff --git a/ui/site/src/expandText.ts b/ui/site/src/expandText.ts index 530c0938d6..e9ef90937d 100644 --- a/ui/site/src/expandText.ts +++ b/ui/site/src/expandText.ts @@ -76,7 +76,7 @@ lichess.load.then(() => { return $iframe; } - function expandYoutubes(as: Candidate[], wait: number = 100) { + function expandYoutubes(as: Candidate[], wait = 100) { var a = as.shift(), wait = Math.min(1500, wait); if (a) @@ -103,7 +103,7 @@ lichess.load.then(() => { }); } - function expandStudies(as: Candidate[], wait: number = 100) { + function expandStudies(as: Candidate[], wait = 100) { const a = as.shift(); wait = Math.min(1500, wait); if (a) diff --git a/ui/site/src/infiniteScroll.ts b/ui/site/src/infiniteScroll.ts index 424c92c158..e3313939fd 100644 --- a/ui/site/src/infiniteScroll.ts +++ b/ui/site/src/infiniteScroll.ts @@ -7,7 +7,7 @@ export default function InfiniteScroll(selector: string) { }); } -function register(el: HTMLElement, selector: string, backoff: number = 500) { +function register(el: HTMLElement, selector: string, backoff = 500) { const nav = el.querySelector('.pager') as HTMLAnchorElement | null, next = nav?.querySelector('.pager a') as HTMLAnchorElement | null, nextUrl = next?.href; diff --git a/ui/site/src/modUser.ts b/ui/site/src/modUser.ts index 7086715608..792a92f24a 100644 --- a/ui/site/src/modUser.ts +++ b/ui/site/src/modUser.ts @@ -62,7 +62,7 @@ lichess.load.then(() => { function userMod($inZone: Cash) { lichess.contentLoaded($inZone[0]); - const makeReady = (selector: string, f: (el: HTMLElement, i: number) => void, cls: string = 'ready') => { + const makeReady = (selector: string, f: (el: HTMLElement, i: number) => void, cls = 'ready') => { $inZone.find(selector + `:not(.${cls})`).each(function (this: HTMLElement, i: number) { f($(this).addClass(cls)[0] as HTMLElement, i); }); diff --git a/ui/swiss/src/ctrl.ts b/ui/swiss/src/ctrl.ts index 040bf33d52..7427ef99fa 100644 --- a/ui/swiss/src/ctrl.ts +++ b/ui/swiss/src/ctrl.ts @@ -12,10 +12,10 @@ export default class SwissCtrl { pages: Pages = {}; lastPageDisplayed: number | undefined; focusOnMe: boolean; - joinSpinner: boolean = false; + joinSpinner = false; playerInfoId?: string; - disableClicks: boolean = true; - searching: boolean = false; + disableClicks = true; + searching = false; private lastStorage = lichess.storage.make('last-redirect'); diff --git a/ui/tournament/src/ctrl.ts b/ui/tournament/src/ctrl.ts index 9e51284ba7..61f00b6319 100644 --- a/ui/tournament/src/ctrl.ts +++ b/ui/tournament/src/ctrl.ts @@ -21,12 +21,12 @@ export default class TournamentController { pages: Pages = {}; lastPageDisplayed: number | undefined; focusOnMe: boolean; - joinSpinner: boolean = false; + joinSpinner = false; playerInfo: PlayerInfo = {}; teamInfo: CtrlTeamInfo = {}; - disableClicks: boolean = true; - searching: boolean = false; - joinWithTeamSelector: boolean = false; + disableClicks = true; + searching = false; + joinWithTeamSelector = false; redraw: () => void; private lastStorage = lichess.storage.make('last-redirect'); diff --git a/ui/tournament/src/view/util.ts b/ui/tournament/src/view/util.ts index 7e76f4010a..0415a4aa2c 100644 --- a/ui/tournament/src/view/util.ts +++ b/ui/tournament/src/view/util.ts @@ -33,7 +33,7 @@ export function playerName(p) { return p.title ? [h('span.utitle', p.title), ' ' + p.name] : p.name; } -export function player(p, asLink: boolean, withRating: boolean, defender: boolean = false, leader: boolean = false) { +export function player(p, asLink: boolean, withRating: boolean, defender = false, leader = false) { return h( 'a.ulpt.user-link' + (((p.title || '') + p.name).length > 15 ? '.long' : ''), {