From 4f41d80b8819b75591bdd2ce51ad0cb7fba71481 Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Tue, 31 May 2022 14:06:27 -0700 Subject: [PATCH] Replace as string with String constructor --- src/client.ts | 8 ++++---- src/command-line/upgrade.ts | 2 +- src/config.ts | 6 +++--- src/models/user.ts | 2 +- src/plugins/clientCertificate.ts | 2 +- src/plugins/inputs/msg.ts | 4 ++-- src/plugins/irc-events/connection.ts | 2 +- src/plugins/messageStorage/sqlite.ts | 2 +- src/plugins/messageStorage/text.ts | 2 +- src/plugins/webpush.ts | 8 ++++---- src/server.ts | 2 +- src/types/modules/irc-framework.d.ts | 1 + test/fixtures/.thelounge/sts-policies.json | 2 +- test/models/network.ts | 1 - 14 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/client.ts b/src/client.ts index df6f8f12..cd42f96d 100644 --- a/src/client.ts +++ b/src/client.ts @@ -242,7 +242,7 @@ class Client { // Get channel id for lobby before creating other channels for nicer ids const lobbyChannelId = client.idChan++; - if (args.channels) { + if (Array.isArray(args.channels)) { let badName = false; args.channels.forEach((chan: Chan) => { @@ -266,7 +266,7 @@ class Client { "User '" + client.name + "' on network '" + - (args.name as string) + + String(args.name) + "' has an invalid channel which has been ignored" ); } @@ -289,12 +289,12 @@ class Client { // TODO; better typing for args const network = new Network({ - uuid: args.uuid as string, + uuid: String(args.uuid), name: String( args.name || (Config.values.lockNetwork ? Config.values.defaults.name : "") || "" ), host: String(args.host || ""), - port: parseInt(args.port as string, 10), + port: parseInt(String(args.port), 10), tls: !!args.tls, userDisconnected: !!args.userDisconnected, rejectUnauthorized: !!args.rejectUnauthorized, diff --git a/src/command-line/upgrade.ts b/src/command-line/upgrade.ts index d567be73..06644f43 100644 --- a/src/command-line/upgrade.ts +++ b/src/command-line/upgrade.ts @@ -61,7 +61,7 @@ program log.info("Package(s) have been successfully upgraded."); }) .catch((code) => { - log.error(`Failed to upgrade package(s). Exit code ${code as string}`); + log.error(`Failed to upgrade package(s). Exit code ${String(code)}`); process.exit(1); }); }); diff --git a/src/config.ts b/src/config.ts index db46cda2..35d8d56c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -230,9 +230,9 @@ class Config { this.values.fileUpload.baseUrl = undefined; log.warn( - `The ${colors.bold("fileUpload.baseUrl")} you specified is invalid: ${ - e as string - }` + `The ${colors.bold("fileUpload.baseUrl")} you specified is invalid: ${String( + e + )}` ); } } diff --git a/src/models/user.ts b/src/models/user.ts index 714fdffd..95b6087c 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -19,7 +19,7 @@ class User { Object.defineProperty(this, "mode", { get() { - return (this.modes[0] as string) || ""; + return String(this.modes[0]); }, }); diff --git a/src/plugins/clientCertificate.ts b/src/plugins/clientCertificate.ts index ec87d21e..d276fdc9 100644 --- a/src/plugins/clientCertificate.ts +++ b/src/plugins/clientCertificate.ts @@ -74,7 +74,7 @@ function generateAndWrite(folderPath: string, paths: {privateKeyPath: any; certi return certificate; } catch (e: any) { - log.error("Unable to write certificate", e as string); + log.error("Unable to write certificate", String(e)); } return null; diff --git a/src/plugins/inputs/msg.ts b/src/plugins/inputs/msg.ts index c1171dc2..ecbba9f5 100644 --- a/src/plugins/inputs/msg.ts +++ b/src/plugins/inputs/msg.ts @@ -1,10 +1,10 @@ import {PluginInputHandler} from "./index"; import Msg, {MessageType} from "../../models/msg"; -import {ChanType} from "../../models/chan"; +import Chan, {ChanType} from "../../models/chan"; const commands = ["query", "msg", "say"]; -function getTarget(cmd, args, chan) { +function getTarget(cmd: string, args: string[], chan: Chan) { switch (cmd) { case "msg": case "query": diff --git a/src/plugins/irc-events/connection.ts b/src/plugins/irc-events/connection.ts index 2f06b63a..8deed087 100644 --- a/src/plugins/irc-events/connection.ts +++ b/src/plugins/irc-events/connection.ts @@ -180,7 +180,7 @@ export default function (irc, network) { new Msg({ text: `Disconnected from the network. Reconnecting in ${Math.round( data.wait / 1000 - )} seconds… (Attempt ${data.attempt})`, + )} seconds… (Attempt ${Number(data.attempt)})`, }), true ); diff --git a/src/plugins/messageStorage/sqlite.ts b/src/plugins/messageStorage/sqlite.ts index 1df7d3bb..72e108fe 100644 --- a/src/plugins/messageStorage/sqlite.ts +++ b/src/plugins/messageStorage/sqlite.ts @@ -54,7 +54,7 @@ class SqliteMessageStorage implements ISqliteMessageStorage { try { fs.mkdirSync(logsPath, {recursive: true}); } catch (e: any) { - log.error("Unable to create logs directory", e as string); + log.error("Unable to create logs directory", String(e)); return; } diff --git a/src/plugins/messageStorage/text.ts b/src/plugins/messageStorage/text.ts index d8c10415..fbd2abc3 100644 --- a/src/plugins/messageStorage/text.ts +++ b/src/plugins/messageStorage/text.ts @@ -46,7 +46,7 @@ class TextFileMessageStorage implements MessageStorage { try { fs.mkdirSync(logPath, {recursive: true}); } catch (e: any) { - log.error("Unable to create logs directory", e as string); + log.error("Unable to create logs directory", String(e)); return; } diff --git a/src/plugins/webpush.ts b/src/plugins/webpush.ts index 75bde729..dbf07e20 100644 --- a/src/plugins/webpush.ts +++ b/src/plugins/webpush.ts @@ -84,9 +84,9 @@ class WebPush { WebPushAPI.sendNotification(subscription, JSON.stringify(payload)).catch((error) => { if (error.statusCode >= 400 && error.statusCode < 500) { log.warn( - `WebPush subscription for ${client.name} returned an error (${ - error.statusCode as string - }), removing subscription` + `WebPush subscription for ${client.name} returned an error (${String( + error.statusCode + )}), removing subscription` ); _.forOwn(client.config.sessions, ({pushSubscription}, token) => { @@ -98,7 +98,7 @@ class WebPush { return; } - log.error(`WebPush Error (${error as string})`); + log.error(`WebPush Error (${String(error)})`); }); } } diff --git a/src/server.ts b/src/server.ts index ad17c4cb..423cebd9 100644 --- a/src/server.ts +++ b/src/server.ts @@ -344,7 +344,7 @@ function getClientIp(socket: Socket) { let ip = socket.handshake.address || "127.0.0.1"; if (Config.values.reverseProxy) { - const forwarded = ((socket.handshake.headers["x-forwarded-for"] || "") as string) + const forwarded = String(socket.handshake.headers["x-forwarded-for"]) .split(/\s*,\s*/) .filter(Boolean); diff --git a/src/types/modules/irc-framework.d.ts b/src/types/modules/irc-framework.d.ts index d001461a..dc3fd59c 100644 --- a/src/types/modules/irc-framework.d.ts +++ b/src/types/modules/irc-framework.d.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-use-before-define */ // @ts-nocheck // eslint-disable diff --git a/test/fixtures/.thelounge/sts-policies.json b/test/fixtures/.thelounge/sts-policies.json index 01deda93..033c1805 100644 --- a/test/fixtures/.thelounge/sts-policies.json +++ b/test/fixtures/.thelounge/sts-policies.json @@ -3,6 +3,6 @@ "host": "irc.example.com", "port": 7000, "duration": 3600, - "expires": 1654034227268 + "expires": 1654034491040 } ] diff --git a/test/models/network.ts b/test/models/network.ts index c5a21359..75e4898c 100644 --- a/test/models/network.ts +++ b/test/models/network.ts @@ -178,7 +178,6 @@ describe("Network", function () { }); it("should apply STS policies iff they match", function () { - // eslint-disable-next-line @typescript-eslint/no-empty-function const client = {idMsg: 1, emit() {}} as any; STSPolicies.update("irc.example.com", 7000, 3600);