From b9eaf906e7b7202d06c9fea72b6d3c422a03f81e Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 12 Nov 2021 10:52:10 +0900 Subject: [PATCH] fix lint errors --- packages/backend/.eslintrc.js | 3 ++ packages/backend/@types/jsrsasign.d.ts | 2 +- packages/backend/src/mfm/from-html.ts | 3 +- packages/backend/src/misc/cafy-id.ts | 1 + packages/backend/src/misc/gen-avatar.ts | 2 +- packages/backend/src/prelude/array.ts | 2 +- packages/backend/src/prelude/url.ts | 2 +- .../object-storage/clean-remote-files.ts | 2 +- .../src/queue/processors/system/index.ts | 4 +-- .../queue/processors/system/resync-charts.ts | 2 +- packages/backend/src/queue/queues.ts | 2 +- packages/backend/src/queue/types.ts | 2 +- .../src/remote/activitypub/models/person.ts | 2 +- .../renderer/ordered-collection.ts | 2 +- packages/backend/src/server/api/define.ts | 6 ++-- .../server/api/endpoints/channels/update.ts | 2 +- .../server/api/endpoints/i/2fa/key-done.ts | 2 +- packages/backend/src/server/api/limiter.ts | 8 ++--- .../api/stream/channels/games/reversi.ts | 3 +- .../backend/src/server/api/stream/types.ts | 2 +- packages/backend/src/services/chart/core.ts | 16 ++++----- packages/backend/src/services/stream.ts | 34 +++++++++---------- 22 files changed, 55 insertions(+), 49 deletions(-) diff --git a/packages/backend/.eslintrc.js b/packages/backend/.eslintrc.js index 952a2ee9e..bafd0c9b6 100644 --- a/packages/backend/.eslintrc.js +++ b/packages/backend/.eslintrc.js @@ -22,6 +22,7 @@ module.exports = { 'eol-last': ['error', 'always'], 'semi': ['error', 'always'], 'quotes': ['warn', 'single'], + 'comma-dangle': ['warn', 'always-multiline'], 'keyword-spacing': ['error', { 'before': true, 'after': true, @@ -44,6 +45,8 @@ module.exports = { 'no-multi-spaces': ['warn'], 'no-control-regex': ['warn'], 'no-empty': ['warn'], + 'no-inner-declarations': ['off'], + 'no-sparse-arrays': ['off'], '@typescript-eslint/no-var-requires': ['warn'], '@typescript-eslint/no-inferrable-types': ['warn'], '@typescript-eslint/no-empty-function': ['off'], diff --git a/packages/backend/@types/jsrsasign.d.ts b/packages/backend/@types/jsrsasign.d.ts index bc9d746f7..bb52f8f64 100644 --- a/packages/backend/@types/jsrsasign.d.ts +++ b/packages/backend/@types/jsrsasign.d.ts @@ -171,7 +171,7 @@ declare module 'jsrsasign' { public static getTLVbyList(h: ASN1S, currentIndex: Idx, nthList: Mutable, checkingTag?: string): ASN1TLV; - // tslint:disable-next-line:bool-param-default + // eslint:disable-next-line:bool-param-default public static getVbyList(h: ASN1S, currentIndex: Idx, nthList: Mutable, checkingTag?: string, removeUnusedbits?: boolean): ASN1V; public static hextooidstr(hex: ASN1OIDV): OID; diff --git a/packages/backend/src/mfm/from-html.ts b/packages/backend/src/mfm/from-html.ts index de6aa3d0c..43e16d80c 100644 --- a/packages/backend/src/mfm/from-html.ts +++ b/packages/backend/src/mfm/from-html.ts @@ -48,9 +48,10 @@ export function fromHtml(html: string, hashtagNames?: string[]): string | null { if (!treeAdapter.isElementNode(node)) return; switch (node.nodeName) { - case 'br': + case 'br': { text += '\n'; break; + } case 'a': { diff --git a/packages/backend/src/misc/cafy-id.ts b/packages/backend/src/misc/cafy-id.ts index 39886611e..dd81c5c4c 100644 --- a/packages/backend/src/misc/cafy-id.ts +++ b/packages/backend/src/misc/cafy-id.ts @@ -1,5 +1,6 @@ import { Context } from 'cafy'; +// eslint-disable-next-line @typescript-eslint/ban-types export class ID extends Context { public readonly name = 'ID'; diff --git a/packages/backend/src/misc/gen-avatar.ts b/packages/backend/src/misc/gen-avatar.ts index f03ca9f96..8838ec8d1 100644 --- a/packages/backend/src/misc/gen-avatar.ts +++ b/packages/backend/src/misc/gen-avatar.ts @@ -56,7 +56,7 @@ export function genAvatar(seed: string, stream: WriteStream): Promise { // 1*n (filled by false) const center: boolean[] = new Array(n).fill(false); - // tslint:disable-next-line:prefer-for-of + // eslint:disable-next-line:prefer-for-of for (let x = 0; x < side.length; x++) { for (let y = 0; y < side[x].length; y++) { side[x][y] = rand(3) === 0; diff --git a/packages/backend/src/prelude/array.ts b/packages/backend/src/prelude/array.ts index d63f0475d..1e9e62b89 100644 --- a/packages/backend/src/prelude/array.ts +++ b/packages/backend/src/prelude/array.ts @@ -87,7 +87,7 @@ export function groupOn(f: (x: T) => S, xs: T[]): T[][] { export function groupByX(collections: T[], keySelector: (x: T) => string) { return collections.reduce((obj: Record, item: T) => { const key = keySelector(item); - if (!obj.hasOwnProperty(key)) { + if (!Object.prototype.hasOwnProperty.call(obj, key)) { obj[key] = []; } diff --git a/packages/backend/src/prelude/url.ts b/packages/backend/src/prelude/url.ts index c7f2b7c1e..a4f2f7f5a 100644 --- a/packages/backend/src/prelude/url.ts +++ b/packages/backend/src/prelude/url.ts @@ -1,4 +1,4 @@ -export function query(obj: {}): string { +export function query(obj: Record): string { const params = Object.entries(obj) .filter(([, v]) => Array.isArray(v) ? v.length : v !== undefined) .reduce((a, [k, v]) => (a[k] = v, a), {} as Record); diff --git a/packages/backend/src/queue/processors/object-storage/clean-remote-files.ts b/packages/backend/src/queue/processors/object-storage/clean-remote-files.ts index 3b2e4ea93..a094c39d5 100644 --- a/packages/backend/src/queue/processors/object-storage/clean-remote-files.ts +++ b/packages/backend/src/queue/processors/object-storage/clean-remote-files.ts @@ -7,7 +7,7 @@ import { MoreThan, Not, IsNull } from 'typeorm'; const logger = queueLogger.createSubLogger('clean-remote-files'); -export default async function cleanRemoteFiles(job: Bull.Job<{}>, done: any): Promise { +export default async function cleanRemoteFiles(job: Bull.Job>, done: any): Promise { logger.info(`Deleting cached remote files...`); let deletedCount = 0; diff --git a/packages/backend/src/queue/processors/system/index.ts b/packages/backend/src/queue/processors/system/index.ts index 52b786810..8460ea0a9 100644 --- a/packages/backend/src/queue/processors/system/index.ts +++ b/packages/backend/src/queue/processors/system/index.ts @@ -3,9 +3,9 @@ import { resyncCharts } from './resync-charts'; const jobs = { resyncCharts, -} as Record | Bull.ProcessPromiseFunction<{}>>; +} as Record> | Bull.ProcessPromiseFunction>>; -export default function(dbQueue: Bull.Queue<{}>) { +export default function(dbQueue: Bull.Queue>) { for (const [k, v] of Object.entries(jobs)) { dbQueue.process(k, v); } diff --git a/packages/backend/src/queue/processors/system/resync-charts.ts b/packages/backend/src/queue/processors/system/resync-charts.ts index b36b024cf..78a70bb98 100644 --- a/packages/backend/src/queue/processors/system/resync-charts.ts +++ b/packages/backend/src/queue/processors/system/resync-charts.ts @@ -5,7 +5,7 @@ import { driveChart, notesChart, usersChart } from '@/services/chart/index'; const logger = queueLogger.createSubLogger('resync-charts'); -export default async function resyncCharts(job: Bull.Job<{}>, done: any): Promise { +export async function resyncCharts(job: Bull.Job>, done: any): Promise { logger.info(`Resync charts...`); // TODO: ユーザーごとのチャートも更新する diff --git a/packages/backend/src/queue/queues.ts b/packages/backend/src/queue/queues.ts index a66a7ca45..b1d790fcb 100644 --- a/packages/backend/src/queue/queues.ts +++ b/packages/backend/src/queue/queues.ts @@ -2,7 +2,7 @@ import config from '@/config/index'; import { initialize as initializeQueue } from './initialize'; import { DeliverJobData, InboxJobData, DbJobData, ObjectStorageJobData } from './types'; -export const systemQueue = initializeQueue<{}>('system'); +export const systemQueue = initializeQueue>('system'); export const deliverQueue = initializeQueue('deliver', config.deliverJobPerSec || 128); export const inboxQueue = initializeQueue('inbox', config.inboxJobPerSec || 16); export const dbQueue = initializeQueue('db'); diff --git a/packages/backend/src/queue/types.ts b/packages/backend/src/queue/types.ts index 39cab2996..c8c714715 100644 --- a/packages/backend/src/queue/types.ts +++ b/packages/backend/src/queue/types.ts @@ -33,7 +33,7 @@ export type DbUserImportJobData = { fileId: DriveFile['id']; }; -export type ObjectStorageJobData = ObjectStorageFileJobData | {}; +export type ObjectStorageJobData = ObjectStorageFileJobData | Record; export type ObjectStorageFileJobData = { key: string; diff --git a/packages/backend/src/remote/activitypub/models/person.ts b/packages/backend/src/remote/activitypub/models/person.ts index eb8c00a10..95db46bff 100644 --- a/packages/backend/src/remote/activitypub/models/person.ts +++ b/packages/backend/src/remote/activitypub/models/person.ts @@ -274,7 +274,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise { +export async function updatePerson(uri: string, resolver?: Resolver | null, hint?: Record): Promise { if (typeof uri !== 'string') throw new Error('uri is not string'); // URIがこのサーバーを指しているならスキップ diff --git a/packages/backend/src/remote/activitypub/renderer/ordered-collection.ts b/packages/backend/src/remote/activitypub/renderer/ordered-collection.ts index 68870a0ec..c4b4337af 100644 --- a/packages/backend/src/remote/activitypub/renderer/ordered-collection.ts +++ b/packages/backend/src/remote/activitypub/renderer/ordered-collection.ts @@ -6,7 +6,7 @@ * @param last URL of last page (optional) * @param orderedItems attached objects (optional) */ -export default function(id: string | null, totalItems: any, first?: string, last?: string, orderedItems?: object) { +export default function(id: string | null, totalItems: any, first?: string, last?: string, orderedItems?: Record) { const page: any = { id, type: 'OrderedCollection', diff --git a/packages/backend/src/server/api/define.ts b/packages/backend/src/server/api/define.ts index 4bd8f95e3..48253e78e 100644 --- a/packages/backend/src/server/api/define.ts +++ b/packages/backend/src/server/api/define.ts @@ -20,7 +20,7 @@ type SimpleUserInfo = { }; type Params = { - [P in keyof T['params']]: NonNullable[P]['transform'] extends Function + [P in keyof T['params']]: NonNullable[P]['transform'] extends () => any ? ReturnType[P]['transform']> : NonNullable[P]['default'] extends null | number | string ? NonOptional[P]['validator']['get']>[0]> @@ -30,7 +30,7 @@ type Params = { export type Response = Record | void; type executor = - (params: Params, user: T['requireCredential'] extends true ? SimpleUserInfo : SimpleUserInfo | null, token: AccessToken | null, file?: any, cleanup?: Function) => + (params: Params, user: T['requireCredential'] extends true ? SimpleUserInfo : SimpleUserInfo | null, token: AccessToken | null, file?: any, cleanup?: () => any) => Promise>>; export default function (meta: T, cb: executor) @@ -74,7 +74,7 @@ function getParams(defs: T, params: any): [Params, A }); return true; } else { - if (v === undefined && def.hasOwnProperty('default')) { + if (v === undefined && Object.prototype.hasOwnProperty.call(def, 'default')) { x[k] = def.default; } else { x[k] = v; diff --git a/packages/backend/src/server/api/endpoints/channels/update.ts b/packages/backend/src/server/api/endpoints/channels/update.ts index 9b447bd04..05f279d6a 100644 --- a/packages/backend/src/server/api/endpoints/channels/update.ts +++ b/packages/backend/src/server/api/endpoints/channels/update.ts @@ -69,7 +69,7 @@ export default define(meta, async (ps, me) => { throw new ApiError(meta.errors.accessDenied); } - // tslint:disable-next-line:no-unnecessary-initializer + // eslint:disable-next-line:no-unnecessary-initializer let banner = undefined; if (ps.bannerId != null) { banner = await DriveFiles.findOne({ diff --git a/packages/backend/src/server/api/endpoints/i/2fa/key-done.ts b/packages/backend/src/server/api/endpoints/i/2fa/key-done.ts index b4d3af235..e06d0a9f6 100644 --- a/packages/backend/src/server/api/endpoints/i/2fa/key-done.ts +++ b/packages/backend/src/server/api/endpoints/i/2fa/key-done.ts @@ -75,7 +75,7 @@ export default define(meta, async (ps, user) => { const flags = attestation.authData[32]; - // tslint:disable-next-line:no-bitwise + // eslint:disable-next-line:no-bitwise if (!(flags & 1)) { throw new Error('user not present'); } diff --git a/packages/backend/src/server/api/limiter.ts b/packages/backend/src/server/api/limiter.ts index 1e2fe5bcb..82a8613c9 100644 --- a/packages/backend/src/server/api/limiter.ts +++ b/packages/backend/src/server/api/limiter.ts @@ -10,16 +10,16 @@ const logger = new Logger('limiter'); export default (endpoint: IEndpoint, user: User) => new Promise((ok, reject) => { const limitation = endpoint.meta.limit!; - const key = limitation.hasOwnProperty('key') + const key = Object.prototype.hasOwnProperty.call(limitation, 'key') ? limitation.key : endpoint.name; const hasShortTermLimit = - limitation.hasOwnProperty('minInterval'); + Object.prototype.hasOwnProperty.call(limitation, 'minInterval'); const hasLongTermLimit = - limitation.hasOwnProperty('duration') && - limitation.hasOwnProperty('max'); + Object.prototype.hasOwnProperty.call(limitation, 'duration') && + Object.prototype.hasOwnProperty.call(limitation, 'max'); if (hasShortTermLimit) { min(); diff --git a/packages/backend/src/server/api/stream/channels/games/reversi.ts b/packages/backend/src/server/api/stream/channels/games/reversi.ts index 3b89aac35..399750c26 100644 --- a/packages/backend/src/server/api/stream/channels/games/reversi.ts +++ b/packages/backend/src/server/api/stream/channels/games/reversi.ts @@ -19,7 +19,7 @@ export default class extends Channel { @autobind public async onMessage(type: string, body: any) { switch (type) { - case 'ping': + case 'ping': { if (body.id == null) return; const matching = await ReversiMatchings.findOne({ parentId: this.user!.id, @@ -28,6 +28,7 @@ export default class extends Channel { if (matching == null) return; publishMainStream(matching.childId, 'reversiInvited', await ReversiMatchings.pack(matching, { id: matching.childId })); break; + } } } } diff --git a/packages/backend/src/server/api/stream/types.ts b/packages/backend/src/server/api/stream/types.ts index 70eb5c5ce..f4302f64a 100644 --- a/packages/backend/src/server/api/stream/types.ts +++ b/packages/backend/src/server/api/stream/types.ts @@ -31,7 +31,7 @@ export interface BroadcastTypes { } export interface UserStreamTypes { - terminate: {}; + terminate: Record; followChannel: Channel; unfollowChannel: Channel; updateUserProfile: UserProfile; diff --git a/packages/backend/src/services/chart/core.ts b/packages/backend/src/services/chart/core.ts index c0d3280c2..78b7dd135 100644 --- a/packages/backend/src/services/chart/core.ts +++ b/packages/backend/src/services/chart/core.ts @@ -70,7 +70,7 @@ export default abstract class Chart> { @autobind private static convertSchemaToFlatColumnDefinitions(schema: SimpleSchema) { - const columns = {} as any; + const columns = {} as Record; const flatColumns = (x: Obj, path?: string) => { for (const [k, v] of Object.entries(x)) { const p = path ? `${path}${this.columnDot}${k}` : k; @@ -93,8 +93,8 @@ export default abstract class Chart> { } @autobind - private static convertFlattenColumnsToObject(x: Record): Record { - const obj = {} as any; + private static convertFlattenColumnsToObject(x: Record): Record { + const obj = {} as Record; for (const k of Object.keys(x).filter(k => k.startsWith(Chart.columnPrefix))) { // now k is ___x_y_z const path = k.substr(Chart.columnPrefix.length).split(Chart.columnDot).join('.'); @@ -104,7 +104,7 @@ export default abstract class Chart> { } @autobind - private static convertObjectToFlattenColumns(x: Record) { + private static convertObjectToFlattenColumns(x: Record) { const columns = {} as Record; const flatten = (x: Obj, path?: string) => { for (const [k, v] of Object.entries(x)) { @@ -121,9 +121,9 @@ export default abstract class Chart> { } @autobind - private static countUniqueFields(x: Record) { + private static countUniqueFields(x: Record) { const exec = (x: Obj) => { - const res = {} as Record; + const res = {} as Record; for (const [k, v] of Object.entries(x)) { if (typeof v === 'object' && !Array.isArray(v)) { res[k] = exec(v); @@ -140,7 +140,7 @@ export default abstract class Chart> { @autobind private static convertQuery(diff: Record) { - const query: Record = {}; + const query: Record string> = {}; for (const [k, v] of Object.entries(diff)) { if (typeof v === 'number') { @@ -337,7 +337,7 @@ export default abstract class Chart> { } @autobind - public async save() { + public async save(): Promise { if (this.buffer.length === 0) { logger.info(`${this.name}: Write skipped`); return; diff --git a/packages/backend/src/services/stream.ts b/packages/backend/src/services/stream.ts index 2c308a1b5..0901857c3 100644 --- a/packages/backend/src/services/stream.ts +++ b/packages/backend/src/services/stream.ts @@ -37,74 +37,74 @@ class Publisher { channel: channel, message: message })); - } + }; public publishInternalEvent = (type: K, value?: InternalStreamTypes[K]): void => { this.publish('internal', type, typeof value === 'undefined' ? null : value); - } + }; public publishUserEvent = (userId: User['id'], type: K, value?: UserStreamTypes[K]): void => { this.publish(`user:${userId}`, type, typeof value === 'undefined' ? null : value); - } + }; public publishBroadcastStream = (type: K, value?: BroadcastTypes[K]): void => { this.publish('broadcast', type, typeof value === 'undefined' ? null : value); - } + }; public publishMainStream = (userId: User['id'], type: K, value?: MainStreamTypes[K]): void => { this.publish(`mainStream:${userId}`, type, typeof value === 'undefined' ? null : value); - } + }; public publishDriveStream = (userId: User['id'], type: K, value?: DriveStreamTypes[K]): void => { this.publish(`driveStream:${userId}`, type, typeof value === 'undefined' ? null : value); - } + }; public publishNoteStream = (noteId: Note['id'], type: K, value?: NoteStreamTypes[K]): void => { this.publish(`noteStream:${noteId}`, type, { id: noteId, body: value }); - } + }; public publishChannelStream = (channelId: Channel['id'], type: K, value?: ChannelStreamTypes[K]): void => { this.publish(`channelStream:${channelId}`, type, typeof value === 'undefined' ? null : value); - } + }; public publishUserListStream = (listId: UserList['id'], type: K, value?: UserListStreamTypes[K]): void => { this.publish(`userListStream:${listId}`, type, typeof value === 'undefined' ? null : value); - } + }; public publishAntennaStream = (antennaId: Antenna['id'], type: K, value?: AntennaStreamTypes[K]): void => { this.publish(`antennaStream:${antennaId}`, type, typeof value === 'undefined' ? null : value); - } + }; public publishMessagingStream = (userId: User['id'], otherpartyId: User['id'], type: K, value?: MessagingStreamTypes[K]): void => { this.publish(`messagingStream:${userId}-${otherpartyId}`, type, typeof value === 'undefined' ? null : value); - } + }; public publishGroupMessagingStream = (groupId: UserGroup['id'], type: K, value?: GroupMessagingStreamTypes[K]): void => { this.publish(`messagingStream:${groupId}`, type, typeof value === 'undefined' ? null : value); - } + }; public publishMessagingIndexStream = (userId: User['id'], type: K, value?: MessagingIndexStreamTypes[K]): void => { this.publish(`messagingIndexStream:${userId}`, type, typeof value === 'undefined' ? null : value); - } + }; public publishReversiStream = (userId: User['id'], type: K, value?: ReversiStreamTypes[K]): void => { this.publish(`reversiStream:${userId}`, type, typeof value === 'undefined' ? null : value); - } + }; public publishReversiGameStream = (gameId: ReversiGame['id'], type: K, value?: ReversiGameStreamTypes[K]): void => { this.publish(`reversiGameStream:${gameId}`, type, typeof value === 'undefined' ? null : value); - } + }; public publishNotesStream = (note: Packed<'Note'>): void => { this.publish('notesStream', null, note); - } + }; public publishAdminStream = (userId: User['id'], type: K, value?: AdminStreamTypes[K]): void => { this.publish(`adminStream:${userId}`, type, typeof value === 'undefined' ? null : value); - } + }; } const publisher = new Publisher();