Fix all 93 ESLint issues (3 errors, 90 warnings) (#666)

This commit is contained in:
Thomas Durieux
2026-04-15 09:04:22 +02:00
committed by GitHub
parent 1d97c76e7e
commit f4209110c7
28 changed files with 77 additions and 69 deletions
+2 -2
View File
@@ -80,8 +80,8 @@ const config: Config = {
};
for (const conf in process.env) {
if ((config as any)[conf] !== undefined) {
(config as any)[conf] = process.env[conf];
if ((config as unknown as Record<string, unknown>)[conf] !== undefined) {
(config as unknown as Record<string, string | undefined>)[conf] = process.env[conf];
}
}
+1 -1
View File
@@ -246,7 +246,7 @@ export default class AnonymizedFile {
anonymizerOptions: anonymizer.opt,
},
})
.on("error", (err) => {
.on("error", (_err) => {
handleError(
new AnonymousError("file_not_found", {
object: this,
+2 -2
View File
@@ -9,7 +9,7 @@ import User from "./User";
* Custom error message
*/
export default class AnonymousError extends CustomError {
value?: any;
value?: unknown;
httpStatus?: number;
cause?: Error;
@@ -18,7 +18,7 @@ export default class AnonymousError extends CustomError {
opt?: {
httpStatus?: number;
cause?: Error;
object?: any;
object?: unknown;
}
) {
super(message);
+2 -2
View File
@@ -16,7 +16,7 @@ export default class Conference {
* @param status the new status
* @param errorMessage a potential error message to display
*/
async updateStatus(status: ConferenceStatus, errorMessage?: string) {
async updateStatus(status: ConferenceStatus, _errorMessage?: string) {
this._data.status = status;
await this._data.save();
return;
@@ -104,7 +104,7 @@ export default class Conference {
return this._data.options;
}
toJSON(opt?: { billing: boolean }): any {
toJSON(_opt?: { billing: boolean }): Record<string, unknown> {
const pricePerHourPerRepo = this._data.plan.pricePerRepository / 30;
let price = 0;
const today =
+1 -2
View File
@@ -3,7 +3,6 @@ import { Octokit } from "@octokit/rest";
import Repository from "./Repository";
import UserModel from "./model/users/users.model";
import config from "../config";
import { RepositoryStatus } from "./types";
export function octokit(token: string) {
return new Octokit({
@@ -19,7 +18,7 @@ export async function checkToken(token: string) {
try {
await oct.users.getAuthenticated();
return true;
} catch (error) {
} catch {
return false;
}
}
+3 -3
View File
@@ -37,7 +37,7 @@ export default class PullRequest {
if (this._model.source.accessToken) {
try {
return this._model.source.accessToken;
} catch (error) {
} catch {
console.debug(
"[ERROR] Token is invalid",
this._model.source.pullRequestId
@@ -240,7 +240,7 @@ export default class PullRequest {
}
content() {
const output: any = {
const output: Record<string, unknown> = {
anonymizeDate: this._model.anonymizeDate,
merged: this._model.pullRequest.merged,
mergedDate: this._model.pullRequest.mergedDate,
@@ -259,7 +259,7 @@ export default class PullRequest {
}
if (this.options.comments) {
output.comments = this._model.pullRequest.comments?.map((comment) => {
const o: any = {};
const o: Record<string, unknown> = {};
if (this.options.body) o.body = anonymizer.anonymize(comment.body);
if (this.options.username)
o.author = anonymizer.anonymize(comment.author);
-1
View File
@@ -1,5 +1,4 @@
import { model } from "mongoose";
import { join } from "path";
import { IFileDocument, IFileModel } from "./files.types";
import FileSchema from "./files.schema";
+1 -1
View File
@@ -31,7 +31,7 @@ export default class GitHubDownload extends GitHubBase {
response = await this.getZipUrl();
} catch (error) {
throw new AnonymousError("repo_not_found", {
httpStatus: (error as any).status || 404,
httpStatus: (error as { status?: number }).status || 404,
object: this.data,
cause: error as Error,
});
+3 -3
View File
@@ -99,7 +99,7 @@ export class GitHubRepository {
}
} catch (error) {
throw new AnonymousError("repo_not_found", {
httpStatus: (error as any).status,
httpStatus: (error as { status?: number }).status,
cause: error as Error,
object: this,
});
@@ -212,7 +212,7 @@ export async function getRepositoryFromGitHub(opt: {
if (opt.repo.indexOf(".git") > -1) {
opt.repo = opt.repo.replace(".git", "");
}
let dbModel = null;
let dbModel;
if (opt.repositoryID) {
dbModel = isConnected
? await RepositoryModel.findById(opt.repositoryID)
@@ -255,7 +255,7 @@ export async function getRepositoryFromGitHub(opt: {
});
}
throw new AnonymousError("repo_not_found", {
httpStatus: (error as any).status,
httpStatus: (error as { status?: number }).status,
object: {
owner: opt.owner,
repo: opt.repo,
+5 -5
View File
@@ -70,7 +70,7 @@ export default class GitHubStream extends GitHubBase {
content.on("error", (error) => {
error = new AnonymousError("file_not_found", {
httpStatus: (error as any).status || (error as any).httpStatus,
httpStatus: (error as { status?: number; httpStatus?: number }).status || (error as { httpStatus?: number }).httpStatus,
cause: error as Error,
object: filePath,
});
@@ -85,7 +85,7 @@ export default class GitHubStream extends GitHubBase {
async getFileContent(file: AnonymizedFile): Promise<stream.Readable> {
try {
void file.filePath;
} catch (_) {
} catch {
// compute the original path if ambiguous
await file.originalPath();
}
@@ -139,7 +139,7 @@ export default class GitHubStream extends GitHubBase {
file: 0,
};
const output: IFile[] = [];
let data = null;
let data;
try {
data = await this.getGHTree(sha, count, {
recursive: false,
@@ -152,12 +152,12 @@ export default class GitHubStream extends GitHubBase {
output.push(...this.tree2Tree(data.tree, parentPath));
} catch (error) {
console.log(error);
if ((error as any).status == 409 || (error as any).status == 404) {
if ((error as { status?: number }).status == 409 || (error as { status?: number }).status == 404) {
// empty repo
data = { tree: [] };
} else {
throw new AnonymousError("repo_not_found", {
httpStatus: (error as any).status || 404,
httpStatus: (error as { status?: number }).status || 404,
object: this.data,
cause: error as Error,
});
+2 -1
View File
@@ -8,6 +8,7 @@ export default class Zip implements SourceBase {
type = "Zip";
url?: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(data: any, readonly repoId: string) {
this.url = data.url;
}
@@ -28,7 +29,7 @@ export default class Zip implements SourceBase {
return storage.read(file.repository.repoId, file.filePath);
}
toJSON(): any {
toJSON(): { type: string } {
return {
type: this.type,
};
+7 -7
View File
@@ -25,7 +25,7 @@ export default class FileSystem extends StorageBase {
const stat = await fs.promises.stat(fullPath);
if (stat.isDirectory()) return FILE_TYPE.FOLDER;
if (stat.isFile()) return FILE_TYPE.FILE;
} catch (_) {
} catch {
// ignore file not found or not downloaded
}
return FILE_TYPE.NOT_FOUND;
@@ -65,13 +65,13 @@ export default class FileSystem extends StorageBase {
try {
await this.mk(repoId, dirname(p));
if (data instanceof Readable) {
data.on("error", (err) => {
data.on("error", (_err) => {
this.rm(repoId, p);
});
}
return await fs.promises.writeFile(fullPath, data, "utf-8");
} catch (err: any) {
// throw err;
} catch {
// write error ignored
}
}
@@ -91,8 +91,8 @@ export default class FileSystem extends StorageBase {
await fs.promises.mkdir(fullPath, {
recursive: true,
});
} catch (err: any) {
if (err.code !== "EEXIST") {
} catch (err: unknown) {
if (err instanceof Error && (err as NodeJS.ErrnoException).code !== "EEXIST") {
throw err;
}
}
@@ -135,7 +135,7 @@ export default class FileSystem extends StorageBase {
})
);
}
} catch (error) {
} catch {
// ignore stat errors for individual files
}
}
+3 -3
View File
@@ -55,7 +55,7 @@ export default class S3Storage extends StorageBase {
// if we can get the file info, it is a file
await this.fileInfo(repoId, path);
return FILE_TYPE.FILE;
} catch (err) {
} catch {
// check if it is a directory
const data = await this.client().listObjectsV2({
Bucket: config.S3_BUCKET,
@@ -69,7 +69,7 @@ export default class S3Storage extends StorageBase {
}
/** @override */
async mk(repoId: string, dir: string = ""): Promise<void> {
async mk(repoId: string, _dir: string = ""): Promise<void> {
// no need to create folder on S3
}
@@ -125,7 +125,7 @@ export default class S3Storage extends StorageBase {
} else {
res.end();
}
} catch (error) {
} catch {
try {
res.status(500);
} catch (err) {
+6 -5
View File
@@ -14,11 +14,12 @@ export default async function (job: SandboxedJob<Repository, void>) {
getRepository: typeof getRepositoryImport;
} = require("../../server/database");
console.log(`[QUEUE] ${job.data.repoId} is going to be downloaded`);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let statusInterval: any = null;
await connect();
const repo = await getRepository(job.data.repoId);
try {
let progress: any = null;
let progress: { status: string } | null = null;
statusInterval = setInterval(async () => {
try {
if (
@@ -37,7 +38,7 @@ export default async function (job: SandboxedJob<Repository, void>) {
);
await repo.updateStatus(repo.status, progress?.status || "");
}
} catch (_) {
} catch {
// ignore error
}
}, 1000);
@@ -61,14 +62,14 @@ export default async function (job: SandboxedJob<Repository, void>) {
}
throw error;
}
} catch (error: any) {
} catch (error: unknown) {
clearInterval(statusInterval);
console.log(`[QUEUE] ${job.data.repoId} is finished with an error`, error);
setTimeout(async () => {
// delay to avoid double saving
try {
await repo.updateStatus(RepositoryStatus.ERROR, error.message);
} catch (ignore) {}
await repo.updateStatus(RepositoryStatus.ERROR, (error as Error).message);
} catch { /* ignored */ }
}, 400);
} finally {
clearInterval(statusInterval);
+1 -1
View File
@@ -17,7 +17,7 @@ export default async function (job: SandboxedJob<Repository, void>) {
);
const repo = await getRepository(job.data.repoId);
await repo.removeCache();
} catch (error) {
} catch {
// error already handled
} finally {
console.log(`[QUEUE] Cache of ${job.data.repoId} is removed.`);
+1 -1
View File
@@ -26,7 +26,7 @@ export default async function (job: SandboxedJob<Repository, void>) {
}
throw error;
}
} catch (error) {
} catch {
// error already handled
} finally {
console.log(`[QUEUE] ${job.data.repoId} is removed`);
+1 -1
View File
@@ -24,7 +24,7 @@ export async function connect() {
return database;
}
export async function getRepository(repoId: string, opts: {} = {}) {
export async function getRepository(repoId: string, _opts: {} = {}) {
if (!repoId || repoId == "undefined") {
throw new AnonymousError("repo_not_found", {
object: repoId,
+6 -6
View File
@@ -89,20 +89,20 @@ export default async function start() {
sendCommand: (...args: string[]) => redisClient.sendCommand(args),
}),
windowMs: 15 * 60 * 1000, // 15 minutes
skip: async (request: express.Request, response: express.Response) => {
skip: async (request: express.Request, _response: express.Response) => {
try {
const user = await getUser(request);
if (user && user.isAdmin) return true;
} catch (_) {
} catch {
// ignore: user not connected
}
return false;
},
max: async (request: express.Request, response: express.Response) => {
max: async (request: express.Request, _response: express.Response) => {
try {
const user = await getUser(request);
if (user) return config.RATE_LIMIT;
} catch (_) {
} catch {
// ignore: user not connected
}
// if not logged in, limit to half the rate
@@ -111,7 +111,7 @@ export default async function start() {
keyGenerator,
standardHeaders: true,
legacyHeaders: false,
message: (request: express.Request, response: express.Response) => {
message: (_request: express.Request, _response: express.Response) => {
return `You can only make ${config.RATE_LIMIT} requests every 15min. Please try again later.`;
},
});
@@ -167,7 +167,7 @@ export default async function start() {
res.sendStatus(404);
});
let stat: any = {};
let stat: Record<string, unknown> = {};
setInterval(() => {
stat = {};
+5 -2
View File
@@ -51,14 +51,14 @@ router.post("/queue/:name/:repo_id", async (req, res) => {
await job.retry();
res.send("ok");
} catch (error) {
} catch {
try {
if (job) {
await job.remove();
queue.add(job.name, job.data, job.opts);
}
res.send("ok");
} catch (error) {
} catch {
res.status(500).send("error_retrying_job");
}
}
@@ -121,6 +121,7 @@ router.get("/repos", async (req, res) => {
const remove = req.query.removed == "true";
const expired = req.query.expired == "true";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let sort: any = { _id: 1 };
if (req.query.sort) {
sort = {};
@@ -190,6 +191,7 @@ router.get("/users", async (req, res) => {
const limit = parseInt(req.query.limit as string) || 10;
const skipIndex = (page - 1) * limit;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let sort: any = { _id: 1 };
if (req.query.sort) {
sort = {};
@@ -260,6 +262,7 @@ router.get("/conferences", async (req, res) => {
const limit = parseInt(req.query.limit as string) || 10;
const skipIndex = (page - 1) * limit;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let sort: any = { _id: 1 };
if (req.query.sort) {
sort = {};
+3 -1
View File
@@ -67,6 +67,7 @@ router.get("/", async (req: express.Request, res: express.Response) => {
}
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function validateConferenceForm(conf: any) {
if (!conf.name)
throw new AnonymousError("conf_name_missing", {
@@ -237,12 +238,13 @@ router.get(
const conference = new Conference(data);
try {
isOwnerOrAdmin(conference.ownerIDs, user);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const o: any = conference.toJSON();
o.repositories = (await conference.repositories()).map((r) =>
r.toJSON()
);
res.json(o);
} catch (error) {
} catch {
return res.json({
conferenceID: conference.conferenceID,
name: conference.name,
+1 -1
View File
@@ -29,7 +29,7 @@ const verify = async (
profile: Profile,
done: OAuth2Strategy.VerifyCallback
): Promise<void> => {
let user: IUserDocument | null = null;
let user: IUserDocument | null;
try {
user = await UserModel.findOne({ "externalIDs.github": profile.id });
if (user) {
+2
View File
@@ -98,6 +98,7 @@ router.get(
}
);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function validateNewPullRequest(pullRequestUpdate: any): void {
const validCharacters = /^[0-9a-zA-Z\-_]+$/;
if (
@@ -146,6 +147,7 @@ function validateNewPullRequest(pullRequestUpdate: any): void {
function updatePullRequestModel(
model: IAnonymizedPullRequestDocument,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
pullRequestUpdate: any
) {
model.options = {
+4
View File
@@ -39,6 +39,7 @@ async function getTokenForAdmin(user: User, req: express.Request) {
path: "owner",
model: UserModel,
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const user: IUserDocument = existingRepo?.owner as any;
if (user instanceof UserModel) {
const check = await checkToken(user.accessTokens.github);
@@ -280,6 +281,7 @@ router.get("/:repoId/", async (req: express.Request, res: express.Response) => {
}
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function validateNewRepo(repoUpdate: any): void {
const validCharacters = /^[0-9a-zA-Z\-_]+$/;
if (
@@ -325,6 +327,7 @@ function validateNewRepo(repoUpdate: any): void {
function updateRepoModel(
model: IAnonymizedRepositoryDocument,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
repoUpdate: any
) {
if (repoUpdate.source.type) {
@@ -485,6 +488,7 @@ router.post("/", async (req: express.Request, res: express.Response) => {
httpStatus: 400,
object: repoUpdate,
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
if (error.message == "repo_not_found") {
// the repository does not exist yet
+2 -2
View File
@@ -31,7 +31,7 @@ router.get(
let user: User | undefined = undefined;
try {
user = await getUser(req);
} catch (_) {}
} catch { /* not logged in */ }
let download = false;
if (
@@ -187,7 +187,7 @@ router.get(
let user: User | undefined = undefined;
try {
user = await getUser(req);
} catch (_) {}
} catch { /* not logged in */ }
res.json({
url: redirectURL,
download: download || user?.isAdmin === true,
+5 -4
View File
@@ -13,8 +13,7 @@ export async function getPullRequest(
) {
try {
const pullRequest = await db.getPullRequest(req.params.pullRequestId);
if (opt?.nocheck == true) {
} else {
if (opt?.nocheck !== true) {
// redirect if the repository is expired
if (
pullRequest.status == "expired" &&
@@ -44,8 +43,7 @@ export async function getRepo(
) {
try {
const repo = await db.getRepository(req.params.repoId);
if (opt.nocheck == true) {
} else {
if (opt.nocheck !== true) {
// redirect if the repository is expired
if (
repo.status == RepositoryStatus.EXPIRED &&
@@ -73,6 +71,7 @@ export function isOwnerOrAdmin(authorizedUsers: string[], user: User) {
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function printError(error: any, req?: express.Request) {
if (error instanceof AnonymousError) {
let message = `[ERROR] ${error.toString()} ${error.stack
@@ -97,6 +96,7 @@ function printError(error: any, req?: express.Request) {
}
export function handleError(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
error: any,
res?: express.Response,
req?: express.Request
@@ -139,6 +139,7 @@ export async function getUser(req: express.Request) {
if (!req.user) {
notConnected();
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const user = (req.user as any).user;
if (!user) {
notConnected();
+1 -1
View File
@@ -88,7 +88,7 @@ async function webView(req: express.Request, res: express.Response) {
let info: IFile | null = null;
try {
info = await f.getFileInfo();
} catch (error) {}
} catch { /* ignored */ }
if (
req.headers.accept?.includes("text/html") &&
(filePath == "" || (info && info.size == null))
+3 -3
View File
@@ -6,7 +6,7 @@ import Repository from "../core/Repository";
export function conferenceStatusCheck() {
// check every 6 hours the status of the conferences
const job = schedule.scheduleJob("0 */6 * * *", async () => {
schedule.scheduleJob("0 */6 * * *", async () => {
(await ConferenceModel.find({ status: { $eq: "ready" } })).forEach(
async (data) => {
const conference = new Conference(data);
@@ -24,7 +24,7 @@ export function conferenceStatusCheck() {
export function repositoryStatusCheck() {
// check every 6 hours the status of the repositories
const job = schedule.scheduleJob("0 */6 * * *", async () => {
schedule.scheduleJob("0 */6 * * *", async () => {
console.log("[schedule] Check repository status and unused repositories");
(
await AnonymizedRepositoryModel.find({
@@ -35,7 +35,7 @@ export function repositoryStatusCheck() {
const repo = new Repository(data);
try {
repo.check();
} catch (error) {
} catch {
console.log(`Repository ${repo.repoId} is expired`);
}
const fourMonthAgo = new Date();
+4 -8
View File
@@ -1,5 +1,3 @@
import { promisify } from "util";
import * as stream from "stream";
import * as express from "express";
import GitHubStream from "../core/source/GitHubStream";
import {
@@ -22,7 +20,6 @@ router.post(
const token: string = req.body.token;
const repoFullName = req.body.repoFullName.split("/");
const repoId = req.body.repoId;
const branch = req.body.branch;
const commit = req.body.commit;
const anonymizerOptions = req.body.anonymizerOptions;
@@ -52,12 +49,12 @@ router.post(
console.error(error);
try {
archive.finalize();
} catch (error) {}
} catch { /* ignored */ }
})
.on("close", () => {
try {
archive.finalize();
} catch (error) {}
} catch { /* ignored */ }
})
.pipe(Parse())
.on("entry", (entry) => {
@@ -83,12 +80,12 @@ router.post(
console.error(error);
try {
archive.finalize();
} catch (error) {}
} catch { /* ignored */ }
})
.on("finish", () => {
try {
archive.finalize();
} catch (error) {}
} catch { /* ignored */ }
});
archive.pipe(res).on("error", (error) => {
console.error(error);
@@ -104,7 +101,6 @@ router.post("/", async (req: express.Request, res: express.Response) => {
const token: string = req.body.token;
const repoFullName = req.body.repoFullName.split("/");
const repoId = req.body.repoId;
const branch = req.body.branch;
const fileSha = req.body.sha;
const commit = req.body.commit;
const filePath = req.body.filePath;