feature: Adds eslint rules.

This commit is contained in:
greysoh 2024-05-10 17:37:04 -04:00
parent 09f7987e75
commit 3c95c23369
No known key found for this signature in database
GPG key ID: FE0F173B8FC01571
26 changed files with 124 additions and 95 deletions

View file

@ -2,9 +2,18 @@ import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
export default [
{languageOptions: { globals: globals.node }},
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
languageOptions: {
globals: globals.node
},
rules: {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "off"
}
},
];

View file

@ -55,7 +55,7 @@ function parseBackendProviderString(data: string): BackendParsedProviderString {
if (typeof jsonData.ip != "string")
throw new Error("IP field is not a string");
if (typeof jsonData.port != "number") throw new Error("Port is not a number");
if (
@ -63,7 +63,7 @@ function parseBackendProviderString(data: string): BackendParsedProviderString {
typeof jsonData.publicPort != "number"
)
throw new Error("(optional field) Proxied port is not a number");
if (
typeof jsonData.isProxied != "undefined" &&
typeof jsonData.isProxied != "boolean"
@ -216,7 +216,7 @@ export class PassyFireBackendProvider implements BackendBaseClass {
static checkParametersBackendInstance(data: string): ParameterReturnedValue {
try {
parseBackendProviderString(data);
// @ts-expect-error
// @ts-expect-error: We write the function, and we know we're returning an error
} catch (e: Error) {
return {
success: false,

View file

@ -69,7 +69,7 @@ export function route(instance: PassyFireBackendProvider) {
},
},
(req, res) => {
// @ts-expect-error
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
const body: {
username: string;
password: string;
@ -115,7 +115,7 @@ export function route(instance: PassyFireBackendProvider) {
},
},
async (req, res) => {
// @ts-expect-error
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
const body: {
token: string;
} = req.body;
@ -132,8 +132,7 @@ export function route(instance: PassyFireBackendProvider) {
req.hostname.indexOf(":") + 1,
);
// @ts-expect-error
// parseInt(...) can take a number just fine, at least in Node.JS
// @ts-expect-error: parseInt(...) can take a number just fine, at least in Node.JS
const port = parseInt(unparsedPort == "" ? proxiedPort : unparsedPort);
// This protocol is so confusing. I'm sorry.

View file

@ -14,7 +14,7 @@ function authenticateSocket(
ws: WebSocket,
message: string,
state: ConnectedClientExt,
): Boolean {
): boolean {
if (!message.startsWith("Accept: ")) {
ws.send("400 Bad Request");
return false;
@ -57,8 +57,8 @@ export function requestHandler(
let state: "authentication" | "data" = "authentication";
let socket: dgram.Socket | net.Socket | undefined;
// @ts-expect-error
let connectedClient: ConnectedClientExt = {};
// @ts-expect-error: FIXME because this is a mess
const connectedClient: ConnectedClientExt = {};
ws.on("close", () => {
instance.clients.splice(

View file

@ -92,7 +92,7 @@ export class SSHBackendProvider implements BackendBaseClass {
this.logs.push(`Failed to start SSHBackendProvider! Error: '${e}'`);
this.state = "stopped";
// @ts-expect-error
// @ts-expect-error: We know that stuff will be initialized in order, so this will be safe
this.sshInstance = null;
return false;
@ -112,7 +112,7 @@ export class SSHBackendProvider implements BackendBaseClass {
this.sshInstance.dispose();
// @ts-expect-error
// @ts-expect-error: We know that stuff will be initialized in order, so this will be safe
this.sshInstance = null;
this.logs.push("Successfully stopped SSHBackendProvider.");
@ -255,7 +255,7 @@ export class SSHBackendProvider implements BackendBaseClass {
static checkParametersBackendInstance(data: string): ParameterReturnedValue {
try {
parseBackendProviderString(data);
// @ts-expect-error
// @ts-expect-error: We write the function, and we know we're returning an error
} catch (e: Error) {
return {
success: false,

View file

@ -35,12 +35,12 @@ export function route(routeOptions: RouteOptions) {
},
},
async (req, res) => {
// @ts-expect-error
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
const body: {
token: string;
name: string;
description?: string;
connectionDetails: any;
connectionDetails: unknown;
backend: string;
} = req.body;

View file

@ -33,7 +33,7 @@ export function route(routeOptions: RouteOptions) {
},
},
async (req, res) => {
// @ts-expect-error
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
const body: {
token: string;
id?: number;
@ -69,7 +69,7 @@ export function route(routeOptions: RouteOptions) {
success: true,
data: prismaBackends.map(i => ({
id: i.id,
name: i.name,
description: i.description,

View file

@ -30,7 +30,7 @@ export function route(routeOptions: RouteOptions) {
},
},
async (req, res) => {
// @ts-expect-error
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
const body: {
token: string;
id: number;

View file

@ -27,7 +27,7 @@ export function route(routeOptions: RouteOptions) {
},
},
async (req, res) => {
// @ts-expect-error
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
const body: {
token: string;
id: number;
@ -59,8 +59,12 @@ export function route(routeOptions: RouteOptions) {
return {
success: true,
data: backends[forward.destProviderID].getAllConnections().filter((i) => {
return i.connectionDetails.sourceIP == forward.sourceIP && i.connectionDetails.sourcePort == forward.sourcePort && i.connectionDetails.destPort == forward.destPort;
data: backends[forward.destProviderID].getAllConnections().filter(i => {
return (
i.connectionDetails.sourceIP == forward.sourceIP &&
i.connectionDetails.sourcePort == forward.sourcePort &&
i.connectionDetails.destPort == forward.destPort
);
}),
};
},

View file

@ -50,7 +50,7 @@ export function route(routeOptions: RouteOptions) {
},
},
async (req, res) => {
// @ts-expect-error
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
const body: {
token: string;

View file

@ -41,7 +41,7 @@ export function route(routeOptions: RouteOptions) {
},
},
async (req, res) => {
// @ts-expect-error
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
const body: {
token: string;

View file

@ -30,7 +30,7 @@ export function route(routeOptions: RouteOptions) {
},
},
async (req, res) => {
// @ts-expect-error
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
const body: {
token: string;
id: number;

View file

@ -30,7 +30,7 @@ export function route(routeOptions: RouteOptions) {
},
},
async (req, res) => {
// @ts-expect-error
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
const body: {
token: string;
id: number;
@ -58,8 +58,7 @@ export function route(routeOptions: RouteOptions) {
error: "Backend not found",
});
// Other restrictions in place make it so that it MUST be either TCP or UDP
// @ts-expect-error
// @ts-expect-error: Other restrictions in place make it so that it MUST be either TCP or UDP
const protocol: "tcp" | "udp" = forward.protocol;
backends[forward.destProviderID].addConnection(

View file

@ -30,7 +30,7 @@ export function route(routeOptions: RouteOptions) {
},
},
async (req, res) => {
// @ts-expect-error
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
const body: {
token: string;
id: number;
@ -58,8 +58,7 @@ export function route(routeOptions: RouteOptions) {
error: "Backend not found",
});
// Other restrictions in place make it so that it MUST be either TCP or UDP
// @ts-expect-error
// @ts-expect-error: Other restrictions in place make it so that it MUST be either TCP or UDP
const protocol: "tcp" | "udp" = forward.protocol;
backends[forward.destProviderID].removeConnection(

View file

@ -22,7 +22,7 @@ export function route(routeOptions: RouteOptions) {
},
},
async (req, res) => {
// @ts-expect-error
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
const body: {
token: string;
} = req.body;

View file

@ -29,7 +29,7 @@ export function route(routeOptions: RouteOptions) {
},
},
async (req, res) => {
// @ts-expect-error
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
const body: {
name: string;
email: string;
@ -87,9 +87,9 @@ export function route(routeOptions: RouteOptions) {
}
if (options.allowUnsafeGlobalTokens) {
// @ts-expect-error
// @ts-expect-error: Setting this correctly is a goddamn mess, but this is safe to an extent. It won't crash at least
userData.rootToken = generateRandomData();
// @ts-expect-error
// @ts-expect-error: Read above.
userData.isRootServiceAccount = true;
}

View file

@ -20,27 +20,28 @@ export function route(routeOptions: RouteOptions) {
properties: {
email: { type: "string" },
username: { type: "string" },
password: { type: "string" }
password: { type: "string" },
},
},
},
},
async (req, res) => {
// @ts-expect-error
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
const body: {
email?: string;
username?: string;
password: string;
} = req.body;
if (!body.email && !body.username) return res.status(400).send({
error: "missing both email and username. please supply at least one."
});
if (!body.email && !body.username)
return res.status(400).send({
error: "missing both email and username. please supply at least one.",
});
const userSearch = await prisma.user.findFirst({
where: {
email: body.email,
username: body.username
username: body.username,
},
});

View file

@ -31,7 +31,7 @@ export function route(routeOptions: RouteOptions) {
},
},
async (req, res) => {
// @ts-expect-error
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
const body: {
token: string;
id?: number;
@ -64,7 +64,7 @@ export function route(routeOptions: RouteOptions) {
name: i.name,
email: i.email,
isServiceAccount: i.isRootServiceAccount,
username: i.username
username: i.username,
})),
};
},

View file

@ -30,7 +30,7 @@ export function route(routeOptions: RouteOptions) {
},
},
async (req, res) => {
// @ts-expect-error
// @ts-expect-error: Fastify routes schema parsing is trustworthy, so we can "assume" invalid types
const body: {
token: string;
uid: number;