fix lint errors

This commit is contained in:
syuilo 2021-11-12 10:52:10 +09:00
parent 84df0714d8
commit b9eaf906e7
22 changed files with 55 additions and 49 deletions

View file

@ -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'],

View file

@ -171,7 +171,7 @@ declare module 'jsrsasign' {
public static getTLVbyList(h: ASN1S, currentIndex: Idx<ASN1ObjectString>, nthList: Mutable<Nth[]>, checkingTag?: string): ASN1TLV;
// tslint:disable-next-line:bool-param-default
// eslint:disable-next-line:bool-param-default
public static getVbyList(h: ASN1S, currentIndex: Idx<ASN1ObjectString>, nthList: Mutable<Nth[]>, checkingTag?: string, removeUnusedbits?: boolean): ASN1V;
public static hextooidstr(hex: ASN1OIDV): OID;

View file

@ -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':
{

View file

@ -1,5 +1,6 @@
import { Context } from 'cafy';
// eslint-disable-next-line @typescript-eslint/ban-types
export class ID<Maybe = string> extends Context<string | (Maybe extends {} ? string : Maybe)> {
public readonly name = 'ID';

View file

@ -56,7 +56,7 @@ export function genAvatar(seed: string, stream: WriteStream): Promise<void> {
// 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;

View file

@ -87,7 +87,7 @@ export function groupOn<T, S>(f: (x: T) => S, xs: T[]): T[][] {
export function groupByX<T>(collections: T[], keySelector: (x: T) => string) {
return collections.reduce((obj: Record<string, T[]>, item: T) => {
const key = keySelector(item);
if (!obj.hasOwnProperty(key)) {
if (!Object.prototype.hasOwnProperty.call(obj, key)) {
obj[key] = [];
}

View file

@ -1,4 +1,4 @@
export function query(obj: {}): string {
export function query(obj: Record<string, unknown>): 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<string, any>);

View file

@ -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<void> {
export default async function cleanRemoteFiles(job: Bull.Job<Record<string, unknown>>, done: any): Promise<void> {
logger.info(`Deleting cached remote files...`);
let deletedCount = 0;

View file

@ -3,9 +3,9 @@ import { resyncCharts } from './resync-charts';
const jobs = {
resyncCharts,
} as Record<string, Bull.ProcessCallbackFunction<{}> | Bull.ProcessPromiseFunction<{}>>;
} as Record<string, Bull.ProcessCallbackFunction<Record<string, unknown>> | Bull.ProcessPromiseFunction<Record<string, unknown>>>;
export default function(dbQueue: Bull.Queue<{}>) {
export default function(dbQueue: Bull.Queue<Record<string, unknown>>) {
for (const [k, v] of Object.entries(jobs)) {
dbQueue.process(k, v);
}

View file

@ -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<void> {
export async function resyncCharts(job: Bull.Job<Record<string, unknown>>, done: any): Promise<void> {
logger.info(`Resync charts...`);
// TODO: ユーザーごとのチャートも更新する

View file

@ -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<Record<string, unknown>>('system');
export const deliverQueue = initializeQueue<DeliverJobData>('deliver', config.deliverJobPerSec || 128);
export const inboxQueue = initializeQueue<InboxJobData>('inbox', config.inboxJobPerSec || 16);
export const dbQueue = initializeQueue<DbJobData>('db');

View file

@ -33,7 +33,7 @@ export type DbUserImportJobData = {
fileId: DriveFile['id'];
};
export type ObjectStorageJobData = ObjectStorageFileJobData | {};
export type ObjectStorageJobData = ObjectStorageFileJobData | Record<string, unknown>;
export type ObjectStorageFileJobData = {
key: string;

View file

@ -274,7 +274,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
* @param resolver Resolver
* @param hint Hint of Person object (Personの場合Remote resolveをせずに更新に利用します)
*/
export async function updatePerson(uri: string, resolver?: Resolver | null, hint?: object): Promise<void> {
export async function updatePerson(uri: string, resolver?: Resolver | null, hint?: Record<string, unknown>): Promise<void> {
if (typeof uri !== 'string') throw new Error('uri is not string');
// URIがこのサーバーを指しているならスキップ

View file

@ -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<string, unknown>) {
const page: any = {
id,
type: 'OrderedCollection',

View file

@ -20,7 +20,7 @@ type SimpleUserInfo = {
};
type Params<T extends IEndpointMeta> = {
[P in keyof T['params']]: NonNullable<T['params']>[P]['transform'] extends Function
[P in keyof T['params']]: NonNullable<T['params']>[P]['transform'] extends () => any
? ReturnType<NonNullable<T['params']>[P]['transform']>
: NonNullable<T['params']>[P]['default'] extends null | number | string
? NonOptional<ReturnType<NonNullable<T['params']>[P]['validator']['get']>[0]>
@ -30,7 +30,7 @@ type Params<T extends IEndpointMeta> = {
export type Response = Record<string, any> | void;
type executor<T extends IEndpointMeta> =
(params: Params<T>, user: T['requireCredential'] extends true ? SimpleUserInfo : SimpleUserInfo | null, token: AccessToken | null, file?: any, cleanup?: Function) =>
(params: Params<T>, user: T['requireCredential'] extends true ? SimpleUserInfo : SimpleUserInfo | null, token: AccessToken | null, file?: any, cleanup?: () => any) =>
Promise<T['res'] extends undefined ? Response : SchemaType<NonNullable<T['res']>>>;
export default function <T extends IEndpointMeta>(meta: T, cb: executor<T>)
@ -74,7 +74,7 @@ function getParams<T extends IEndpointMeta>(defs: T, params: any): [Params<T>, 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;

View file

@ -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({

View file

@ -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');
}

View file

@ -10,16 +10,16 @@ const logger = new Logger('limiter');
export default (endpoint: IEndpoint, user: User) => new Promise<void>((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();

View file

@ -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;
}
}
}
}

View file

@ -31,7 +31,7 @@ export interface BroadcastTypes {
}
export interface UserStreamTypes {
terminate: {};
terminate: Record<string, unknown>;
followChannel: Channel;
unfollowChannel: Channel;
updateUserProfile: UserProfile;

View file

@ -70,7 +70,7 @@ export default abstract class Chart<T extends Record<string, any>> {
@autobind
private static convertSchemaToFlatColumnDefinitions(schema: SimpleSchema) {
const columns = {} as any;
const columns = {} as Record<string, unknown>;
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<T extends Record<string, any>> {
}
@autobind
private static convertFlattenColumnsToObject(x: Record<string, any>): Record<string, any> {
const obj = {} as any;
private static convertFlattenColumnsToObject(x: Record<string, unknown>): Record<string, unknown> {
const obj = {} as Record<string, unknown>;
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<T extends Record<string, any>> {
}
@autobind
private static convertObjectToFlattenColumns(x: Record<string, any>) {
private static convertObjectToFlattenColumns(x: Record<string, unknown>) {
const columns = {} as Record<string, number | unknown[]>;
const flatten = (x: Obj, path?: string) => {
for (const [k, v] of Object.entries(x)) {
@ -121,9 +121,9 @@ export default abstract class Chart<T extends Record<string, any>> {
}
@autobind
private static countUniqueFields(x: Record<string, any>) {
private static countUniqueFields(x: Record<string, unknown>) {
const exec = (x: Obj) => {
const res = {} as Record<string, any>;
const res = {} as Record<string, unknown>;
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<T extends Record<string, any>> {
@autobind
private static convertQuery(diff: Record<string, number | unknown[]>) {
const query: Record<string, Function> = {};
const query: Record<string, () => string> = {};
for (const [k, v] of Object.entries(diff)) {
if (typeof v === 'number') {
@ -337,7 +337,7 @@ export default abstract class Chart<T extends Record<string, any>> {
}
@autobind
public async save() {
public async save(): Promise<void> {
if (this.buffer.length === 0) {
logger.info(`${this.name}: Write skipped`);
return;

View file

@ -37,74 +37,74 @@ class Publisher {
channel: channel,
message: message
}));
}
};
public publishInternalEvent = <K extends keyof InternalStreamTypes>(type: K, value?: InternalStreamTypes[K]): void => {
this.publish('internal', type, typeof value === 'undefined' ? null : value);
}
};
public publishUserEvent = <K extends keyof UserStreamTypes>(userId: User['id'], type: K, value?: UserStreamTypes[K]): void => {
this.publish(`user:${userId}`, type, typeof value === 'undefined' ? null : value);
}
};
public publishBroadcastStream = <K extends keyof BroadcastTypes>(type: K, value?: BroadcastTypes[K]): void => {
this.publish('broadcast', type, typeof value === 'undefined' ? null : value);
}
};
public publishMainStream = <K extends keyof MainStreamTypes>(userId: User['id'], type: K, value?: MainStreamTypes[K]): void => {
this.publish(`mainStream:${userId}`, type, typeof value === 'undefined' ? null : value);
}
};
public publishDriveStream = <K extends keyof DriveStreamTypes>(userId: User['id'], type: K, value?: DriveStreamTypes[K]): void => {
this.publish(`driveStream:${userId}`, type, typeof value === 'undefined' ? null : value);
}
};
public publishNoteStream = <K extends keyof NoteStreamTypes>(noteId: Note['id'], type: K, value?: NoteStreamTypes[K]): void => {
this.publish(`noteStream:${noteId}`, type, {
id: noteId,
body: value
});
}
};
public publishChannelStream = <K extends keyof ChannelStreamTypes>(channelId: Channel['id'], type: K, value?: ChannelStreamTypes[K]): void => {
this.publish(`channelStream:${channelId}`, type, typeof value === 'undefined' ? null : value);
}
};
public publishUserListStream = <K extends keyof UserListStreamTypes>(listId: UserList['id'], type: K, value?: UserListStreamTypes[K]): void => {
this.publish(`userListStream:${listId}`, type, typeof value === 'undefined' ? null : value);
}
};
public publishAntennaStream = <K extends keyof AntennaStreamTypes>(antennaId: Antenna['id'], type: K, value?: AntennaStreamTypes[K]): void => {
this.publish(`antennaStream:${antennaId}`, type, typeof value === 'undefined' ? null : value);
}
};
public publishMessagingStream = <K extends keyof MessagingStreamTypes>(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 = <K extends keyof GroupMessagingStreamTypes>(groupId: UserGroup['id'], type: K, value?: GroupMessagingStreamTypes[K]): void => {
this.publish(`messagingStream:${groupId}`, type, typeof value === 'undefined' ? null : value);
}
};
public publishMessagingIndexStream = <K extends keyof MessagingIndexStreamTypes>(userId: User['id'], type: K, value?: MessagingIndexStreamTypes[K]): void => {
this.publish(`messagingIndexStream:${userId}`, type, typeof value === 'undefined' ? null : value);
}
};
public publishReversiStream = <K extends keyof ReversiStreamTypes>(userId: User['id'], type: K, value?: ReversiStreamTypes[K]): void => {
this.publish(`reversiStream:${userId}`, type, typeof value === 'undefined' ? null : value);
}
};
public publishReversiGameStream = <K extends keyof ReversiGameStreamTypes>(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 = <K extends keyof AdminStreamTypes>(userId: User['id'], type: K, value?: AdminStreamTypes[K]): void => {
this.publish(`adminStream:${userId}`, type, typeof value === 'undefined' ? null : value);
}
};
}
const publisher = new Publisher();