From 4cf05ba1da1fcb5de774aaf34a136785b2d98586 Mon Sep 17 00:00:00 2001 From: topce Date: Mon, 5 Apr 2021 21:27:25 +0200 Subject: [PATCH] switch on ban-types --- .eslintrc.json | 2 +- ui/@types/cash/index.d.ts | 3 +++ ui/analyse/src/study/interfaces.ts | 4 ++-- ui/analyse/src/study/relay/relayCtrl.ts | 2 +- ui/chat/src/enhance.ts | 2 +- ui/common/src/resize.ts | 11 ++++++++--- ui/lobby/src/interfaces.ts | 2 +- 7 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index ab986ea4ef..1daec756bd 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -33,7 +33,7 @@ "no-constant-condition": "off", "no-prototype-builtins": "off", "no-extra-boolean-cast": "off", - "@typescript-eslint/ban-types": "off", + "@typescript-eslint/ban-types": "error", "no-async-promise-executor": "off", "@typescript-eslint/adjacent-overload-signatures": "off" } diff --git a/ui/@types/cash/index.d.ts b/ui/@types/cash/index.d.ts index 29072df33d..e895c3e002 100644 --- a/ui/@types/cash/index.d.ts +++ b/ui/@types/cash/index.d.ts @@ -10,6 +10,7 @@ interface CashStatic { declare type falsy = undefined | null | false | 0 | ''; declare type Ele = Window | Document | HTMLElement | Element | Node; declare type EleLoose = HTMLElement & Element & Node; +// eslint-disable-next-line @typescript-eslint/ban-types declare type Selector = falsy | string | Function | HTMLCollection | NodeList | Ele | Ele[] | ArrayLike | Cash; declare type Comparator = string | Ele | Cash | ((this: EleLoose, index: number, ele: EleLoose) => boolean); declare type Context = Document | HTMLElement | Element; @@ -44,6 +45,7 @@ interface CashStatic { } interface CashStatic { isWindow(x: any): x is Window; + // eslint-disable-next-line @typescript-eslint/ban-types isFunction(x: any): x is Function; isNumeric(x: any): boolean; isArray(x: any): x is Array; @@ -156,6 +158,7 @@ interface Cash { one(events: string, selector: string | null | undefined, data: any, callback: EventCallback): this; } interface Cash { + // eslint-disable-next-line @typescript-eslint/ban-types ready(callback: Function): this; } interface Cash { diff --git a/ui/analyse/src/study/interfaces.ts b/ui/analyse/src/study/interfaces.ts index ce1f284814..f8103ac82c 100644 --- a/ui/analyse/src/study/interfaces.ts +++ b/ui/analyse/src/study/interfaces.ts @@ -112,8 +112,8 @@ export interface StudySettings { explorer: UserSelection; cloneable: UserSelection; chat: UserSelection; - sticky: Boolean; - description: Boolean; + sticky: boolean; + description: boolean; } export interface ReloadData { diff --git a/ui/analyse/src/study/relay/relayCtrl.ts b/ui/analyse/src/study/relay/relayCtrl.ts index d5991a7f5c..d28d60f341 100644 --- a/ui/analyse/src/study/relay/relayCtrl.ts +++ b/ui/analyse/src/study/relay/relayCtrl.ts @@ -25,7 +25,7 @@ export default class RelayCtrl { }; } - setSync = (v: Boolean) => { + setSync = (v: boolean) => { this.send('relaySync', v); this.redraw(); }; diff --git a/ui/chat/src/enhance.ts b/ui/chat/src/enhance.ts index 4ff04e81c7..ac87187fe6 100644 --- a/ui/chat/src/enhance.ts +++ b/ui/chat/src/enhance.ts @@ -22,7 +22,7 @@ function linkReplace(_: string, url: string) { const userPattern = /(^|[^\w@#/])@([\w-]{2,})/g; const pawnDropPattern = /^[a-h][2-7]$/; -function userLinkReplace(orig: string, prefix: String, user: string) { +function userLinkReplace(orig: string, prefix: string, user: string) { if (user.length > 20 || user.match(pawnDropPattern)) return orig; return prefix + '@' + user + ''; } diff --git a/ui/common/src/resize.ts b/ui/common/src/resize.ts index 941855e0bb..d080d6918a 100644 --- a/ui/common/src/resize.ts +++ b/ui/common/src/resize.ts @@ -2,7 +2,7 @@ import * as cg from 'chessground/types'; import * as xhr from './xhr'; import debounce from './debounce'; -export type MouchEvent = MouseEvent & TouchEvent; +export type MouchEvent = MouseEvent | TouchEvent; type Visible = (ply: Ply) => boolean; @@ -60,7 +60,12 @@ export default function resizeHandle(els: cg.Elements, pref: number, ply: number } function eventPosition(e: MouchEvent): [number, number] | undefined { - if (e.clientX || e.clientX === 0) return [e.clientX, e.clientY]; - if (e.touches && e.targetTouches[0]) return [e.targetTouches[0].clientX, e.targetTouches[0].clientY]; + if (isMouseEvent(e)) { + if (e.clientX || e.clientX === 0) return [e.clientX, e.clientY]; + } else if (e.touches && e.targetTouches[0]) return [e.targetTouches[0].clientX, e.targetTouches[0].clientY]; return undefined; } + +function isMouseEvent(e: MouchEvent): e is MouseEvent { + return (e as MouseEvent).clientX !== undefined; +} diff --git a/ui/lobby/src/interfaces.ts b/ui/lobby/src/interfaces.ts index 65a048ef28..e62c036f0b 100644 --- a/ui/lobby/src/interfaces.ts +++ b/ui/lobby/src/interfaces.ts @@ -40,7 +40,7 @@ export interface NowPlaying { gameId: string; fen: Fen; color: Color; - lastMove: String; + lastMove: string; variant: { key: string; name: string;