eslint: variable naming

This commit is contained in:
undefined committed 2022-01-14 03:00:19 +08:00
1 parent 55a95b97ea
commit 268ac23b26
17 files changed
+96 -52

No files matched your search

+43 -1
View File
@@ -11,6 +11,9 @@ parser: '@typescript-eslint/parser'
plugins: plugins:
- '@typescript-eslint' - '@typescript-eslint'
- simple-import-sort - simple-import-sort
ignorePatterns:
- public/
- '*.spec.ts'
rules: rules:
'@typescript-eslint/dot-notation': 0 '@typescript-eslint/dot-notation': 0
'@typescript-eslint/no-implied-eval': 0 '@typescript-eslint/no-implied-eval': 0
@@ -24,7 +27,42 @@ rules:
- error - error
- always - always
- exceptAfterSingleLine: true - exceptAfterSingleLine: true
'@typescript-eslint/naming-convention': 0 '@typescript-eslint/naming-convention':
- warn
- selector: default
format: [camelCase]
leadingUnderscore: allowSingleOrDouble
- selector: default
filter:
regex: '^([A-Z]|_+id|__call__)$'
match: true
format: null
- selector: variable
modifiers: [destructured]
filter:
regex: '^_id$'
match: false
format: [camelCase, PascalCase, UPPER_CASE, snake_case]
- selector: variable
format: [camelCase, PascalCase, UPPER_CASE]
modifiers: [const]
leadingUnderscore: allowSingleOrDouble
- selector: property
format: [camelCase, PascalCase, UPPER_CASE, snake_case]
leadingUnderscore: allowSingleOrDouble
- selector: [function, parameter, parameterProperty, objectLiteralMethod]
filter:
regex: __call__
match: false
format: [camelCase, PascalCase]
leadingUnderscore: allowSingleOrDouble
- selector: enum
format: [PascalCase]
- selector: [class, interface, typeAlias, enumMember]
format: [PascalCase, camelCase]
- selector: typeParameter
format: [camelCase, PascalCase, UPPER_CASE]
'@typescript-eslint/no-redeclare': 0 '@typescript-eslint/no-redeclare': 0
class-methods-use-this: 0 class-methods-use-this: 0
@@ -77,3 +115,7 @@ settings:
import/resolver: import/resolver:
typescript: typescript:
alwaysTryTypes: true alwaysTryTypes: true
# parserOptions:
# project:
# - './tsconfig.json'
# - './packages/**/tsconfig.json'
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "@hydrooj/hydrojudge", "name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js", "bin": "bin/hydrojudge.js",
"version": "2.12.15", "version": "2.12.16",
"main": "package.json", "main": "package.json",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"repository": "https://github.com/hydro-dev/Hydro.git", "repository": "https://github.com/hydro-dev/Hydro.git",
+2 -2
View File
@@ -189,8 +189,8 @@ function isValidConfig(config) {
if (config.count > (getConfig('testcases_max') || 100)) { if (config.count > (getConfig('testcases_max') || 100)) {
throw new FormatError('Too many testcases. Cancelled.'); throw new FormatError('Too many testcases. Cancelled.');
} }
const total_time = sum(config.subtasks.map((subtask) => subtask.time * subtask.cases.length)); const time = sum(config.subtasks.map((subtask) => subtask.time * subtask.cases.length));
if (total_time > (getConfig('total_time_limit') || 60) * 1000) { if (time > (getConfig('total_time_limit') || 60) * 1000) {
throw new FormatError('Total time limit longer than {0}s. Cancelled.', [+getConfig('total_time_limit') || 60]); throw new FormatError('Total time limit longer than {0}s. Cancelled.', [+getConfig('total_time_limit') || 60]);
} }
const memMax = max(config.subtasks.map((subtask) => subtask.memory)); const memMax = max(config.subtasks.map((subtask) => subtask.memory));
+1
View File
@@ -6,6 +6,7 @@ import fs from 'fs-extra';
import yaml from 'js-yaml'; import yaml from 'js-yaml';
const argv = cac().parse(); const argv = cac().parse();
// eslint-disable-next-line @typescript-eslint/naming-convention
let CONFIG_FILE = path.resolve(os.homedir(), '.config', 'hydro', 'judge.yaml'); let CONFIG_FILE = path.resolve(os.homedir(), '.config', 'hydro', 'judge.yaml');
let config = { let config = {
+6 -6
View File
@@ -30,7 +30,7 @@ declare global {
} }
if (!global.onDestory) global.onDestory = []; if (!global.onDestory) global.onDestory = [];
if (!global.hosts) global.hosts = []; if (!global.hosts) global.hosts = [];
let SI = false; let exit = false;
const terminate = async () => { const terminate = async () => {
log.info('正在保存数据'); log.info('正在保存数据');
@@ -38,11 +38,11 @@ const terminate = async () => {
await Promise.all(global.onDestory.map((f) => f())); await Promise.all(global.onDestory.map((f) => f()));
process.exit(1); process.exit(1);
} catch (e) { } catch (e) {
if (SI) process.exit(1); if (exit) process.exit(1);
log.error(e.stack); log.error(e.stack);
log.error('发生了错误。'); log.error('发生了错误。');
log.error('再次按下 Ctrl-C 可强制退出。'); log.error('再次按下 Ctrl-C 可强制退出。');
SI = true; exit = true;
} }
}; };
process.on('SIGINT', terminate); process.on('SIGINT', terminate);
@@ -60,7 +60,7 @@ async function worker(queue: Queue<any>) {
async function daemon() { async function daemon() {
const _hosts = getConfig('hosts'); const _hosts = getConfig('hosts');
const retry_delay_sec = getConfig('retry_delay_sec'); const delay = getConfig('retry_delay_sec');
const hosts = {}; const hosts = {};
const queue = new Queue<any>(); const queue = new Queue<any>();
for (const i in _hosts) { for (const i in _hosts) {
@@ -77,8 +77,8 @@ async function daemon() {
break; break;
} catch (e) { } catch (e) {
log.error(e, e.stack); log.error(e, e.stack);
log.info(`在 ${retry_delay_sec} 秒后重试`); log.info(`在 ${delay} 秒后重试`);
await sleep(retry_delay_sec * 1000); await sleep(delay * 1000);
} }
} }
} }
+2 -2
View File
@@ -27,7 +27,7 @@ function proc({
execute = '', execute = '',
time = 16000, time = 16000,
memory = parseMemoryMB(getConfig('memoryMax')), memory = parseMemoryMB(getConfig('memoryMax')),
process_limit = getConfig('processLimit'), processLimit = getConfig('processLimit'),
stdin = '', copyIn = {}, copyOut = [], copyOutCached = [], stdin = '', copyIn = {}, copyOut = [], copyOutCached = [],
} = {}) { } = {}) {
if (!supportOptional) { if (!supportOptional) {
@@ -48,7 +48,7 @@ function proc({
memoryLimit: Math.floor(memory * 1024 * 1024), memoryLimit: Math.floor(memory * 1024 * 1024),
strictMemoryLimit: getConfig('strict_memory'), strictMemoryLimit: getConfig('strict_memory'),
// stackLimit: memory * 1024 * 1024, // stackLimit: memory * 1024 * 1024,
procLimit: process_limit, procLimit: processLimit,
copyIn, copyIn,
copyOut, copyOut,
copyOutCached, copyOutCached,
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "3.3.10", "version": "3.3.11",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "src/loader", "main": "src/loader",
"module": "src/loader", "module": "src/loader",
+3 -3
View File
@@ -49,13 +49,13 @@ async function syzojSync(info) {
memory: `${judge.memoryLimit}m`, memory: `${judge.memoryLimit}m`,
}; };
if (judge.extraSourceFiles) { if (judge.extraSourceFiles) {
const user_extra_files = []; const files = [];
for (const key in judge.extraSourceFiles) { for (const key in judge.extraSourceFiles) {
for (const file in judge.extraSourceFiles[key]) { for (const file in judge.extraSourceFiles[key]) {
user_extra_files.push(file); files.push(file);
} }
} }
config.user_extra_files = user_extra_files; config.user_extra_files = files;
} }
if (judge.checker?.type === 'custom') { if (judge.checker?.type === 'custom') {
config.checker_type = judge.checker.interface; config.checker_type = judge.checker.interface;
+2 -2
View File
@@ -501,12 +501,12 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
this.response.body.additional_file = getAdditionalFile ? sortFiles(this.pdoc.additional_file || []) : []; this.response.body.additional_file = getAdditionalFile ? sortFiles(this.pdoc.additional_file || []) : [];
if (pjax) { if (pjax) {
const { testdata, additional_file } = this.response.body; const { testdata, additional_file } = this.response.body;
const owner_udoc = await user.getById(domainId, this.pdoc.owner); const owner = await user.getById(domainId, this.pdoc.owner);
this.response.body = { this.response.body = {
fragments: (await Promise.all([ fragments: (await Promise.all([
this.renderHTML('partials/problem_files-testdata.html', { testdata, pdoc: this.pdoc }), this.renderHTML('partials/problem_files-testdata.html', { testdata, pdoc: this.pdoc }),
this.renderHTML('partials/problem_files-additional_file.html', { additional_file, pdoc: this.pdoc }), this.renderHTML('partials/problem_files-additional_file.html', { additional_file, pdoc: this.pdoc }),
this.renderHTML('partials/problem-sidebar-information.html', { pdoc: this.pdoc, owner_udoc }), this.renderHTML('partials/problem-sidebar-information.html', { pdoc: this.pdoc, owner_udoc: owner }),
])).map((i) => ({ html: i })), ])).map((i) => ({ html: i })),
}; };
this.response.template = ''; this.response.template = '';
+17 -17
View File
@@ -1,44 +1,44 @@
const _CACHE_INFO = { const _CACHE_INFO = {
last_s: 0.0, s: 0.0,
last_y: 0, y: 0,
values: [0.0], values: [0.0],
}; };
function _LOGP(x: number) { function _LOGP(x: number) {
const sqrt_2_pi = 2.506628274631000502415765284811; // Sqrt[Pi] const sqrtPi = 2.506628274631000502415765284811; // Sqrt[Pi]
return (2 * Math.exp(-1.0 * (Math.log(x) ** 2) * 2)) / x / sqrt_2_pi; return (2 * Math.exp(-1.0 * (Math.log(x) ** 2) * 2)) / x / sqrtPi;
} }
function _integrate_ensure_cache(y: number) { function _intergrateEnsureCache(y: number) {
let last_y = _CACHE_INFO.last_y; let lastY = _CACHE_INFO.y;
if (y <= last_y) return _CACHE_INFO; if (y <= lastY) return _CACHE_INFO;
let s = _CACHE_INFO.last_s; let s = _CACHE_INFO.s;
const dx = 0.1; const dx = 0.1;
const dT = 2; const dT = 2;
let x0 = (last_y / dT) * dx; let x0 = (lastY / dT) * dx;
while (y > last_y) { while (y > lastY) {
x0 += dx; x0 += dx;
s += _LOGP(x0) * dx; s += _LOGP(x0) * dx;
for (let i = 1; i <= dT; i++) _CACHE_INFO.values.push(s); for (let i = 1; i <= dT; i++) _CACHE_INFO.values.push(s);
last_y += dT; lastY += dT;
} }
_CACHE_INFO.last_y = last_y; _CACHE_INFO.y = lastY;
_CACHE_INFO.last_s = s; _CACHE_INFO.s = s;
return _CACHE_INFO; return _CACHE_INFO;
} }
_integrate_ensure_cache(1000000); _intergrateEnsureCache(1000000);
function _integrate(y: number) { function _integrate(y: number) {
_integrate_ensure_cache(y); _intergrateEnsureCache(y);
return _CACHE_INFO.values[y]; return _CACHE_INFO.values[y];
} }
function difficultyAlgorithm(nSubmit: number, nAccept: number) { function difficultyAlgorithm(nSubmit: number, nAccept: number) {
if (!nSubmit) return null; if (!nSubmit) return null;
const s = _integrate(nSubmit); const s = _integrate(nSubmit);
const ac_rate = nAccept / nSubmit; const acRate = nAccept / nSubmit;
const ans = Math.round(10.0 - 1.30 * s * 10.0 * ac_rate); const ans = Math.round(10.0 - 1.30 * s * 10.0 * acRate);
return Math.max(ans, 1); return Math.max(ans, 1);
} }
+7 -7
View File
@@ -103,16 +103,16 @@ interface RatingOutputUser {
} }
function calculate(users: RatingInputUser[]): RatingOutputUser[] { function calculate(users: RatingInputUser[]): RatingOutputUser[] {
let last_idx = 0; let lastIdx = 0;
let last_rank = 1; let lastRank = 1;
for (let i = 1; i < users.length; i++) { for (let i = 1; i < users.length; i++) {
if (users[i].rank > last_rank) { if (users[i].rank > lastRank) {
for (let j = last_idx; j < i; j++) users[j].rank = i; for (let j = lastIdx; j < i; j++) users[j].rank = i;
last_idx = i; lastIdx = i;
last_rank = users[i].rank; lastRank = users[i].rank;
} }
} }
for (let i = last_idx; i < users.length; i++) { for (let i = lastIdx; i < users.length; i++) {
users[i].rank = users.length; users[i].rank = users.length;
} }
const calculator = new RatingCalculator(users); const calculator = new RatingCalculator(users);
+2 -1
View File
@@ -56,7 +56,8 @@ export async function feedback(): Promise<[string, StatusUpdate]> {
superagent.post(`${system.get('server.center')}/report`) superagent.post(`${system.get('server.center')}/report`)
.send({ installId, payload }) .send({ installId, payload })
.then((res) => { .then((res) => {
if (res.body.updateUrl) system.set('server.center', res.body.updateUrl); if (res.body.updateUrl?.startsWith('https://')) system.set('server.center', res.body.updateUrl);
if (res.body.notification) global.Hydro.model.message.sendNotification(res.body.notification);
}) })
.catch(() => logger.debug('Cannot connect to hydro center.')); .catch(() => logger.debug('Cannot connect to hydro center.'));
return [mid, $update]; return [mid, $update];
+1
View File
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop */
/* eslint-disable @typescript-eslint/naming-convention */
import AdmZip from 'adm-zip'; import AdmZip from 'adm-zip';
import yaml from 'js-yaml'; import yaml from 'js-yaml';
import { pick } from 'lodash'; import { pick } from 'lodash';
+2 -2
View File
@@ -15,7 +15,7 @@ import { Handler, Route } from 'hydrooj/src/service/server';
fs.ensureDirSync('/tmp/hydro/import-qduoj'); fs.ensureDirSync('/tmp/hydro/import-qduoj');
class ImportQduojHandler extends Handler { class ImportQduojHandler extends Handler {
async ImportFromFile(domainId: string, zipfile: string) { async fromFile(domainId: string, zipfile: string) {
const zip = new AdmZip(zipfile); const zip = new AdmZip(zipfile);
const tmp = path.resolve(os.tmpdir(), 'hydro', 'import-qduoj', String.random(32)); const tmp = path.resolve(os.tmpdir(), 'hydro', 'import-qduoj', String.random(32));
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
@@ -121,7 +121,7 @@ class ImportQduojHandler extends Handler {
if (!this.request.files.file) throw new ValidationError('file'); if (!this.request.files.file) throw new ValidationError('file');
const stat = await fs.stat(this.request.files.file.path); const stat = await fs.stat(this.request.files.file.path);
if (stat.size > 128 * 1024 * 1024) throw new ValidationError('file', 'File too large'); if (stat.size > 128 * 1024 * 1024) throw new ValidationError('file', 'File too large');
await this.ImportFromFile(domainId, this.request.files.file.path); await this.fromFile(domainId, this.request.files.file.path);
this.response.redirect = this.url('problem_main'); this.response.redirect = this.url('problem_main');
} }
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/import-qduoj", "name": "@hydrooj/import-qduoj",
"version": "1.3.2", "version": "1.3.3",
"description": "Import QDUOJ problem export", "description": "Import QDUOJ problem export",
"main": "package.json", "main": "package.json",
"repository": "https://github.com/hydro-dev/Hydro.git", "repository": "https://github.com/hydro-dev/Hydro.git",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/vjudge", "name": "@hydrooj/vjudge",
"version": "1.4.11", "version": "1.4.12",
"description": "Submit problems to remote oj", "description": "Submit problems to remote oj",
"main": "package.json", "main": "package.json",
"repository": "https://github.com/hydro-dev/Hydro.git", "repository": "https://github.com/hydro-dev/Hydro.git",
+4 -5
View File
@@ -74,9 +74,8 @@ export default class CodeforcesProvider implements IBasicProvider {
async ensureLogin() { async ensureLogin() {
if (await this.loggedIn) return true; if (await this.loggedIn) return true;
logger.info('retry login'); logger.info('retry login');
const csrf_token = await this.getCsrfToken('/enter');
const res = await this.post('/enter').send({ const res = await this.post('/enter').send({
csrf_token, csrf_token: await this.getCsrfToken('/enter'),
action: 'enter', action: 'enter',
ftaa: '', ftaa: '',
bfaa: '', bfaa: '',
@@ -197,10 +196,10 @@ export default class CodeforcesProvider implements IBasicProvider {
const [, contestId, submittedProblemIndex] = id.startsWith('P921') const [, contestId, submittedProblemIndex] = id.startsWith('P921')
? ['', '921', id.split('P921')[1]] ? ['', '921', id.split('P921')[1]]
: /^P(\d+)([A-Z][0-9]*)$/.exec(id); : /^P(\d+)([A-Z][0-9]*)$/.exec(id);
const csrf_token = await this.getCsrfToken('/problemset/submit'); const csrf = await this.getCsrfToken('/problemset/submit');
// TODO check submit time to ensure submission // TODO check submit time to ensure submission
await this.post(`/problemset/submit?csrf_token=${csrf_token}`).send({ await this.post(`/problemset/submit?csrf_token=${csrf}`).send({
csrf_token, csrf_token: csrf,
contestId, contestId,
action: 'submitSolutionFormSubmitted', action: 'submitSolutionFormSubmitted',
programTypeId, programTypeId,