workspace: update eslint rule (#1027)

This commit is contained in:
undefined authored and GitHub committed 2025-08-06 18:51:25 +01:00
1 parent 05c3b8f2bd
commit cee3c00ddb
150 files changed
+1069 -1043

No files matched your search

+2 -2
View File
@@ -10,7 +10,7 @@ import esbuild from 'esbuild';
declare module 'hydrooj' {
interface UI {
esbuildPlugins?: esbuild.Plugin[]
esbuildPlugins?: esbuild.Plugin[];
}
interface SystemKeys {
'ui-default.nav_logo_dark': string;
@@ -91,7 +91,7 @@ export async function buildUI() {
const entryPoints: string[] = [];
const lazyModules: string[] = [];
const newFiles = ['entry.js'];
for (const addon of Object.values(global.addons)) {
for (const addon of Object.values(global.addons) as string[]) {
let publicPath = resolve(addon, 'frontend');
if (!fs.existsSync(publicPath)) publicPath = resolve(addon, 'public');
if (!fs.existsSync(publicPath)) continue;
@@ -8,7 +8,7 @@ function parseNextNumber(str, pos, max) {
value: '',
};
let code = str.charCodeAt(pos);
while (pos < max && (code >= 0x30 /* 0 */ && code <= 0x39 /* 9 */) || code === 0x25 /* % */) {
while (pos < max && ((code >= 0x30 /* 0 */ && code <= 0x39 /* 9 */) || code === 0x25 /* % */)) {
code = str.charCodeAt(++pos);
}
result.ok = true;
@@ -24,9 +24,9 @@ function parseImageSize(str, pos, max) {
width: '',
height: '',
};
if (pos >= max) { return result; }
if (pos >= max) return result;
let code = str.charCodeAt(pos);
if (code !== 0x3d /* = */) { return result; }
if (code !== 0x3D /* = */) return result;
pos++;
code = str.charCodeAt(pos);
if (code !== 0x78 /* x */ && (code < 0x30 || code > 0x39) /* [0-9] */) {
@@ -67,14 +67,14 @@ export default function plugin(md) {
const oldPos = state.pos;
const max = state.posMax;
if (state.src.charCodeAt(state.pos) !== 0x21/* ! */) { return false; }
if (state.src.charCodeAt(state.pos + 1) !== 0x5B/* [ */) { return false; }
if (state.src.charCodeAt(state.pos) !== 0x21/* ! */) return false;
if (state.src.charCodeAt(state.pos + 1) !== 0x5B/* [ */) return false;
const labelStart = state.pos + 2;
const labelEnd = md.helpers.parseLinkLabel(state, state.pos + 1, false);
// parser failed to find ']', so it's not a valid link
if (labelEnd < 0) { return false; }
if (labelEnd < 0) return false;
pos = labelEnd + 1;
if (pos < max && state.src.charCodeAt(pos) === 0x28/* ( */) {
@@ -89,7 +89,7 @@ export default function plugin(md) {
code = state.src.charCodeAt(pos);
if (code !== 0x20 && code !== 0x0A) { break; }
}
if (pos >= max) { return false; }
if (pos >= max) return false;
// [link]( <href> "title" )
// ^^^^^^ parsing link destination
@@ -162,7 +162,7 @@ export default function plugin(md) {
//
// Link reference
//
if (typeof state.env.references === 'undefined') { return false; }
if (typeof state.env.references === 'undefined') return false;
// [foo] [bar]
// ^^ optional whitespace (can include newlines)
@@ -112,7 +112,7 @@ export default function plugin(md) {
const render = (latex: string, displayMode = false) => {
options.displayMode = displayMode;
try {
latex = latex.replace(/\\def{\\([a-zA-Z0-9]+)}/g, '\\def\\$1');
latex = latex.replace(/\\def\{\\([a-zA-Z0-9]+)\}/g, '\\def\\$1');
return katex.renderToString(latex, options);
} catch (error) {
if (options.throwOnError) console.error(error);
@@ -1,4 +1,7 @@
/* eslint-disable max-len */
/* eslint-disable regexp/prefer-question-quantifier */
/* eslint-disable regexp/no-useless-non-capturing-group */
/* eslint-disable regexp/optimal-quantifier-concatenation */
import type MarkdownIt from 'markdown-it';
import { v4 as uuid } from 'uuid';
@@ -10,6 +13,7 @@ function youtubeParser(url: string) {
const match = url.match(ytRegex);
return match && match[7].length === 11 ? match[7] : url;
}
// eslint-disable-next-line regexp/no-empty-alternative
const vimeoRegex = /https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^/]*)\/videos\/|album\/(\d+)\/video\/|)(\d+)(?:$|\/|\?)/;
function vimeoParser(url: string) {
const match = url.match(vimeoRegex);
@@ -25,7 +29,7 @@ function preziParser(url: string) {
const match = url.match(preziRegex);
return match ? match[1] : url;
}
const EMBED_REGEX = /@\[([a-zA-Z].+?)]\((.*?)[)]/im;
const EMBED_REGEX = /@\[([a-zA-Z].+?)\]\((.*?)\)/;
function extractVideoParameters(url: string) {
const parameterMap = new Map();
const params = url.replace(/&amp;/gi, '&').split(/[#?&]/);
@@ -83,7 +87,7 @@ declare module 'hydrooj' {
interface ModuleInterfaces {
richmedia: {
get: (service: string, src: string, md: MarkdownIt) => string | null;
}
};
}
}
@@ -19,7 +19,7 @@ const depedentTags = {
dt: ['dl'],
dd: ['dl'],
};
const whitelistClasses = ['row', 'columns', 'typo', 'note', 'warn'].concat(new Array(12).fill(0).map((_, i) => `medium-${i + 1}`));
const whitelistClasses = ['row', 'columns', 'typo', 'note', 'warn'].concat(Array.from({ length: 12 }).fill(0).map((_, i) => `medium-${i + 1}`));
const tagCheck = new FilterXSS({
css: false,
+1 -1
View File
@@ -1,7 +1,7 @@
import { moment, ObjectId } from 'hydrooj';
import { AnsiUp } from 'ansi_up';
export { size, formatSeconds } from 'hydrooj';
export { formatSeconds, size } from 'hydrooj';
const AU = new AnsiUp();
+3 -3
View File
@@ -30,7 +30,7 @@ async function getFiles(folder: string, base = ''): Promise<string[]> {
files.push(...await getFiles(path.join(folder, i), path.join(base, i)));
} else files.push(path.join(base, i));
}
return files.map((item) => item.replace(/\\/gmi, '/'));
return files.map((item) => item.replace(/\\/g, '/'));
}
function locateFile(basePath: string, filenames: string[]) {
@@ -47,7 +47,7 @@ nunjucks.runtime.memberLookup = function memberLookup(obj, val) {
if (obj === undefined || obj === null) return undefined;
if (typeof obj[val] === 'function') {
const fn = function (...args) {
return obj[val].call(obj, ...args);
return obj[val].call(obj, ...args); // eslint-disable-line no-useless-call
};
fn._original = obj[val];
return fn;
@@ -255,7 +255,7 @@ export class TemplateService extends Service {
const pending = Object.values(global.addons);
const logger = this.ctx.logger('template');
for (const i of pending) {
const p = locateFile(i, ['template', 'templates']);
const p = locateFile(i as string, ['template', 'templates']);
if (p && (await fs.stat(p)).isDirectory()) {
try {
const files = await getFiles(p);