Add ESLint (#941)

* Add eslint, switch to lint-staged for precommit

* Fix all ESLint errors

* Update GH workflow to check prettier and eslint
This commit is contained in:
Madeline
2023-01-20 18:10:47 +11:00
committed by GitHub
parent 0c815fde91
commit 084dc0be08
157 changed files with 1905 additions and 668 deletions
+6 -4
View File
@@ -54,11 +54,12 @@ export const API_PREFIX = /^\/api(\/v\d+)?/;
export const API_PREFIX_TRAILING_SLASH = /^\/api(\/v\d+)?\//;
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Express {
interface Request {
user_id: string;
user_bot: boolean;
token: string;
token: { id: string; iat: number };
rights: Rights;
}
}
@@ -87,7 +88,7 @@ export async function Authentication(
try {
const { jwtSecret } = Config.get().security;
const { decoded, user }: any = await checkToken(
const { decoded, user } = await checkToken(
req.headers.authorization,
jwtSecret,
);
@@ -97,7 +98,8 @@ export async function Authentication(
req.user_bot = user.bot;
req.rights = new Rights(Number(user.rights));
return next();
} catch (error: any) {
return next(new HTTPError(error?.toString(), 400));
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return next(new HTTPError(error!.toString(), 400));
}
}
+4 -8
View File
@@ -42,7 +42,7 @@ type RateLimit = {
expires_at: Date;
};
let Cache = new Map<string, RateLimit>();
const Cache = new Map<string, RateLimit>();
const EventRateLimit = "RATELIMIT";
export default function rateLimit(opts: {
@@ -57,12 +57,8 @@ export default function rateLimit(opts: {
error?: boolean;
success?: boolean;
onlyIp?: boolean;
}): any {
return async (
req: Request,
res: Response,
next: NextFunction,
): Promise<any> => {
}) {
return async (req: Request, res: Response, next: NextFunction) => {
// exempt user? if so, immediately short circuit
if (req.user_id) {
const rights = await getRights(req.user_id);
@@ -85,7 +81,7 @@ export default function rateLimit(opts: {
)
max_hits = opts.MODIFY;
let offender = Cache.get(executor_id + bucket_id);
const offender = Cache.get(executor_id + bucket_id);
if (offender) {
let reset = offender.expires_at.getTime();