From 084dc0be08555891cad4c2bb984822a62ec5ec9f Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Fri, 20 Jan 2023 18:10:47 +1100 Subject: Add ESLint (#941) * Add eslint, switch to lint-staged for precommit * Fix all ESLint errors * Update GH workflow to check prettier and eslint --- src/bundle/Server.ts | 2 +- src/bundle/start.ts | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'src/bundle') diff --git a/src/bundle/Server.ts b/src/bundle/Server.ts index a5f96c3a..96f6a149 100644 --- a/src/bundle/Server.ts +++ b/src/bundle/Server.ts @@ -24,7 +24,7 @@ import * as Api from "@fosscord/api"; import * as Gateway from "@fosscord/gateway"; import { CDNServer } from "@fosscord/cdn"; import express from "express"; -import { green, bold, yellow } from "picocolors"; +import { green, bold } from "picocolors"; import { Config, initDatabase, Sentry } from "@fosscord/util"; const app = express(); diff --git a/src/bundle/start.ts b/src/bundle/start.ts index 10fb7c36..8da3cc20 100644 --- a/src/bundle/start.ts +++ b/src/bundle/start.ts @@ -29,14 +29,15 @@ import { execSync } from "child_process"; const cores = process.env.THREADS ? parseInt(process.env.THREADS) : 1; -if (cluster.isPrimary) { - function getCommitOrFail() { - try { - return execSync("git rev-parse HEAD").toString().trim(); - } catch (e) { - return null; - } +function getCommitOrFail() { + try { + return execSync("git rev-parse HEAD").toString().trim(); + } catch (e) { + return null; } +} + +if (cluster.isPrimary) { const commit = getCommitOrFail(); console.log( @@ -81,14 +82,14 @@ Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).) // Fork workers. for (let i = 0; i < cores; i++) { // Delay each worker start if using sqlite database to prevent locking it - let delay = process.env.DATABASE?.includes("://") ? 0 : i * 1000; + const delay = process.env.DATABASE?.includes("://") ? 0 : i * 1000; setTimeout(() => { cluster.fork(); console.log(`[Process] worker ${cyan(i)} started.`); }, delay); } - cluster.on("message", (sender: Worker, message: any) => { + cluster.on("message", (sender: Worker, message) => { for (const id in cluster.workers) { const worker = cluster.workers[id]; if (worker === sender || !worker) continue; @@ -96,7 +97,7 @@ Cores: ${cyan(os.cpus().length)} (Using ${cores} thread(s).) } }); - cluster.on("exit", (worker: any, code: any, signal: any) => { + cluster.on("exit", (worker) => { console.log( `[Worker] ${red( `died with PID: ${worker.process.pid} , restarting ...`, -- cgit 1.4.1