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 authored and GitHub committed 2023-01-20 18:10:47 +11:00
1 parent 0c815fde91
commit 084dc0be08
157 files changed
+737 -666

No files matched your search

@@ -32,7 +32,7 @@ router.get(
? parseInt(req.query.length as string)
: 255;
let tokens: ValidRegistrationToken[] = [];
const tokens: ValidRegistrationToken[] = [];
for (let i = 0; i < count; i++) {
const token = ValidRegistrationToken.create({
+1 -1
View File
@@ -74,7 +74,7 @@ router.post(
"totp_secret",
"mfa_enabled",
],
}).catch((e) => {
}).catch(() => {
throw FieldErrors({
login: {
message: req.t("auth:login.INVALID_LOGIN"),
+3 -3
View File
@@ -27,8 +27,8 @@ router.post(
"/",
route({ body: "TotpSchema" }),
async (req: Request, res: Response) => {
const { code, ticket, gift_code_sku_id, login_source } =
req.body as TotpSchema;
// const { code, ticket, gift_code_sku_id, login_source } =
const { code, ticket } = req.body as TotpSchema;
const user = await User.findOneOrFail({
where: {
@@ -47,7 +47,7 @@ router.post(
});
if (!backup) {
const ret = verifyToken(user.totp_secret!, code);
const ret = verifyToken(user.totp_secret || "", code);
if (!ret || ret.delta != 0)
throw new HTTPError(
req.t("auth:login.INVALID_TOTP_CODE"),
+5 -5
View File
@@ -36,7 +36,7 @@ import {
} from "@fosscord/api";
import bcrypt from "bcrypt";
import { HTTPError } from "lambert-server";
import { LessThan, MoreThan } from "typeorm";
import { MoreThan } from "typeorm";
const router: Router = Router();
@@ -53,12 +53,12 @@ router.post(
let regTokenUsed = false;
if (req.get("Referrer") && req.get("Referrer")?.includes("token=")) {
// eg theyre on https://staging.fosscord.com/register?token=whatever
const token = req.get("Referrer")!.split("token=")[1].split("&")[0];
const token = req.get("Referrer")?.split("token=")[1].split("&")[0];
if (token) {
const regToken = await ValidRegistrationToken.findOne({
const regToken = await ValidRegistrationToken.findOneOrFail({
where: { token, expires_at: MoreThan(new Date()) },
});
await ValidRegistrationToken.delete({ token });
await regToken.remove();
regTokenUsed = true;
console.log(
`[REGISTER] Registration token ${token} used for registration!`,
@@ -71,7 +71,7 @@ router.post(
}
// email will be slightly modified version of the user supplied email -> e.g. protection against GMail Trick
let email = adjustEmail(body.email);
const email = adjustEmail(body.email);
// check if registration is allowed
if (!regTokenUsed && !register.allowNewRegistration) {