eslint: add github/array-foreach rule

This commit is contained in:
undefined committed 2023-10-20 20:59:48 +08:00
1 parent 9901ffa62d
commit 335a272db4
21 files changed
+59 -51

No files matched your search

+3 -3
View File
@@ -20,13 +20,13 @@ export default async function readYamlCases(cfg: Record<string, any> = {}, check
}
if (cfg.interactor) config.interactor = checkFile(cfg.interactor, 'Cannot find interactor {0}.');
if (cfg.validator) config.validator = checkFile(cfg.validator, 'Cannot find validator {0}.');
['judge', 'user'].forEach((n) => {
for (const n of ['judge', 'user']) {
const conf = cfg[`${n}_extra_files`];
if (!conf) return;
if (!conf) continue;
if (conf instanceof Array) {
config[`${n}_extra_files`] = conf.map((file) => checkFile(file, `Cannot find ${n} extra file {0}.`));
} else throw new Error(`Invalid ${n}_extra_files config.`);
});
}
}
if (cfg.cases?.length) {
config.subtasks = [{
+1 -1
View File
@@ -27,7 +27,7 @@ export interface LangConfig {
export function parseLang(config: string): Record<string, LangConfig> {
const file = yaml.load(config) as Record<string, LangConfig>;
if (typeof file === 'undefined' || typeof file === 'string' || typeof file === 'number') throw new Error();
Object.keys(file).filter((i) => i.startsWith('_')).forEach((k) => delete file[k]);
for (const key of Object.keys(file)) if (key.startsWith('_')) delete file[key];
for (const key in file) {
const entry = file[key];
if (key.includes('.')) {
+3 -5
View File
@@ -36,9 +36,7 @@ export function folderSize(folderPath: string) {
size += stats.size;
const files = fs.readdirSync(p);
if (Array.isArray(files)) {
files.forEach((file) => {
_next(path.join(p, file));
});
for (const file of files) _next(path.join(p, file));
}
}
}
@@ -247,9 +245,9 @@ export function CallableInstance(property = '__call__') {
else func = this.constructor.prototype[property];
const apply = function __call__(...args) { return func.apply(apply, ...args); };
Object.setPrototypeOf(apply, this.constructor.prototype);
Object.getOwnPropertyNames(func).forEach((p) => {
for (const p of Object.getOwnPropertyNames(func)) {
Object.defineProperty(apply, p, Object.getOwnPropertyDescriptor(func, p));
});
}
return apply;
}