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
+1 -1
View File
@@ -17,7 +17,7 @@
*/
import { Router, Request, Response } from "express";
import { Guild, Member, User } from "@fosscord/util";
import { Member, User } from "@fosscord/util";
import { route } from "@fosscord/api";
import bcrypt from "bcrypt";
import { HTTPError } from "lambert-server";
@@ -43,7 +43,7 @@ router.patch(
const body = req.body as UserGuildSettingsSchema;
if (body.channel_overrides) {
for (var channel in body.channel_overrides) {
for (const channel in body.channel_overrides) {
Channel.findOneOrFail({ where: { id: channel } });
}
}
+4 -3
View File
@@ -55,7 +55,7 @@ router.patch(
});
// Populated on password change
var newToken: string | undefined;
let newToken: string | undefined;
if (body.avatar)
body.avatar = await handleFile(
@@ -120,7 +120,7 @@ router.patch(
}
if (body.username) {
var check_username = body?.username?.replace(/\s/g, "");
const check_username = body?.username?.replace(/\s/g, "");
if (!check_username) {
throw FieldErrors({
username: {
@@ -153,7 +153,8 @@ router.patch(
user.validate();
await user.save();
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
delete user.data;
// TODO: send update member list event in gateway
@@ -23,6 +23,7 @@ import {
generateMfaBackupCodes,
User,
CodesVerificationSchema,
DiscordApiErrors,
} from "@fosscord/util";
const router = Router();
@@ -31,14 +32,17 @@ router.post(
"/",
route({ body: "CodesVerificationSchema" }),
async (req: Request, res: Response) => {
const { key, nonce, regenerate } = req.body as CodesVerificationSchema;
// const { key, nonce, regenerate } = req.body as CodesVerificationSchema;
const { regenerate } = req.body as CodesVerificationSchema;
// TODO: We don't have email/etc etc, so can't send a verification code.
// Once that's done, this route can verify `key`
const user = await User.findOneOrFail({ where: { id: req.user_id } });
// const user = await User.findOneOrFail({ where: { id: req.user_id } });
if ((await User.count({ where: { id: req.user_id } })) === 0)
throw DiscordApiErrors.UNKNOWN_USER;
var codes: BackupCode[];
let codes: BackupCode[];
if (regenerate) {
await BackupCode.update(
{ user: { id: req.user_id } },
+1 -1
View File
@@ -51,7 +51,7 @@ router.post(
});
}
var codes: BackupCode[];
let codes: BackupCode[];
if (regenerate) {
await BackupCode.update(
{ user: { id: req.user_id } },
+1 -1
View File
@@ -42,7 +42,7 @@ router.post(
const backup = await BackupCode.findOne({ where: { code: body.code } });
if (!backup) {
const ret = verifyToken(user.totp_secret!, body.code);
const ret = verifyToken(user.totp_secret || "", body.code);
if (!ret || ret.delta != 0)
throw new HTTPError(
req.t("auth:login.INVALID_TOTP_CODE"),
+1 -1
View File
@@ -57,7 +57,7 @@ router.post(
if (verifyToken(body.secret, body.code)?.delta != 0)
throw new HTTPError(req.t("auth:login.INVALID_TOTP_CODE"), 60008);
let backup_codes = generateMfaBackupCodes(req.user_id);
const backup_codes = generateMfaBackupCodes(req.user_id);
await Promise.all(backup_codes.map((x) => x.save()));
await User.update(
{ id: req.user_id },
+3 -3
View File
@@ -175,7 +175,7 @@ async function updateRelationship(
select: userProjection,
});
var relationship = user.relationships.find((x) => x.to_id === id);
let relationship = user.relationships.find((x) => x.to_id === id);
const friendRequest = friend.relationships.find(
(x) => x.to_id === req.user_id,
);
@@ -219,13 +219,13 @@ async function updateRelationship(
if (user.relationships.length >= maxFriends)
throw DiscordApiErrors.MAXIMUM_FRIENDS.withParams(maxFriends);
var incoming_relationship = Relationship.create({
let incoming_relationship = Relationship.create({
nickname: undefined,
type: RelationshipType.incoming,
to: user,
from: friend,
});
var outgoing_relationship = Relationship.create({
let outgoing_relationship = Relationship.create({
nickname: undefined,
type: RelationshipType.outgoing,
to: friend,
+1 -1
View File
@@ -17,7 +17,7 @@
*/
import { Router, Response, Request } from "express";
import { OrmUtils, User, UserSettingsSchema } from "@fosscord/util";
import { User, UserSettingsSchema } from "@fosscord/util";
import { route } from "@fosscord/api";
const router = Router();