From 3a3983d38d28f442b174d651fab746ab9c04f3a0 Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 1 Feb 2021 12:33:48 +0800 Subject: [PATCH] workspace: update eslint config --- .eslintignore | 3 +- .eslintrc.js | 59 ------------------------ .eslintrc.yaml | 55 ++++++++++++++++++++++ package.json | 10 ++-- packages/fps-importer/package.json | 4 +- packages/hydrojudge/package.json | 6 +-- packages/hydrojudge/src/compile.ts | 2 +- packages/hydrojudge/src/judge/index.ts | 2 +- packages/hydrojudge/src/log.ts | 36 +++++++-------- packages/hydrojudge/src/sysinfo.ts | 12 ++--- packages/hydrooj/package.json | 17 +++---- packages/hydrooj/src/entry/setup.ts | 2 - packages/hydrooj/src/interface.ts | 10 +++- packages/hydrooj/src/lib/download.ts | 2 +- packages/hydrooj/src/lib/sysinfo.ts | 12 ++--- packages/hydrooj/src/logger.ts | 28 +++++------ packages/hydrooj/src/model/document.ts | 10 ++-- packages/hydrooj/src/model/domain.ts | 4 +- packages/hydrooj/src/model/problem.ts | 2 +- packages/hydrooj/src/model/system.ts | 20 ++++---- packages/hydrooj/src/options.ts | 2 +- packages/hydrooj/src/script/blacklist.ts | 4 +- packages/hydrooj/src/script/rating.ts | 10 ++-- packages/hydrooj/src/service/bus.ts | 6 +-- packages/hydrooj/src/service/server.ts | 5 +- packages/hydrooj/src/typeutils.ts | 6 +-- packages/hydrooj/src/ui.ts | 2 +- packages/import-qduoj/package.json | 2 +- packages/migrate-vijos/package.json | 2 +- 29 files changed, 169 insertions(+), 166 deletions(-) delete mode 100644 .eslintrc.js create mode 100644 .eslintrc.yaml diff --git a/.eslintignore b/.eslintignore index b089d749..71bfd891 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,4 +2,5 @@ dist *.d.ts *.js test -tests \ No newline at end of file +tests +node_modules diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 3b25b3a0..00000000 --- a/.eslintrc.js +++ /dev/null @@ -1,59 +0,0 @@ -module.exports = { - root: true, - env: { - node: true, - }, - extends: [ - 'airbnb-base', - ], - globals: { - Atomics: 'readonly', - SharedArrayBuffer: 'readonly', - BigInt: true, - }, - parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint'], - rules: { - '@typescript-eslint/no-dupe-class-members': 'error', - '@typescript-eslint/no-unused-vars': 'error', - camelcase: 'off', - 'global-require': 'off', - 'guard-for-in': 'off', - 'implicit-arrow-linebreak': 'off', - 'import/extensions': 'off', - 'import/no-cycle': 'off', - 'import/no-extraneous-dependencies': 'off', - 'import/no-named-as-default': 'off', - 'import/no-named-as-default-member': 'off', - 'import/prefer-default-export': 'off', - indent: ['warn', 4], - 'lines-between-class-members': ['error', 'always', { 'exceptAfterSingleLine': true }], - 'max-classes-per-file': 'off', - 'max-len': ['warn', 150], - 'no-bitwise': 'off', - 'no-console': 'off', - 'no-continue': 'off', - 'no-dupe-class-members': 'off', - 'no-extend-native': 'off', - 'no-inner-declarations': 'off', - 'no-multi-assign': 'off', - 'no-nested-ternary': 'off', - 'no-param-reassign': 'off', - 'no-plusplus': 'off', - 'no-restricted-syntax': 'off', - 'no-return-await': 'off', - 'no-underscore-dangle': 'off', - 'no-unused-vars': 'off', - 'prefer-destructuring': 'off', - }, - settings: { - 'import/parsers': { - '@typescript-eslint/parser': ['.ts'], - }, - 'import/resolver': { - typescript: { - alwaysTryTypes: true, - }, - }, - }, -}; diff --git a/.eslintrc.yaml b/.eslintrc.yaml new file mode 100644 index 00000000..9a47450b --- /dev/null +++ b/.eslintrc.yaml @@ -0,0 +1,55 @@ +root: true +extends: + - airbnb-typescript/base +globals: + Atomics: readonly + SharedArrayBuffer: readonly + BigInt: readonly +parser: '@typescript-eslint/parser' +plugins: + - '@typescript-eslint' +rules: + '@typescript-eslint/dot-notation': off + '@typescript-eslint/no-implied-eval': off + '@typescript-eslint/no-throw-literal': off + + '@typescript-eslint/indent': + - warn + - 4 + '@typescript-eslint/lines-between-class-members': + - error + - always + - exceptAfterSingleLine: true + '@typescript-eslint/naming-convention': off + '@typescript-eslint/no-redeclare': off + + global-require: off + guard-for-in: off + implicit-arrow-linebreak: off + import/no-cycle: off + import/no-extraneous-dependencies: off + import/no-named-as-default: off + import/prefer-default-export: off + max-classes-per-file: off + max-len: + - warn + - 150 + no-bitwise: off + no-console: off + no-continue: off + no-extend-native: off + no-multi-assign: off + no-nested-ternary: off + no-param-reassign: off + no-plusplus: off + no-restricted-syntax: off + no-return-await: off + no-underscore-dangle: off + prefer-destructuring: off +settings: + import/parsers: + '@typescript-eslint/parser': + - .ts + import/resolver: + typescript: + alwaysTryTypes: true diff --git a/package.json b/package.json index 44f658b1..dd897429 100644 --- a/package.json +++ b/package.json @@ -23,11 +23,11 @@ "@types/jest": "^26.0.20", "@types/node": "^14.14.22", "@types/semver": "^7.3.4", - "@typescript-eslint/eslint-plugin": "^3.9.1", - "@typescript-eslint/parser": "^3.9.1", + "@typescript-eslint/eslint-plugin": "^4.14.1", + "@typescript-eslint/parser": "^4.14.1", "cross-spawn": "^7.0.3", - "eslint": "^7.18.0", - "eslint-config-airbnb-base": "^14.2.1", + "eslint": "^7.19.0", + "eslint-config-airbnb-typescript": "^12.0.0", "eslint-import-resolver-typescript": "^2.3.0", "eslint-plugin-import": "^2.22.1", "globby": "^11.0.2", @@ -35,7 +35,7 @@ "latest-version": "^5.1.0", "ora": "^5.3.0", "semver": "^7.3.4", - "ts-jest": "^26.4.4", + "ts-jest": "^26.5.0", "typescript": "4.1.3" }, "dependencies": { diff --git a/packages/fps-importer/package.json b/packages/fps-importer/package.json index f164a6bd..11b593a5 100644 --- a/packages/fps-importer/package.json +++ b/packages/fps-importer/package.json @@ -7,13 +7,13 @@ "author": "undefined ", "license": "AGPL-3.0-only", "dependencies": { - "adm-zip": "^0.5.1", + "adm-zip": "^0.5.2", "decode-html": "^2.0.0", "fs-extra": "^9.1.0", "xml2js": "^0.4.23" }, "devDependencies": { - "@types/xml2js": "^0.4.7", + "@types/xml2js": "^0.4.8", "bson": "^4.2.2" }, "peerDependencies": { diff --git a/packages/hydrojudge/package.json b/packages/hydrojudge/package.json index 3a98a066..b7e6d29a 100644 --- a/packages/hydrojudge/package.json +++ b/packages/hydrojudge/package.json @@ -1,12 +1,12 @@ { "name": "@hydrooj/hydrojudge", "bin": "bin/hydrojudge.js", - "version": "2.3.2", + "version": "2.3.3", "main": "package.json", "author": "undefined ", "repository": "https://github.com/hydro-dev/Hydro.git", "dependencies": { - "adm-zip": "^0.5.1", + "adm-zip": "^0.5.2", "axios": "^0.21.1", "bson": "^4.2.2", "fs-extra": "^9.1.0", @@ -14,7 +14,7 @@ "lodash": "^4.17.20", "p-queue": "^6.6.1", "shell-quote": "^1.7.2", - "systeminformation": "^4.34.9", + "systeminformation": "^5.0.8", "yargs": "^16.2.0" }, "peerDependencies": { diff --git a/packages/hydrojudge/src/compile.ts b/packages/hydrojudge/src/compile.ts index 48a53088..ea2d644f 100644 --- a/packages/hydrojudge/src/compile.ts +++ b/packages/hydrojudge/src/compile.ts @@ -36,4 +36,4 @@ export = async function compile( }; } throw new SystemError('Unknown language type.'); -} +}; diff --git a/packages/hydrojudge/src/judge/index.ts b/packages/hydrojudge/src/judge/index.ts index 0429e235..300a697d 100644 --- a/packages/hydrojudge/src/judge/index.ts +++ b/packages/hydrojudge/src/judge/index.ts @@ -6,4 +6,4 @@ import * as hack from './hack'; export = { default: def, interactive, run, submit_answer, hack, -} +}; diff --git a/packages/hydrojudge/src/log.ts b/packages/hydrojudge/src/log.ts index c194cf24..6782ae41 100644 --- a/packages/hydrojudge/src/log.ts +++ b/packages/hydrojudge/src/log.ts @@ -31,39 +31,39 @@ const colors = [ ]; const instances: Record = {}; -type LogFunction = (format: any, ...param: any[]) => void -type LogType = 'success' | 'error' | 'info' | 'warn' | 'debug' +type LogFunction = (format: any, ...param: any[]) => void; +type LogType = 'success' | 'error' | 'info' | 'warn' | 'debug'; export interface Logger extends Record { } export class Logger { - static readonly SUCCESS = 1 - static readonly ERROR = 1 - static readonly INFO = 2 - static readonly WARN = 2 - static readonly DEBUG = 3 - static baseLevel = argv.debug ? 3 : 2 - static showDiff = false - static levels: Record = {} - static lastTime = 0 + static readonly SUCCESS = 1; + static readonly ERROR = 1; + static readonly INFO = 2; + static readonly WARN = 2; + static readonly DEBUG = 3; + static baseLevel = argv.debug ? 3 : 2; + static showDiff = false; + static levels: Record = {}; + static lastTime = 0; static options: InspectOptions = { colors: process.stderr.isTTY, - } + }; static formatters: Record string> = { c: Logger.prototype.color, C: (value) => Logger.color(15, value, ';1'), o: (value) => inspect(value, Logger.options).replace(/\s*\n\s*/g, ' '), - } + }; static color(code: number, value: any, decoration = '') { if (!Logger.options.colors) return `${value}`; return `\u001B[3${code < 8 ? code : `8;5;${code}`}${decoration}m${value}\u001B[0m`; } - private code: number - private displayName: string - public stream: NodeJS.WritableStream = process.stderr + private code: number; + private displayName: string; + public stream: NodeJS.WritableStream = process.stderr; constructor(public name: string, private showDiff = false) { if (name in instances) return instances[name]; @@ -97,7 +97,7 @@ export class Logger { return Logger.levels[this.name] ?? Logger.baseLevel; } - extend = (namespace: string, showDiff = this.showDiff) => new Logger(`${this.name}:${namespace}`, showDiff) + extend = (namespace: string, showDiff = this.showDiff) => new Logger(`${this.name}:${namespace}`, showDiff); format: (format: any, ...param: any[]) => string = (...args) => { if (args[0] instanceof Error) args[0] = args[0].stack || args[0].message; @@ -122,7 +122,7 @@ export class Logger { Logger.lastTime = now; } return format(...args); - } + }; } export default new Logger('judge'); diff --git a/packages/hydrojudge/src/sysinfo.ts b/packages/hydrojudge/src/sysinfo.ts index b75bedf0..bb68590b 100644 --- a/packages/hydrojudge/src/sysinfo.ts +++ b/packages/hydrojudge/src/sysinfo.ts @@ -78,11 +78,11 @@ export async function get() { const cpu = `${Cpu.manufacturer} ${Cpu.brand}`; const memory = `${size(Memory.active)}/${size(Memory.total)}`; const osinfo = `${OsInfo.distro} ${OsInfo.release} ${OsInfo.codename} ${OsInfo.kernel} ${OsInfo.arch}`; - const load = `${CurrentLoad.avgload}`; + const load = `${CurrentLoad.avgLoad}`; const flags = CpuFlags; let battery; - if (!Battery.hasbattery) battery = 'No battery'; - else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.ischarging ? ' Charging' : ''}`; + if (!Battery.hasBattery) battery = 'No battery'; + else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.isCharging ? ' Charging' : ''}`; const mid = OsInfo.serial; cache.cpu = cpu; cache.osinfo = osinfo; @@ -114,10 +114,10 @@ export async function update() { mid, cpu, osinfo, flags, stack, } = cache; const memory = `${size(Memory.active)}/${size(Memory.total)}`; - const load = `${CurrentLoad.avgload}`; + const load = `${CurrentLoad.avgLoad}`; let battery; - if (!Battery.hasbattery) battery = 'No battery'; - else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.ischarging ? ' Charging' : ''}`; + if (!Battery.hasBattery) battery = 'No battery'; + else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.isCharging ? ' Charging' : ''}`; const reqCount = global.reqCount; global.reqCount = 0; return [ diff --git a/packages/hydrooj/package.json b/packages/hydrooj/package.json index 2bb91669..38d7b95a 100644 --- a/packages/hydrooj/package.json +++ b/packages/hydrooj/package.json @@ -1,6 +1,6 @@ { "name": "hydrooj", - "version": "2.17.6", + "version": "2.17.7", "bin": "bin/hydrooj.js", "main": "dist/loader.js", "typings": "dist/loader.d.ts", @@ -11,8 +11,8 @@ "node": ">=10.10" }, "dependencies": { - "adm-zip": "^0.5.1", - "ansi_up": "^4.0.4", + "adm-zip": "^0.5.2", + "ansi_up": "^5.0.0", "cookies": "^0.8.0", "detect-browser": "^5.1.1", "fs-extra": "^9.1.0", @@ -32,27 +32,28 @@ "serialize-javascript": "^5.0.1", "sockjs": "^0.3.20", "superagent": "^6.1.0", - "systeminformation": "^4.34.9", - "terminal-kit": "^1.45.8", + "systeminformation": "^5.0.8", + "terminal-kit": "^1.45.9", "yargs": "^16.2.0" }, "devDependencies": { "@types/adm-zip": "^0.4.33", "@types/fs-extra": "^9.0.6", "@types/js-yaml": "^4.0.0", - "@types/koa": "^2.11.4", + "@types/koa": "^2.11.7", "@types/koa-router": "^7.4.1", "@types/koa-static-cache": "^5.1.0", "@types/lodash": "^4.14.168", "@types/lru-cache": "^5.1.0", "@types/minio": "^7.0.7", - "@types/mongodb": "^3.5.33", + "@types/mongodb": "^3.6.3", "@types/nodemailer": "^6.4.0", "@types/serialize-javascript": "^5.0.0", "@types/sockjs": "^0.3.32", "@types/superagent": "^4.1.8", "@types/terminal-kit": "^1.28.2", - "@types/yargs": "^15.0.12" + "@types/yargs": "^16.0.0", + "formidable": "^1.2.2" }, "scripts": { "build": "tsc", diff --git a/packages/hydrooj/src/entry/setup.ts b/packages/hydrooj/src/entry/setup.ts index 89b31307..b71ed4b3 100644 --- a/packages/hydrooj/src/entry/setup.ts +++ b/packages/hydrooj/src/entry/setup.ts @@ -10,7 +10,6 @@ import { argv } from 'yargs'; import { Logger } from '../logger'; const logger = new Logger('setup'); - const listenPort = argv.port || 8888; async function get(ctx: Context) { @@ -81,7 +80,6 @@ async function get(ctx: Context) { async function post(ctx: Context) { const { host, port, name, username, password, - // @ts-ignore } = ctx.request.body; let mongourl = 'mongodb://'; if (username) mongourl += `${username}:${password}@`; diff --git a/packages/hydrooj/src/interface.ts b/packages/hydrooj/src/interface.ts index a8427eca..eacfff31 100644 --- a/packages/hydrooj/src/interface.ts +++ b/packages/hydrooj/src/interface.ts @@ -2,6 +2,7 @@ import type { Readable, Writable } from 'stream'; import type { ObjectID } from 'mongodb'; import type fs from 'fs'; import type { Dictionary, NumericDictionary } from 'lodash'; +import type * as Koa from 'koa'; import type { Pdoc } from './model/problem'; type document = typeof import('./model/document'); @@ -159,7 +160,7 @@ export interface SampleContentNode { payload: [string, string], } export type ContentNode = PlainContentNode | TextContentNode | SampleContentNode; -export type Content = string | ContentNode[] | Record +export type Content = string | ContentNode[] | Record; declare module './model/problem' { interface Pdoc { @@ -589,3 +590,10 @@ declare global { } } } + +declare module 'koa' { + interface Request extends Koa.BaseRequest { + body?: any; + files?: import('formidable').Files; + } +} diff --git a/packages/hydrooj/src/lib/download.ts b/packages/hydrooj/src/lib/download.ts index 76575bc2..37ca2775 100644 --- a/packages/hydrooj/src/lib/download.ts +++ b/packages/hydrooj/src/lib/download.ts @@ -11,7 +11,7 @@ async function _download(url: string, path: string, retry: number) { return path; } -function download(url: string): SuperAgentRequest +function download(url: string): SuperAgentRequest; function download(url: string, path?: string, retry = 3) { if (path) return _download(url, path, retry); return superagent.get(url).retry(retry); diff --git a/packages/hydrooj/src/lib/sysinfo.ts b/packages/hydrooj/src/lib/sysinfo.ts index 77d71464..fd8b4e1c 100644 --- a/packages/hydrooj/src/lib/sysinfo.ts +++ b/packages/hydrooj/src/lib/sysinfo.ts @@ -18,11 +18,11 @@ export async function get() { const cpu = `${Cpu.manufacturer} ${Cpu.brand}`; const memory = `${size(Memory.active)}/${size(Memory.total)}`; const osinfo = `${OsInfo.distro} ${OsInfo.release} ${OsInfo.codename} ${OsInfo.kernel} ${OsInfo.arch}`; - const load = `${CurrentLoad.avgload}`; + const load = `${CurrentLoad.avgLoad}`; const flags = CpuFlags; let battery; - if (!Battery.hasbattery) battery = 'No battery'; - else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.ischarging ? ' Charging' : ''}`; + if (!Battery.hasBattery) battery = 'No battery'; + else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.isCharging ? ' Charging' : ''}`; const mid = OsInfo.serial; cache.cpu = cpu; cache.osinfo = osinfo; @@ -44,10 +44,10 @@ export async function update(): Promise<[string, any, any]> { mid, cpu, osinfo, flags, } = cache; const memory = `${size(Memory.active)}/${size(Memory.total)}`; - const load = `${CurrentLoad.avgload}`; + const load = `${CurrentLoad.avgLoad}`; let battery; - if (!Battery.hasbattery) battery = 'No battery'; - else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.ischarging ? ' Charging' : ''}`; + if (!Battery.hasBattery) battery = 'No battery'; + else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.isCharging ? ' Charging' : ''}`; return [ mid, { diff --git a/packages/hydrooj/src/logger.ts b/packages/hydrooj/src/logger.ts index 0448056c..9d23c805 100644 --- a/packages/hydrooj/src/logger.ts +++ b/packages/hydrooj/src/logger.ts @@ -3,22 +3,22 @@ import { argv } from 'yargs'; import { Time } from './utils'; const instances: Record = {}; -type LogFunction = (format: any, ...param: any[]) => void -type LogType = 'success' | 'error' | 'info' | 'warn' | 'debug' +type LogFunction = (format: any, ...param: any[]) => void; +type LogType = 'success' | 'error' | 'info' | 'warn' | 'debug'; export interface Logger extends Record { } export class Logger { - static readonly SUCCESS = 1 - static readonly ERROR = 1 - static readonly INFO = 2 - static readonly WARN = 2 - static readonly DEBUG = 3 - static baseLevel = argv.debug ? 3 : 2 - static showDiff = false - static levels: Record = {} - static lastTime = 0 + static readonly SUCCESS = 1; + static readonly ERROR = 1; + static readonly INFO = 2; + static readonly WARN = 2; + static readonly DEBUG = 3; + static baseLevel = argv.debug ? 3 : 2; + static showDiff = false; + static levels: Record = {}; + static lastTime = 0; static formatters: Record string> = { o: (value) => inspect(value).replace(/\s*\n\s*/g, ' '), - } + }; constructor(public name: string, private showDiff = false) { if (name in instances) return instances[name]; @@ -48,7 +48,7 @@ export class Logger { return Logger.levels[this.name] ?? Logger.baseLevel; } - extend = (namespace: string, showDiff = this.showDiff) => new Logger(`${this.name}:${namespace}`, showDiff) + extend = (namespace: string, showDiff = this.showDiff) => new Logger(`${this.name}:${namespace}`, showDiff); format: (format: any, ...param: any[]) => string = (...args) => { if (args[0] instanceof Error) args[0] = args[0].stack || args[0].message; @@ -71,7 +71,7 @@ export class Logger { Logger.lastTime = now; } return format(...args); - } + }; } global.Hydro.Logger = Logger; diff --git a/packages/hydrooj/src/model/document.ts b/packages/hydrooj/src/model/document.ts index 0b4b20f0..dde86f35 100644 --- a/packages/hydrooj/src/model/document.ts +++ b/packages/hydrooj/src/model/document.ts @@ -49,13 +49,13 @@ export async function add, -): Promise +): Promise; export async function add( domainId: string, content: Content, owner: number, docType: T, docId: null, parentType?: DocType[T]['parentType'], parentId?: DocType[T]['parentId'], args?: Partial, -): Promise +): Promise; export async function add( domainId: string, content: Content, owner: number, docType: number, docId: DocID = null, @@ -164,14 +164,14 @@ export function count( return coll.find({ ...query, docType, domainId }).count(); } -export async function push( +export async function push( domainId: string, docType: K, docId: DocType[K]['docId'], key: ArrayKeys, value: DocType[K][0], -): Promise<[DocType[K], ObjectID]> +): Promise<[DocType[K], ObjectID]>; export async function push( domainId: string, docType: K, docId: DocType[K]['docId'], key: keyof DocType[K], content: string, owner: number, args?: DocType[K][T][0], -): Promise<[DocType[K], ObjectID]> +): Promise<[DocType[K], ObjectID]>; export async function push( domainId: string, docType: number, docId: DocID, key: string, arg0: any, arg1?: any, arg2?: any, diff --git a/packages/hydrooj/src/model/domain.ts b/packages/hydrooj/src/model/domain.ts index 023ca170..977654ba 100644 --- a/packages/hydrooj/src/model/domain.ts +++ b/packages/hydrooj/src/model/domain.ts @@ -95,8 +95,8 @@ export function setUserRole(domainId: string, uid: number, role: string) { return collUser.updateOne({ uid, domainId }, { $set: { role } }, { upsert: true }); } -export async function getRoles(domainId: string): Promise -export async function getRoles(domain: DomainDoc): Promise +export async function getRoles(domainId: string): Promise; +export async function getRoles(domain: DomainDoc): Promise; export async function getRoles(arg: string | DomainDoc) { let ddoc: DomainDoc; if (typeof arg === 'string') ddoc = await get(arg); diff --git a/packages/hydrooj/src/model/problem.ts b/packages/hydrooj/src/model/problem.ts index 203f537a..a72c9a90 100644 --- a/packages/hydrooj/src/model/problem.ts +++ b/packages/hydrooj/src/model/problem.ts @@ -17,7 +17,7 @@ export interface Pdoc { export namespace Pdoc { export type Field = keyof Pdoc; export const fields: Field[] = []; - type Getter = (docId?: number, pid?: string) => Partial + type Getter = (docId?: number, pid?: string) => Partial; const getters: Getter[] = []; export function extend(getter: Getter) { getters.push(getter); diff --git a/packages/hydrooj/src/model/system.ts b/packages/hydrooj/src/model/system.ts index 3f5b7d76..077b8eab 100644 --- a/packages/hydrooj/src/model/system.ts +++ b/packages/hydrooj/src/model/system.ts @@ -7,37 +7,37 @@ import * as bus from '../service/bus'; const coll = db.collection('system'); const cache: Record = {}; -export function get(key: K): SystemKeys[K] -export function get(key: string): any +export function get(key: K): SystemKeys[K]; +export function get(key: string): any; export function get(key: string): any { return cache[key]; } export function getMany< A extends keyof SystemKeys, B extends keyof SystemKeys, - >(keys: [A, B]): [SystemKeys[A], SystemKeys[B]] +>(keys: [A, B]): [SystemKeys[A], SystemKeys[B]]; export function getMany< A extends keyof SystemKeys, B extends keyof SystemKeys, C extends keyof SystemKeys, - >(keys: [A, B, C]): [SystemKeys[A], SystemKeys[B], SystemKeys[C]] +>(keys: [A, B, C]): [SystemKeys[A], SystemKeys[B], SystemKeys[C]]; export function getMany< A extends keyof SystemKeys, B extends keyof SystemKeys, C extends keyof SystemKeys, D extends keyof SystemKeys, - >(keys: [A, B, C, D]): [SystemKeys[A], SystemKeys[B], SystemKeys[C], SystemKeys[D]] +>(keys: [A, B, C, D]): [SystemKeys[A], SystemKeys[B], SystemKeys[C], SystemKeys[D]]; export function getMany< A extends keyof SystemKeys, B extends keyof SystemKeys, C extends keyof SystemKeys, D extends keyof SystemKeys, E extends keyof SystemKeys, - >(keys: [A, B, C, D, E]): [SystemKeys[A], SystemKeys[B], SystemKeys[C], SystemKeys[D], SystemKeys[E]] +>(keys: [A, B, C, D, E]): [SystemKeys[A], SystemKeys[B], SystemKeys[C], SystemKeys[D], SystemKeys[E]]; export function getMany< A extends keyof SystemKeys, B extends keyof SystemKeys, C extends keyof SystemKeys, D extends keyof SystemKeys, E extends keyof SystemKeys, F extends keyof SystemKeys, - >(keys: [A, B, C, D, E, F]): [SystemKeys[A], SystemKeys[B], SystemKeys[C], SystemKeys[D], SystemKeys[E], SystemKeys[F]] -export function getMany(keys: (keyof SystemKeys)[]): any[] +>(keys: [A, B, C, D, E, F]): [SystemKeys[A], SystemKeys[B], SystemKeys[C], SystemKeys[D], SystemKeys[E], SystemKeys[F]]; +export function getMany(keys: (keyof SystemKeys)[]): any[]; export function getMany(keys: string[]): any[] { return keys.map((key) => cache[key]); } -export async function set(_id: K, value: SystemKeys[K], boardcast?: boolean): Promise -export async function set(_id: string, value: K, boardcast?: boolean): Promise +export async function set(_id: K, value: SystemKeys[K], boardcast?: boolean): Promise; +export async function set(_id: string, value: K, boardcast?: boolean): Promise; export async function set(_id: string, value: any, boardcast = true) { if (boardcast) bus.boardcast('system/setting', { [_id]: value }); const res = await coll.findOneAndUpdate( diff --git a/packages/hydrooj/src/options.ts b/packages/hydrooj/src/options.ts index 19feaa4f..80f71fe4 100644 --- a/packages/hydrooj/src/options.ts +++ b/packages/hydrooj/src/options.ts @@ -28,4 +28,4 @@ export = function load() { result = {}; } return result; -} +}; diff --git a/packages/hydrooj/src/script/blacklist.ts b/packages/hydrooj/src/script/blacklist.ts index f9b53dae..d6ef7a34 100644 --- a/packages/hydrooj/src/script/blacklist.ts +++ b/packages/hydrooj/src/script/blacklist.ts @@ -1,4 +1,4 @@ -/* eslint-disable no-use-before-define */ +/* eslint-disable @typescript-eslint/no-use-before-define */ import { ObjectID } from 'mongodb'; import * as document from '../model/document'; import * as discussion from '../model/discussion'; @@ -62,7 +62,7 @@ async function _user( } export async function run({ - // eslint-disable-next-line no-shadow + // eslint-disable-next-line @typescript-eslint/no-shadow address = null, discuss = null, user = null, dryrun = true, }, report) { if (address) await _address(address, new Set(), new Set(), new Set(), dryrun, report); diff --git a/packages/hydrooj/src/script/rating.ts b/packages/hydrooj/src/script/rating.ts index f2147e2f..cfca5131 100644 --- a/packages/hydrooj/src/script/rating.ts +++ b/packages/hydrooj/src/script/rating.ts @@ -12,10 +12,10 @@ import paginate from '../lib/paginate'; export const description = 'Calculate rp of a domain, or all domains'; -type ND = NumericDictionary +type ND = NumericDictionary; -async function runProblem(pdoc: Pdoc, udict: ND): Promise -async function runProblem(domainId: string, pid: number, udict: ND): Promise +async function runProblem(pdoc: Pdoc, udict: ND): Promise; +async function runProblem(domainId: string, pid: number, udict: ND): Promise; async function runProblem(...arg: any[]) { const pdoc: Pdoc = (typeof arg[0] === 'string') ? await problem.get(arg[0], arg[1], -1) @@ -50,10 +50,10 @@ async function runProblem(...arg: any[]) { } } -async function runContest(tdoc: Tdoc, udict: ND, report: Function): Promise +async function runContest(tdoc: Tdoc, udict: ND, report: Function): Promise; async function runContest( domainId: string, tid: ObjectID, udict: ND, report: Function -): Promise +): Promise; async function runContest(...arg: any[]) { const start = new Date().getTime(); const tdoc: Tdoc = (typeof arg[0] === 'string') diff --git a/packages/hydrooj/src/service/bus.ts b/packages/hydrooj/src/service/bus.ts index ce06437c..0a632d84 100644 --- a/packages/hydrooj/src/service/bus.ts +++ b/packages/hydrooj/src/service/bus.ts @@ -16,8 +16,8 @@ function isBailed(value: any) { return value !== null && value !== false && value !== undefined; } -export type Disposable = () => void -export type VoidReturn = Promise | any +export type Disposable = () => void; +export type VoidReturn = Promise | any; export interface EventMap { 'app/started': () => void @@ -53,7 +53,7 @@ export interface EventMap { 'document/add': (doc: any) => VoidReturn 'document/set': - (domainId: string, docType: T, docId: DocType[T], $set: any, $unset: OnlyFieldsOfType) => VoidReturn + (domainId: string, docType: T, docId: DocType[T], $set: any, $unset: OnlyFieldsOfType) => VoidReturn 'problem/edit': (doc: Pdoc) => VoidReturn 'problem/list': (query: FilterQuery, handler: any) => VoidReturn diff --git a/packages/hydrooj/src/service/server.ts b/packages/hydrooj/src/service/server.ts index ae36efa6..3c242e31 100644 --- a/packages/hydrooj/src/service/server.ts +++ b/packages/hydrooj/src/service/server.ts @@ -1,4 +1,3 @@ -/* eslint-disable prefer-destructuring */ import assert from 'assert'; import { PassThrough } from 'stream'; import { resolve } from 'path'; @@ -199,7 +198,7 @@ type DescriptorBuilder = & ((name: string, type: Type, validate: null, convert: Converter) => MethodDecorator) & ((name: string, type: Type, validate?: Validator, convert?: Converter) => MethodDecorator) & ((name: string, type?: Type, isOptional?: boolean, validate?: Validator, convert?: Converter) => MethodDecorator) - & ((name: string, ...args: Array) => MethodDecorator) + & ((name: string, ...args: Array) => MethodDecorator); export const get: DescriptorBuilder = (name, ...args) => _descriptor(_buildParam(name, 'get', ...args)); export const post: DescriptorBuilder = (name, ...args) => _descriptor(_buildParam(name, 'post', ...args)); @@ -663,7 +662,7 @@ export class ConnectionHandler extends HandlerCommon { params: Record; headers: Record; ip: string; - } + }; constructor(conn: sockjs.Connection) { super(); diff --git a/packages/hydrooj/src/typeutils.ts b/packages/hydrooj/src/typeutils.ts index e69e0b55..5cb167e1 100644 --- a/packages/hydrooj/src/typeutils.ts +++ b/packages/hydrooj/src/typeutils.ts @@ -4,10 +4,10 @@ export type NumberKeys = { export type ArrayKeys = { [K in keyof O]: P[] extends O[K] ? K : never -}[keyof O] +}[keyof O]; export type Value = { [K in keyof O]: V -} +}; -export type Projection = (string & keyof O)[] +export type Projection = (string & keyof O)[]; diff --git a/packages/hydrooj/src/ui.ts b/packages/hydrooj/src/ui.ts index cbd57086..c1fc8189 100644 --- a/packages/hydrooj/src/ui.ts +++ b/packages/hydrooj/src/ui.ts @@ -1,4 +1,4 @@ -/* eslint-disable no-shadow */ +/* eslint-disable @typescript-eslint/no-shadow */ // @ts-nocheck import cluster from 'cluster'; import { diff --git a/packages/import-qduoj/package.json b/packages/import-qduoj/package.json index 102f6d9a..845d4998 100644 --- a/packages/import-qduoj/package.json +++ b/packages/import-qduoj/package.json @@ -7,7 +7,7 @@ "author": "undefined ", "license": "AGPL-3.0-only", "dependencies": { - "adm-zip": "^0.5.1", + "adm-zip": "^0.5.2", "decode-html": "^2.0.0", "fs-extra": "^9.1.0" }, diff --git a/packages/migrate-vijos/package.json b/packages/migrate-vijos/package.json index ad4a40e3..de3b6edf 100644 --- a/packages/migrate-vijos/package.json +++ b/packages/migrate-vijos/package.json @@ -11,7 +11,7 @@ }, "devDependencies": { "@types/js-yaml": "^4.0.0", - "@types/mongodb": "^3.5.33" + "@types/mongodb": "^3.6.3" }, "peerDependencies": { "hydrooj": "2.14.x"