mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
workspace: update eslint rule (#1027)
This commit is contained in:
1 parent
05c3b8f2bd
commit
cee3c00ddb
150 files changed
+1069
-1043
No files matched your search
@@ -42,7 +42,7 @@ export class ContestListHandler extends Handler {
|
||||
if (group && !groups.includes(group)) throw new NotAssignedError(group);
|
||||
const rules = Object.keys(contest.RULES).filter((i) => !contest.RULES[i].hidden);
|
||||
const escaped = escapeRegExp(q.toLowerCase());
|
||||
const $regex = new RegExp(q.length >= 2 ? escaped : `\\A${escaped}`, 'gmi');
|
||||
const $regex = new RegExp(q.length >= 2 ? escaped : `\\A${escaped}`, 'gim');
|
||||
const filter = {
|
||||
...(this.user.hasPerm(PERM.PERM_VIEW_HIDDEN_CONTEST) && !group)
|
||||
? {}
|
||||
@@ -626,10 +626,10 @@ export class ContestBalloonHandler extends ContestManagementBaseHandler {
|
||||
}
|
||||
}
|
||||
|
||||
type BuiltinInput = {
|
||||
interface BuiltinInput {
|
||||
tdoc: Tdoc;
|
||||
groups: any[];
|
||||
};
|
||||
}
|
||||
type AnyFunction = (...args: any) => any;
|
||||
type ParseArgs<T extends { [key: string]: keyof BuiltinInput | AnyFunction | Type<any> }> = {
|
||||
[key in keyof T]: T[key] extends keyof BuiltinInput ? BuiltinInput[T[key]] : T[key] extends AnyFunction ? ReturnType<T[key]> : any
|
||||
@@ -696,9 +696,9 @@ class ScoreboardService extends Service {
|
||||
addView<T extends { [key: string]: keyof BuiltinInput | AnyFunction | Type<any> }>(
|
||||
id: string, name: string, args: T,
|
||||
{ display, supportedRules, cacheTime }: {
|
||||
display: (this: ContestScoreboardHandler, args: ParseArgs<T>) => Promise<void>,
|
||||
supportedRules: string[],
|
||||
cacheTime?: number,
|
||||
display: (this: ContestScoreboardHandler, args: ParseArgs<T>) => Promise<void>;
|
||||
supportedRules: string[];
|
||||
cacheTime?: number;
|
||||
},
|
||||
) {
|
||||
if (this.views[id]) throw new Error(`View ${id} already exists`);
|
||||
@@ -766,7 +766,7 @@ export async function apply(ctx: Context) {
|
||||
config.lockAt = this.tdoc.lockAt;
|
||||
}
|
||||
const [, rows, udict, pdict] = await contest.getScoreboard.call(this, tdoc.domainId, tdoc._id, config);
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
// eslint-disable-next-line ts/naming-convention
|
||||
const page_name = tdoc.rule === 'homework'
|
||||
? 'homework_scoreboard'
|
||||
: 'contest_scoreboard';
|
||||
|
||||
@@ -95,7 +95,7 @@ class DiscussionNodeHandler extends DiscussionHandler {
|
||||
async get(domainId: string, type: string, _name: string, page = 1) {
|
||||
let name: ObjectId | string | number;
|
||||
if (ObjectId.isValid(_name)) name = new ObjectId(_name);
|
||||
else if (isSafeInteger(parseInt(_name, 10))) name = parseInt(_name, 10);
|
||||
else if (isSafeInteger(Number.parseInt(_name, 10))) name = Number.parseInt(_name, 10);
|
||||
else name = _name;
|
||||
const hidden = this.user.own(this.vnode) || this.user.hasPerm(PERM.PERM_EDIT_DISCUSSION) ? {} : { hidden: false };
|
||||
const [ddocs, dpcount] = await this.paginate(
|
||||
|
||||
@@ -534,7 +534,7 @@ class HomeDomainCreateHandler extends Handler {
|
||||
@param('name', Types.Title)
|
||||
@param('bulletin', Types.Content)
|
||||
@param('avatar', Types.Content, true)
|
||||
// eslint-disable-next-line @typescript-eslint/no-shadow
|
||||
// eslint-disable-next-line ts/no-shadow
|
||||
async post(_: string, id: string, name: string, bulletin: string, avatar: string) {
|
||||
const doc = await domain.get(id);
|
||||
if (doc) throw new DomainAlreadyExistsError(id);
|
||||
|
||||
@@ -52,7 +52,7 @@ class HomeworkMainHandler extends Handler {
|
||||
],
|
||||
},
|
||||
...group ? { assign: { $in: [group] } } : {},
|
||||
...q ? { title: { $regex: new RegExp(q.length >= 2 ? escaped : `\\A${escaped}`, 'gmi') } } : {},
|
||||
...q ? { title: { $regex: new RegExp(q.length >= 2 ? escaped : `\\A${escaped}`, 'gim') } } : {},
|
||||
}).sort({
|
||||
penaltySince: -1, endAt: -1, beginAt: -1, _id: -1,
|
||||
});
|
||||
|
||||
@@ -79,7 +79,7 @@ export class JudgeResultCallbackContext {
|
||||
private relatedId = new ObjectId();
|
||||
private meta: { rejudge?: JudgeMeta['rejudge'] };
|
||||
|
||||
constructor(public ctx: Context, public readonly task: Omit<Task, '_id'> & { type: string }) { // eslint-disable-line @typescript-eslint/no-shadow
|
||||
constructor(public ctx: Context, public readonly task: Omit<Task, '_id'> & { type: string }) { // eslint-disable-line ts/no-shadow
|
||||
this.meta = task.meta as JudgeMeta || {};
|
||||
this.finishPromise = new Promise((resolve) => {
|
||||
this.resolve = resolve;
|
||||
|
||||
@@ -239,7 +239,7 @@ class SystemUserImportHandler extends SystemHandler {
|
||||
@param('draft', Types.Boolean)
|
||||
async post(domainId: string, _users: string, draft: boolean) {
|
||||
const users = _users.split('\n');
|
||||
const udocs: { email: string, username: string, password: string, displayName?: string, [key: string]: any; }[] = [];
|
||||
const udocs: { email: string, username: string, password: string, displayName?: string, [key: string]: any }[] = [];
|
||||
const messages = [];
|
||||
const mapping = Object.create(null);
|
||||
const groups: Record<string, string[]> = Object.create(null);
|
||||
|
||||
@@ -56,7 +56,7 @@ function buildQuery(udoc: User) {
|
||||
const defaultSearch = async (domainId: string, q: string, options?: ProblemSearchOptions) => {
|
||||
const escaped = escapeRegExp(q.toLowerCase());
|
||||
const projection: (keyof ProblemDoc)[] = ['domainId', 'docId', 'pid'];
|
||||
const $regex = new RegExp(q.length >= 2 ? escaped : `\\A${escaped}`, 'gmi');
|
||||
const $regex = new RegExp(q.length >= 2 ? escaped : `\\A${escaped}`, 'gim');
|
||||
const filter = { $or: [{ pid: { $regex } }, { title: { $regex } }, { tag: q }] };
|
||||
const pdocs = await problem.getMulti(domainId, filter, projection)
|
||||
.skip(options.skip || 0).limit(options.limit || system.get('pagination.problem')).toArray();
|
||||
@@ -109,7 +109,7 @@ export class ProblemMainHandler extends Handler {
|
||||
this.response.template = 'problem_main.html';
|
||||
if (!limit || limit > this.ctx.setting.get('pagination.problem') || page > 1) limit = this.ctx.setting.get('pagination.problem');
|
||||
this.queryContext.query = buildQuery(this.user);
|
||||
// eslint-disable-next-line @typescript-eslint/no-shadow
|
||||
// eslint-disable-next-line ts/no-shadow
|
||||
const query = this.queryContext.query;
|
||||
const psdict = {};
|
||||
const search = Object.values(global.Hydro.module.problemSearch)[0] || defaultSearch;
|
||||
@@ -607,7 +607,7 @@ export class ProblemEditHandler extends ProblemManageHandler {
|
||||
@route('pid', Types.ProblemId)
|
||||
@post('title', Types.Title)
|
||||
@post('content', Types.Content)
|
||||
@post('pid', Types.ProblemId, true, (i) => /^([a-zA-Z0-9]{1,10}-)?[a-zA-Z]+[a-zA-Z0-9]*$/i.test(i))
|
||||
@post('pid', Types.ProblemId, true, (i) => /^(?:[a-z0-9]{1,10}-)?[a-z][a-z0-9]*$/i.test(i))
|
||||
@post('hidden', Types.Boolean)
|
||||
@post('tag', Types.Content, true, null, parseCategory)
|
||||
@post('difficulty', Types.PositiveInt, (i) => +i <= 10, true)
|
||||
@@ -837,7 +837,7 @@ export class ProblemSolutionHandler extends ProblemDetailHandler {
|
||||
if (!accepted || !this.user.hasPerm(PERM.PERM_VIEW_PROBLEM_SOLUTION_ACCEPT)) {
|
||||
this.checkPerm(PERM.PERM_VIEW_PROBLEM_SOLUTION);
|
||||
}
|
||||
// eslint-disable-next-line prefer-const
|
||||
|
||||
let [psdocs, pcount, pscount] = await this.paginate(
|
||||
solution.getMulti(domainId, this.pdoc.docId),
|
||||
page,
|
||||
@@ -995,7 +995,7 @@ export class ProblemCreateHandler extends Handler {
|
||||
|
||||
@post('title', Types.Title)
|
||||
@post('content', Types.Content)
|
||||
@post('pid', Types.ProblemId, true, (i) => /^([a-zA-Z0-9]{1,10}-)?[a-zA-Z]+[a-zA-Z0-9]*$/i.test(i))
|
||||
@post('pid', Types.ProblemId, true, (i) => /^(?:[a-z0-9]{1,10}-)?[a-z][a-z0-9]*$/i.test(i))
|
||||
@post('hidden', Types.Boolean)
|
||||
@post('difficulty', Types.PositiveInt, (i) => +i <= 10, true)
|
||||
@post('tag', Types.Content, true, null, parseCategory)
|
||||
@@ -1006,7 +1006,7 @@ export class ProblemCreateHandler extends Handler {
|
||||
if (typeof pid !== 'string') pid = `P${pid}`;
|
||||
if (pid && await problem.get(domainId, pid)) throw new ProblemAlreadyExistError(pid);
|
||||
const docId = await problem.add(domainId, pid, title, content, this.user._id, tag ?? [], { hidden, difficulty });
|
||||
const files = new Set(Array.from(content.matchAll(/file:\/\/([a-zA-Z0-9_-]+\.[a-zA-Z0-9]+)/g)).map((i) => i[1]));
|
||||
const files = new Set(Array.from(content.matchAll(/file:\/\/([\w-]+\.[a-zA-Z0-9]+)/g)).map((i) => i[1]));
|
||||
const tasks = [];
|
||||
for (const file of files) {
|
||||
if (this.user._files.find((i) => i.name === file)) {
|
||||
|
||||
@@ -70,7 +70,7 @@ class RecordListHandler extends ContestDetailBaseHandler {
|
||||
}
|
||||
if (pid) {
|
||||
if (typeof pid === 'string' && tdoc && /^[A-Z]$/.test(pid)) {
|
||||
pid = tdoc.pids[parseInt(pid, 36) - 10];
|
||||
pid = tdoc.pids[Number.parseInt(pid, 36) - 10];
|
||||
}
|
||||
const pdoc = await problem.get(domainId, pid);
|
||||
if (pdoc) q.pid = pdoc.docId;
|
||||
@@ -341,7 +341,6 @@ class RecordMainConnectionHandler extends ConnectionHandler {
|
||||
if (typeof this.pid === 'number' && rdoc.pid !== this.pid) return;
|
||||
if (typeof this.uid === 'number' && rdoc.uid !== this.uid) return;
|
||||
|
||||
// eslint-disable-next-line prefer-const
|
||||
let [udoc, pdoc] = await Promise.all([
|
||||
user.getById(this.args.domainId, rdoc.uid),
|
||||
problem.get(rdoc.domainId, rdoc.pid),
|
||||
|
||||
Reference in new issue
Block a user