diff --git a/eslint.config.mjs b/eslint.config.mjs index 5c30f9d3f..b7cd499a7 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -121,6 +121,8 @@ const config = react({ // FIXME A bug with eslint-parser // 'template-curly-spacing': 'off', + 'e18e/prefer-array-at': 'off', + 'style/indent': ['warn', 2, { ArrayExpression: 1, CallExpression: { diff --git a/framework/eslint-config/base.mjs b/framework/eslint-config/base.mjs index c5e55e179..266524317 100644 --- a/framework/eslint-config/base.mjs +++ b/framework/eslint-config/base.mjs @@ -58,9 +58,12 @@ const base = (option, ...args) => antfu( 'default-param-last': 'off', 'dot-notation': 0, + 'e18e/prefer-array-fill': 'off', + 'e18e/prefer-array-from-map': 'off', 'e18e/prefer-array-some': 'off', 'e18e/prefer-array-to-sorted': 'off', 'e18e/prefer-static-regex': 'off', + 'e18e/prefer-timer-args': 'off', 'eslint-comments/no-unlimited-disable': 'off', 'func-names': 0, 'function-call-argument-newline': 0, diff --git a/packages/hydrojudge/src/hosts/vj4.ts b/packages/hydrojudge/src/hosts/vj4.ts index 8bdb4ff17..1cd7d22f4 100644 --- a/packages/hydrojudge/src/hosts/vj4.ts +++ b/packages/hydrojudge/src/hosts/vj4.ts @@ -287,7 +287,7 @@ export default class VJ4 implements Session { ver = fs.readFileSync(path.join(filePath, 'version')).toString(); } catch (e) { /* ignore */ } if (version === ver) { - fs.writeFileSync(path.join(filePath, 'lastUsage'), new Date().getTime().toString()); + fs.writeFileSync(path.join(filePath, 'lastUsage'), Date.now().toString()); return filePath; } fs.removeSync(filePath); @@ -295,7 +295,7 @@ export default class VJ4 implements Session { fs.ensureDirSync(domainDir); await this.problemData(domainId, pid, filePath, 3, next); fs.writeFileSync(path.join(filePath, 'version'), version); - fs.writeFileSync(path.join(filePath, 'lastUsage'), new Date().getTime().toString()); + fs.writeFileSync(path.join(filePath, 'lastUsage'), Date.now().toString()); return filePath; } diff --git a/packages/hydrooj/src/entry/cli.ts b/packages/hydrooj/src/entry/cli.ts index a3c81f57c..a13c6201f 100644 --- a/packages/hydrooj/src/entry/cli.ts +++ b/packages/hydrooj/src/entry/cli.ts @@ -77,7 +77,7 @@ async function cli() { return console.error(parameters.join(', ')); } for (let i = 0; i < args.length; i++) { - if ("'\"".includes(args[i][0]) && "'\"".includes(args[i][args[i].length - 1])) { + if ("'\"".includes(args[i][0]) && "'\"".includes(args[i].at(-1))) { args[i] = args[i].substr(1, args[i].length - 2); } else if (args[i].length === 24 && ObjectId.isValid(args[i])) { args[i] = new ObjectId(args[i]); diff --git a/packages/hydrooj/src/handler/judge.ts b/packages/hydrooj/src/handler/judge.ts index cf65c0481..8d8bb6c89 100644 --- a/packages/hydrooj/src/handler/judge.ts +++ b/packages/hydrooj/src/handler/judge.ts @@ -363,7 +363,7 @@ export async function apply(ctx: Context) { assert(Array.isArray(config.subtasks)); const file = await storage.get(`submission/${rdoc.files.hack.split('#')[0]}`); assert(file); - const hackSubtask = config.subtasks[config.subtasks.length - 1]; + const hackSubtask = config.subtasks.at(-1); hackSubtask.cases ||= []; const input = `hack-${rdoc._id}-${hackSubtask.cases.length + 1}.in`; hackSubtask.cases.push({ input, output: '/dev/null' }); diff --git a/packages/hydrooj/src/handler/status.ts b/packages/hydrooj/src/handler/status.ts index 17f216820..d42db239a 100644 --- a/packages/hydrooj/src/handler/status.ts +++ b/packages/hydrooj/src/handler/status.ts @@ -10,7 +10,7 @@ async function getStatus() { const stats = await coll.find().sort({ type: 1, updateAt: -1 }).toArray(); for (const stat of stats) { let desc = ''; - const online = new Date(stat.updateAt).getTime() > new Date().getTime() - 300000; + const online = new Date(stat.updateAt).getTime() > Date.now() - 300000; if (!online) desc = 'Offline'; desc ||= 'Online'; stat.isOnline = online; diff --git a/packages/hydrooj/src/model/blacklist.ts b/packages/hydrooj/src/model/blacklist.ts index 255695584..5851ecfa1 100644 --- a/packages/hydrooj/src/model/blacklist.ts +++ b/packages/hydrooj/src/model/blacklist.ts @@ -1,7 +1,7 @@ import moment from 'moment-timezone'; import { Context } from '../context'; import db from '../service/db'; -import { ArgMethod } from '../utils'; +import { ArgMethod, Time } from '../utils'; let coll = db.collection('blacklist'); @@ -12,7 +12,7 @@ class BlackListModel { if (expire === 0) expireAt = moment().add(1000, 'months').toDate(); else if (typeof expire === 'number') expireAt = moment().add(expire, 'months').toDate(); else if (expire instanceof Date) expireAt = expire; - else expireAt = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000); + else expireAt = new Date(Date.now() + 365 * Time.day); return await coll.findOneAndUpdate( { _id: id }, { $set: { expireAt } }, diff --git a/packages/hydrooj/src/model/contest.ts b/packages/hydrooj/src/model/contest.ts index 2a6964180..404261746 100644 --- a/packages/hydrooj/src/model/contest.ts +++ b/packages/hydrooj/src/model/contest.ts @@ -78,7 +78,7 @@ export function isLocked(tdoc: Tdoc, time = new Date()) { } export function isExtended(tdoc: Tdoc) { - const now = new Date().getTime(); + const now = Date.now(); return tdoc.penaltySince.getTime() <= now && now < tdoc.endAt.getTime(); } diff --git a/packages/hydrooj/src/model/opcount.ts b/packages/hydrooj/src/model/opcount.ts index 53f229e21..e69d2b255 100644 --- a/packages/hydrooj/src/model/opcount.ts +++ b/packages/hydrooj/src/model/opcount.ts @@ -4,7 +4,7 @@ import db from '../service/db'; const coll = db.collection('opcount'); export async function inc(op: string, ident: string, periodSecs: number, maxOperations: number) { - const now = new Date().getTime(); + const now = Date.now(); const expireAt = new Date(now - (now % (periodSecs * 1000)) + periodSecs * 1000); try { const res = await coll.findOneAndUpdate({ diff --git a/packages/hydrooj/src/script/rating.ts b/packages/hydrooj/src/script/rating.ts index 43cbe94ab..c5a7b42c5 100644 --- a/packages/hydrooj/src/script/rating.ts +++ b/packages/hydrooj/src/script/rating.ts @@ -166,13 +166,13 @@ export async function run({ domainId }, report: Report) { const domains = await domain.getMulti().toArray(); await report({ message: `Found ${domains.length} domains` }); for (const i in domains) { - const start = new Date().getTime(); + const start = Date.now(); await runInDomain(domains[i]._id, report); await report({ case: { status: STATUS.STATUS_ACCEPTED, message: `Domain ${domains[i]._id} finished`, - time: new Date().getTime() - start, + time: Date.now() - start, memory: 0, score: 0, }, diff --git a/packages/hydrooj/src/settings.ts b/packages/hydrooj/src/settings.ts index b26b3d797..edd47f333 100644 --- a/packages/hydrooj/src/settings.ts +++ b/packages/hydrooj/src/settings.ts @@ -103,7 +103,7 @@ export class SettingService extends Service { async _actualMigrate(schema: Schema) { const processNode = async (path: string[], node: Schema) => { for (const item of node.list || []) await processNode(path, item); // eslint-disable-line no-await-in-loop - for (const key in node.dict || {}) await processNode(path.concat(key), node.dict[key]); // eslint-disable-line no-await-in-loop + for (const key in node.dict || {}) await processNode([...path, ...key], node.dict[key]); // eslint-disable-line no-await-in-loop if (['string', 'number', 'boolean'].includes(node.type)) { const value = this.initialValues[path.join('.')]; const migrated = this.initialValues[`${path.join('.')}__migrated`]; @@ -181,10 +181,10 @@ export class SettingService extends Service { if (path.some((p) => typeof p === 'symbol')) return currentValue; return new Proxy(currentValue, { get(self, key: string) { - return getAccess(path.concat(key)); + return getAccess([...path, ...key]); }, set(self, p: string | symbol, newValue: any) { - that.setConfig(path.concat(p).join(','), newValue); + that.setConfig([...path, p].join(','), newValue); return true; }, }); diff --git a/packages/migrate/scripts/hustoj.ts b/packages/migrate/scripts/hustoj.ts index 12643ab1d..8529c48f8 100644 --- a/packages/migrate/scripts/hustoj.ts +++ b/packages/migrate/scripts/hustoj.ts @@ -59,7 +59,7 @@ function fixFileName(fileName: string) { const dotAt = fileName.lastIndexOf('.'); const name = fileName.slice(0, dotAt); const suffix = fileName.slice(dotAt + 1); - if (!name.match(/[0-9]/)) { + if (!/[0-9]/.test(name)) { fileName = `${name}0.${suffix}`; } } diff --git a/packages/migrate/scripts/jnoj.ts b/packages/migrate/scripts/jnoj.ts index 4df79ae88..87bb4bf38 100644 --- a/packages/migrate/scripts/jnoj.ts +++ b/packages/migrate/scripts/jnoj.ts @@ -65,7 +65,7 @@ function fixFileName(fileName: string) { const dotAt = fileName.lastIndexOf('.'); const name = fileName.slice(0, dotAt); const suffix = fileName.slice(dotAt + 1); - if (!name.match(/[0-9]/)) { + if (!/[0-9]/.test(name)) { fileName = `${name}0.${suffix}`; } } diff --git a/packages/ui-default/components/highlighter/prismjs.js b/packages/ui-default/components/highlighter/prismjs.js index c9dfb17a0..6ecec9bc8 100644 --- a/packages/ui-default/components/highlighter/prismjs.js +++ b/packages/ui-default/components/highlighter/prismjs.js @@ -66,12 +66,12 @@ const invisibles = { function addInvisibles(grammar) { if (!grammar || grammar.tab) return; for (const name in invisibles) { - if (Object.prototype.hasOwnProperty.call(invisibles, name)) { + if (Object.hasOwn(invisibles, name)) { grammar[name] = invisibles[name]; } } for (const name in grammar) { - if (Object.prototype.hasOwnProperty.call(grammar, name) && !invisibles[name]) { + if (Object.hasOwn(grammar, name) && !invisibles[name]) { if (name === 'rest') addInvisibles(grammar.rest); else handlerInvisiblesToken(grammar, name); // eslint-disable-line ts/no-use-before-define } diff --git a/packages/vjudge/src/index.ts b/packages/vjudge/src/index.ts index 536485fbd..283cda16d 100644 --- a/packages/vjudge/src/index.ts +++ b/packages/vjudge/src/index.ts @@ -58,7 +58,7 @@ class AccountService { if (langConfig.validAs?.[this.account.type]) task.lang = langConfig.validAs[this.account.type]; const comment = langConfig.comment; if (comment && !this.Provider.noComment) { - const msg = `Hydro submission #${task.rid}@${new Date().getTime()}`; + const msg = `Hydro submission #${task.rid}@${Date.now()}`; if (typeof comment === 'string') task.code = `${comment} ${msg}\n${task.code}`; else if (comment instanceof Array) task.code = `${comment[0]} ${msg} ${comment[1]}\n${task.code}`; }