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
@@ -26,7 +26,7 @@ import {
User,
} from "@fosscord/util";
export async function Close(this: WebSocket, code: number, reason: string) {
export async function Close(this: WebSocket, code: number, reason: Buffer) {
console.log("[WebSocket] closed", code, reason.toString());
if (this.heartbeatTimeout) clearTimeout(this.heartbeatTimeout);
if (this.readyTimeout) clearTimeout(this.readyTimeout);
+5 -2
View File
@@ -16,6 +16,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* eslint-disable @typescript-eslint/ban-ts-comment */
import WS from "ws";
import { genSessionId, WebSocket } from "@fosscord/gateway";
import { Send } from "../util/Send";
@@ -27,10 +28,12 @@ import { Message } from "./Message";
import { Deflate, Inflate } from "fast-zlib";
import { URL } from "url";
import { Config } from "@fosscord/util";
var erlpack: any;
let erlpack: unknown;
try {
erlpack = require("@yukikaze-bot/erlpack");
} catch (error) {}
} catch (error) {
/* empty */
}
// TODO: check rate limit
// TODO: specify rate limit in config
+8 -7
View File
@@ -27,14 +27,16 @@ import path from "path";
import fs from "fs/promises";
const bigIntJson = BigIntJson({ storeAsString: true });
var erlpack: any;
let erlpack: { unpack: (buffer: Buffer) => Payload };
try {
erlpack = require("@yukikaze-bot/erlpack");
} catch (error) {}
} catch (error) {
/* empty */
}
export async function Message(this: WebSocket, buffer: WS.Data) {
// TODO: compression
var data: Payload;
let data: Payload;
if (
(buffer instanceof Buffer && buffer[0] === 123) || // ASCII 123 = `{`. Bad check for JSON
@@ -44,9 +46,9 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
} else if (this.encoding === "json" && buffer instanceof Buffer) {
if (this.inflate) {
try {
buffer = this.inflate.process(buffer) as any;
buffer = this.inflate.process(buffer);
} catch {
buffer = buffer.toString() as any;
buffer = buffer.toString();
}
}
data = bigIntJson.parse(buffer as string);
@@ -78,7 +80,6 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
check.call(this, PayloadSchema, data);
// @ts-ignore
const OPCodeHandler = OPCodeHandlers[data.op];
if (!OPCodeHandler) {
console.error("[Gateway] Unkown opcode " + data.op);
@@ -100,7 +101,7 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
: undefined;
try {
var ret = await OPCodeHandler.call(this, data);
const ret = await OPCodeHandler.call(this, data);
Sentry.withScope((scope) => {
scope.setSpan(transaction);
scope.setUser({ id: this.user_id });