workspace: apply eslint edits

This commit is contained in:
undefined committed 2025-03-21 09:48:17 +08:00
1 parent 040f7d8863
commit 0e7f5fe635
63 files changed
+47 -96

No files matched your search

-1
View File
@@ -13,7 +13,6 @@ import { hydroPath } from '../options';
const logger = new Logger('install');
let yarnVersion = 0;
try {
// eslint-disable-next-line no-unsafe-optional-chaining
yarnVersion = +child.execSync('yarn --version', { cwd: os.tmpdir() }).toString().split('v').pop()!.split('.')[0];
} catch (e) {
// yarn 2 does not support global dir
-2
View File
@@ -1,5 +1,3 @@
/* eslint-disable import/no-dynamic-require */
/* eslint-disable no-await-in-loop */
import os from 'os';
import path from 'path';
import cac from 'cac';
-1
View File
@@ -1,6 +1,5 @@
/* eslint-disable import/no-dynamic-require */
/* eslint-disable no-await-in-loop */
/* eslint-disable no-eval */
import '../lib/index';
import os from 'os';
-1
View File
@@ -13,7 +13,6 @@ export async function load() {
console.error('{"url":"mongodb://localhost:27017/hydro"}');
process.exit(1);
}
// eslint-disable-next-line no-constant-condition
while (true) {
console.error('Please type your MongoDB connection string below:');
console.error('Example: mongodb://localhost:27017/hydro');
-2
View File
@@ -1,4 +1,3 @@
/* eslint-disable import/no-dynamic-require */
/* eslint-disable no-await-in-loop */
import os from 'os';
import path from 'path';
@@ -92,7 +91,6 @@ export async function apply(ctx: Context) {
}
for (const f of Object.values(global.addons)) {
const dir = path.join(f, 'public');
// eslint-disable-next-line no-await-in-loop
if (await fs.pathExists(dir)) await fs.copy(dir, path.join(os.homedir(), '.hydro/static'));
}
ctx.inject(['server'], async ({ server }) => {
-1
View File
@@ -324,7 +324,6 @@ export class ContestEditHandler extends Handler {
await ScheduleModel.deleteMany(task);
const operation = [];
if (Date.now() <= endAt.getTime() && autoHide) {
// eslint-disable-next-line no-await-in-loop
await Promise.all(pids.map((pid) => problem.edit(domainId, pid, { hidden: true })));
operation.push('unhide');
}
-1
View File
@@ -1,4 +1,3 @@
/* eslint-disable camelcase */
import { pick } from 'lodash';
import { lookup } from 'mime-types';
import { Context } from '../context';
-1
View File
@@ -142,7 +142,6 @@ export class ProblemMainHandler extends Handler {
}
const sort = this.queryContext.sort;
await this.ctx.parallel('problem/list', query, this, sort);
// eslint-disable-next-line prefer-const
let [pdocs, ppcount, pcount] = this.queryContext.fail
? [[], 0, 0]
: await this.paginate(
-1
View File
@@ -172,7 +172,6 @@ export interface Document {
}
declare module './model/problem' {
// eslint-disable-next-line @typescript-eslint/no-shadow
interface ProblemDoc {
docType: document['TYPE_PROBLEM'];
docId: number;
-3
View File
@@ -1,8 +1,6 @@
/* eslint-disable import/no-dynamic-require */
/* eslint-disable consistent-return */
/* eslint-disable simple-import-sort/imports */
/* eslint-disable no-await-in-loop */
/* eslint-disable no-eval */
import './init';
import './interface';
import path from 'path';
@@ -156,7 +154,6 @@ async function preload() {
try {
// Is a npm package
const packagejson = require.resolve(`${a}/package.json`);
// eslint-disable-next-line import/no-dynamic-require
const payload = require(packagejson);
const name = payload.name.startsWith('@hydrooj/') ? payload.name.split('@hydrooj/')[1] : payload.name;
global.Hydro.version[name] = payload.version;
+4 -6
View File
@@ -91,7 +91,6 @@ const acm = buildContestRule({
submitAfterAccept: false,
showScoreboard: (tdoc, now) => now > tdoc.beginAt,
showSelfRecord: () => true,
// eslint-disable-next-line @typescript-eslint/no-use-before-define
showRecord: (tdoc, now) => now > tdoc.endAt && !isLocked(tdoc),
stat(tdoc, journal: AcmJournal[]) {
const naccept = Counter<number>();
@@ -100,7 +99,6 @@ const acm = buildContestRule({
const detail: Record<number, AcmDetail> = {};
let accept = 0;
let time = 0;
// eslint-disable-next-line @typescript-eslint/no-use-before-define
const lockAt = isLocked(tdoc) ? tdoc.lockAt : null;
for (const j of journal) {
if (!tdoc.pids.includes(j.pid)) continue;
@@ -281,7 +279,7 @@ const oi = buildContestRule({
const detail = {};
const display = {};
let score = 0;
// eslint-disable-next-line @typescript-eslint/no-use-before-define
const lockAt = isLocked(tdoc) ? tdoc.lockAt : null;
for (const j of journal.filter((i) => tdoc.pids.includes(i.pid))) {
if (lockAt && j.rid.getTimestamp() > lockAt) {
@@ -362,7 +360,7 @@ const oi = buildContestRule({
const tsddict = ((config.lockAt && isLocked(tdoc, new Date())) ? tsdoc.display : tsdoc.detail) || {};
for (const pid of tdoc.pids) {
const index = `${tsdoc.uid}/${tdoc.domainId}/${pid}`;
// eslint-disable-next-line @typescript-eslint/no-use-before-define
const node: ScoreboardNode = (!config.isExport && !config.lockAt && isDone(tdoc)
&& meta?.psdict?.[index]?.rid
&& tsddict[pid]?.rid?.toHexString() !== meta?.psdict?.[index]?.rid?.toHexString()
@@ -408,7 +406,7 @@ const oi = buildContestRule({
if (!first[pid] || first[pid] > time) first[pid] = time;
}
}
// eslint-disable-next-line @typescript-eslint/no-use-before-define
if (isDone(tdoc)) {
const psdocs = await Promise.all(
tdoc.pids.map((pid) => problem.getMultiStatus(tdoc.domainId, { docId: pid, uid: { $in: uids } }).toArray()),
@@ -450,7 +448,7 @@ const oi = buildContestRule({
const ioi = buildContestRule({
TEXT: 'IOI',
submitAfterAccept: false,
// eslint-disable-next-line @typescript-eslint/no-use-before-define
showRecord: (tdoc, now) => now > tdoc.endAt && !isLocked(tdoc),
showSelfRecord: () => true,
showScoreboard: (tdoc, now) => now > tdoc.beginAt,
+6 -8
View File
@@ -382,14 +382,12 @@ export async function revPushStatus<T extends keyof DocStatusType>(
{ $set: { [`${key}.$`]: value }, $inc: { rev: 1 } },
{ returnDocument: 'after' },
);
if (!res) {
res = await collStatus.findOneAndUpdate(
{ domainId, docType, docId, uid },
// @ts-ignore
{ $push: { [key]: value }, $inc: { rev: 1 } },
{ upsert: true, returnDocument: 'after' },
);
}
res ||= await collStatus.findOneAndUpdate(
{ domainId, docType, docId, uid },
// @ts-ignore
{ $push: { [key]: value }, $inc: { rev: 1 } },
{ upsert: true, returnDocument: 'after' },
);
return res;
}
+5 -1
View File
@@ -136,7 +136,11 @@ class DomainModel {
static async setUserRole(domainId: string, uid: MaybeArray<number>, role: string, autojoin = false) {
const update = { $set: { role, ...(autojoin ? { join: true } : {}) } };
if (!(uid instanceof Array)) {
const res = await collUser.findOneAndUpdate({ domainId, uid }, update, { upsert: true, returnDocument: 'after', includeResultMetadata: true });
const res = await collUser.findOneAndUpdate(
{ domainId, uid },
update,
{ upsert: true, returnDocument: 'after', includeResultMetadata: true },
);
const udoc = await UserModel.getById(domainId, uid);
deleteUserCache(udoc);
return res;
-1
View File
@@ -385,7 +385,6 @@ export class ProblemModel {
}
for (const pdoc of pdocs) {
try {
// eslint-disable-next-line no-await-in-loop
pdoc.config = await parseConfig(pdoc.config as string);
} catch (e) {
pdoc.config = `Cannot parse: ${e.message}`;
-2
View File
@@ -45,7 +45,6 @@ export const DOMAIN_USER_SETTINGS_BY_KEY: SettingDict = {};
export const DOMAIN_SETTINGS_BY_KEY: SettingDict = {};
export const SYSTEM_SETTINGS_BY_KEY: SettingDict = {};
// eslint-disable-next-line max-len
export type SettingType = 'text' | 'yaml' | 'number' | 'float' | 'markdown' | 'password' | 'boolean' | 'textarea' | [string, string][] | Record<string, string> | 'json';
export const Setting = (
@@ -355,7 +354,6 @@ SystemSetting(
Setting('setting_storage', 'installid', String.random(64), 'text', 'installid', 'Installation ID', FLAG_HIDDEN | FLAG_DISABLED),
);
// eslint-disable-next-line import/no-mutable-exports
export const langs: Record<string, LangConfig> = {};
declare module '@cordisjs/core' {
-1
View File
@@ -169,7 +169,6 @@ export async function apply(ctx: Context) {
stream.on('error', async () => {
// The $changeStream stage is only supported on replica sets
logger.info('No replica set found.');
// eslint-disable-next-line no-constant-condition
while (true) {
let res;
try {
+1 -1
View File
@@ -316,7 +316,7 @@ class UserModel {
autoAlloc = true;
}
const salt = String.random();
while (true) { // eslint-disable-line no-constant-condition
while (true) {
try {
// eslint-disable-next-line no-await-in-loop
await coll.insertOne({
+1 -1
View File
@@ -58,4 +58,4 @@ export { EventMap } from './service/bus';
export { db, pwsh };
// to load ctx.scoreboard
export { } from './handler/contest'; // eslint-disable-line @typescript-eslint/no-useless-empty-export
export { } from './handler/contest';
@@ -1,4 +1,3 @@
/* eslint-disable no-await-in-loop */
import Schema from 'schemastery';
import { STATUS } from '../model/builtin';
import * as document from '../model/document';
@@ -1,4 +1,3 @@
/* eslint-disable no-await-in-loop */
import Schema from 'schemastery';
import { STATUS } from '../model/builtin';
import storage from '../model/storage';
-1
View File
@@ -1,4 +1,3 @@
/* eslint-disable no-await-in-loop */
import {
BSON, Db, Filter, ObjectId, OnlyFieldsOfType,
} from 'mongodb';
+1 -1
View File
@@ -59,7 +59,7 @@ export class MongoService extends Service {
const mongourl = await MongoService.getUrl();
const url = mongoUri.parse(mongourl);
this.client = await MongoClient.connect(mongourl);
yield () => { this.client.close(); }
yield () => { this.client.close(); };
this.db = this.client.db(url.database || 'hydro');
await bus.parallel('database/connect', this.db);
this.ctx.setInterval(() => this.fixExpireAfter(), Time.hour);
-1
View File
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-shadow */
import { Logger } from './logger';
import bus from './service/bus';