From 0df36490c7871fdcf06d6b1cee9bd092e5440837 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Sun, 7 May 2023 18:07:18 +0200 Subject: [PATCH] fix lints in foundkey-js Fixes all lints except '@typescript-eslint/no-explicit-any'. --- packages/foundkey-js/src/api.ts | 12 +++++++----- packages/foundkey-js/src/entities.ts | 9 +++------ packages/foundkey-js/src/streaming.ts | 7 +++---- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/foundkey-js/src/api.ts b/packages/foundkey-js/src/api.ts index 923fbd304..8a9ff1fce 100644 --- a/packages/foundkey-js/src/api.ts +++ b/packages/foundkey-js/src/api.ts @@ -42,13 +42,15 @@ export class APIClient { constructor(opts: { origin: APIClient['origin']; credential?: APIClient['credential']; - fetch?: APIClient['fetch'] | null | undefined; + fetch?: FetchLike; }) { this.origin = opts.origin; this.credential = opts.credential; - // ネイティブ関数をそのまま変数に代入して使おうとするとChromiumではIllegal invocationエラーが発生するため、 - // 環境で実装されているfetchを使う場合は無名関数でラップして使用する - this.fetch = opts.fetch || ((...args) => fetch(...args)); + // Wrap a native function with an anonymous function when using + // environment-implemented fetch, because Chromium generates an + // Illegal invocation error if you try to use a native function by + // assigning it to a variable as it is. + this.fetch = opts.fetch || (((...args) => fetch(...args)) as FetchLike); } public request( @@ -79,7 +81,7 @@ export class APIClient { cache: 'no-cache', }).then(async (res) => { const body = res.status === 204 ? null : await res.json(); - + if (res.status === 200) { resolve(body); } else if (res.status === 204) { diff --git a/packages/foundkey-js/src/entities.ts b/packages/foundkey-js/src/entities.ts index d2cbe8289..5cec05c99 100644 --- a/packages/foundkey-js/src/entities.ts +++ b/packages/foundkey-js/src/entities.ts @@ -135,9 +135,9 @@ export type Note = { user: User; userId: User['id']; reply?: Note; - replyId: Note['id']; + replyId: Note['id'] | null; renote?: Note; - renoteId: Note['id']; + renoteId: Note['id'] | null; files: DriveFile[]; fileIds: DriveFile['id'][]; visibility: NoteVisibility; @@ -475,9 +475,6 @@ export function isPureRenote(note: Note): boolean { return note.renoteId != null && note.text == null && note.cw == null - && ( - note.fileIds == null - || note.fileIds.length === 0 - ) + && note.fileIds.length === 0 && note.poll == null; } diff --git a/packages/foundkey-js/src/streaming.ts b/packages/foundkey-js/src/streaming.ts index 0892db9d9..8f397f720 100644 --- a/packages/foundkey-js/src/streaming.ts +++ b/packages/foundkey-js/src/streaming.ts @@ -34,14 +34,13 @@ export default class Stream extends EventEmitter { constructor(origin: string, user: { token: string; } | null, options?: { WebSocket?: any; - }) { + } = {}) { super(); - options = options || { }; const query = urlQuery({ i: user?.token, - - // To prevent cache of an HTML such as error screen + + // cache busting parameter _t: Date.now(), });