Upgrading eslint

This commit is contained in:
David Négrier 2021-12-23 15:27:17 +01:00
parent 220c9433d1
commit 3e91a79078
20 changed files with 835 additions and 1641 deletions

View File

@ -68,9 +68,9 @@
"@types/mkdirp": "^1.0.1", "@types/mkdirp": "^1.0.1",
"@types/redis": "^2.8.31", "@types/redis": "^2.8.31",
"@types/uuidv4": "^5.0.0", "@types/uuidv4": "^5.0.0",
"@typescript-eslint/eslint-plugin": "^2.26.0", "@typescript-eslint/eslint-plugin": "^5.8.0",
"@typescript-eslint/parser": "^2.26.0", "@typescript-eslint/parser": "^5.8.0",
"eslint": "^6.8.0", "eslint": "^8.5.0",
"jasmine": "^3.5.0", "jasmine": "^3.5.0",
"lint-staged": "^11.0.0", "lint-staged": "^11.0.0",
"prettier": "^2.3.1", "prettier": "^2.3.1",

View File

@ -10,6 +10,6 @@ App.listen(HTTP_PORT, () => console.log(`WorkAdventure HTTP API starting on port
const server = new grpc.Server(); const server = new grpc.Server();
server.addService<IRoomManagerServer>(RoomManagerService, roomManager); server.addService<IRoomManagerServer>(RoomManagerService, roomManager);
server.bind('0.0.0.0:'+GRPC_PORT, grpc.ServerCredentials.createInsecure()); server.bind(`0.0.0.0:${GRPC_PORT}`, grpc.ServerCredentials.createInsecure());
server.start(); server.start();
console.log('WorkAdventure HTTP/2 API starting on port %d!', GRPC_PORT); console.log('WorkAdventure HTTP/2 API starting on port %d!', GRPC_PORT);

View File

@ -36,9 +36,11 @@ export class DebugController {
return "BatchedMessages"; return "BatchedMessages";
} }
if (value instanceof Map) { if (value instanceof Map) {
const obj: any = {}; // eslint-disable-line @typescript-eslint/no-explicit-any const obj: { [key: string | number]: unknown } = {};
for (const [mapKey, mapValue] of value.entries()) { for (const [mapKey, mapValue] of value.entries()) {
obj[mapKey] = mapValue; if (typeof mapKey === "number" || typeof mapKey === "string") {
obj[mapKey] = mapValue;
}
} }
return obj; return obj;
} else if (value instanceof Set) { } else if (value instanceof Set) {

View File

@ -1,12 +1,10 @@
import { App } from "../Server/sifrr.server"; import { App } from "../Server/sifrr.server";
import { HttpRequest, HttpResponse } from "uWebSockets.js"; import { HttpRequest, HttpResponse } from "uWebSockets.js";
const register = require("prom-client").register; import { register, collectDefaultMetrics } from "prom-client";
const collectDefaultMetrics = require("prom-client").collectDefaultMetrics;
export class PrometheusController { export class PrometheusController {
constructor(private App: App) { constructor(private App: App) {
collectDefaultMetrics({ collectDefaultMetrics({
timeout: 10000,
gcDurationBuckets: [0.001, 0.01, 0.1, 1, 2, 5], // These are the default buckets. gcDurationBuckets: [0.001, 0.01, 0.1, 1, 2, 5], // These are the default buckets.
}); });

View File

@ -34,6 +34,7 @@ import { ADMIN_API_URL } from "../Enum/EnvironmentVariable";
import { LocalUrlError } from "../Services/LocalUrlError"; import { LocalUrlError } from "../Services/LocalUrlError";
import { emitErrorOnRoomSocket } from "../Services/MessageHelpers"; import { emitErrorOnRoomSocket } from "../Services/MessageHelpers";
import { VariableError } from "../Services/VariableError"; import { VariableError } from "../Services/VariableError";
import { isRoomRedirect } from "../Services/AdminApi/RoomRedirect";
export type ConnectCallback = (user: User, group: Group) => void; export type ConnectCallback = (user: User, group: Group) => void;
export type DisconnectCallback = (user: User, group: Group) => void; export type DisconnectCallback = (user: User, group: Group) => void;
@ -282,9 +283,7 @@ export class GameRoom {
this.positionNotifier.leave(group); this.positionNotifier.leave(group);
group.destroy(); group.destroy();
if (!this.groups.has(group)) { if (!this.groups.has(group)) {
throw new Error( throw new Error(`Could not find group ${group.getId()} referenced by user ${user.id} in World.`);
"Could not find group " + group.getId() + " referenced by user " + user.id + " in World."
);
} }
this.groups.delete(group); this.groups.delete(group);
//todo: is the group garbage collected? //todo: is the group garbage collected?
@ -485,9 +484,9 @@ export class GameRoom {
} }
const result = await adminApi.fetchMapDetails(roomUrl); const result = await adminApi.fetchMapDetails(roomUrl);
if (!isMapDetailsData(result)) { if (isRoomRedirect(result)) {
console.error("Unexpected room details received from server", result); console.error("Unexpected room redirect received while querying map details", result);
throw new Error("Unexpected room details received from server"); throw new Error("Unexpected room redirect received while querying map details");
} }
return result; return result;
} }

View File

@ -116,7 +116,7 @@ export class Group implements Movable {
leave(user: User): void { leave(user: User): void {
const success = this.users.delete(user); const success = this.users.delete(user);
if (success === false) { if (success === false) {
throw new Error("Could not find user " + user.id + " in the group " + this.id); throw new Error(`Could not find user ${user.id} in the group ${this.id}`);
} }
user.group = undefined; user.group = undefined;

View File

@ -39,21 +39,13 @@ export class Zone {
const result = this.things.delete(thing); const result = this.things.delete(thing);
if (!result) { if (!result) {
if (thing instanceof User) { if (thing instanceof User) {
throw new Error("Could not find user in zone " + thing.id); throw new Error(`Could not find user in zone ${thing.id}`);
} }
if (thing instanceof Group) { if (thing instanceof Group) {
throw new Error( throw new Error(
"Could not find group " + `Could not find group ${thing.getId()} in zone (${this.x},${this.y}). Position of group: (${
thing.getId() + thing.getPosition().x
" in zone (" + },${thing.getPosition().y})`
this.x +
"," +
this.y +
"). Position of group: (" +
thing.getPosition().x +
"," +
thing.getPosition().y +
")"
); );
} }
} }

View File

@ -166,7 +166,7 @@ const roomManager: IRoomManagerServer = {
socketManager socketManager
.addZoneListener(call, zoneMessage.getRoomid(), zoneMessage.getX(), zoneMessage.getY()) .addZoneListener(call, zoneMessage.getRoomid(), zoneMessage.getX(), zoneMessage.getY())
.catch((e) => { .catch((e) => {
emitErrorOnZoneSocket(call, e.toString()); emitErrorOnZoneSocket(call, e);
}); });
call.on("cancelled", () => { call.on("cancelled", () => {
@ -196,7 +196,7 @@ const roomManager: IRoomManagerServer = {
const roomMessage = call.request; const roomMessage = call.request;
socketManager.addRoomListener(call, roomMessage.getRoomid()).catch((e) => { socketManager.addRoomListener(call, roomMessage.getRoomid()).catch((e) => {
emitErrorOnRoomSocket(call, e.toString()); emitErrorOnRoomSocket(call, e);
}); });
call.on("cancelled", () => { call.on("cancelled", () => {

View File

@ -1,3 +1,5 @@
/* eslint-disable */
import { Readable } from "stream"; import { Readable } from "stream";
import { us_listen_socket_close, TemplatedApp, HttpResponse, HttpRequest } from "uWebSockets.js"; import { us_listen_socket_close, TemplatedApp, HttpResponse, HttpRequest } from "uWebSockets.js";

View File

@ -1,3 +1,5 @@
/* eslint-disable */
import { createWriteStream } from "fs"; import { createWriteStream } from "fs";
import { join, dirname } from "path"; import { join, dirname } from "path";
import Busboy from "busboy"; import Busboy from "busboy";

View File

@ -1,3 +1,5 @@
/* eslint-disable */
import { ReadStream } from "fs"; import { ReadStream } from "fs";
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any

View File

@ -1,7 +1,7 @@
import { ADMIN_API_TOKEN, ADMIN_API_URL } from "../Enum/EnvironmentVariable"; import { ADMIN_API_TOKEN, ADMIN_API_URL } from "../Enum/EnvironmentVariable";
import Axios from "axios"; import Axios from "axios";
import { MapDetailsData } from "./AdminApi/MapDetailsData"; import { isMapDetailsData, MapDetailsData } from "./AdminApi/MapDetailsData";
import { RoomRedirect } from "./AdminApi/RoomRedirect"; import { isRoomRedirect, RoomRedirect } from "./AdminApi/RoomRedirect";
class AdminApi { class AdminApi {
async fetchMapDetails(playUri: string): Promise<MapDetailsData | RoomRedirect> { async fetchMapDetails(playUri: string): Promise<MapDetailsData | RoomRedirect> {
@ -17,6 +17,12 @@ class AdminApi {
headers: { Authorization: `${ADMIN_API_TOKEN}` }, headers: { Authorization: `${ADMIN_API_TOKEN}` },
params, params,
}); });
if (!isMapDetailsData(res.data) && !isRoomRedirect(res.data)) {
console.error("Unexpected answer from the /api/map admin endpoint.", res.data);
throw new Error("Unexpected answer from the /api/map admin endpoint.");
}
return res.data; return res.data;
} }
} }

View File

@ -1,4 +1,4 @@
const EventEmitter = require("events"); import { EventEmitter } from "events";
const clientJoinEvent = "clientJoin"; const clientJoinEvent = "clientJoin";
const clientLeaveEvent = "clientLeave"; const clientLeaveEvent = "clientLeave";

View File

@ -32,7 +32,7 @@ class MapFetcher {
//throw new Error("Invalid map format for map " + mapUrl); //throw new Error("Invalid map format for map " + mapUrl);
console.error("Invalid map format for map " + mapUrl); console.error("Invalid map format for map " + mapUrl);
} }
/* eslint-disable-next-line @typescript-eslint/no-unsafe-return */
return res.data; return res.data;
} }

View File

@ -10,15 +10,18 @@ import {
import { UserSocket } from "_Model/User"; import { UserSocket } from "_Model/User";
import { RoomSocket, ZoneSocket } from "../RoomManager"; import { RoomSocket, ZoneSocket } from "../RoomManager";
export function emitError(Client: UserSocket, error: unknown): void { function getMessageFromError(error: unknown): string {
let message = "";
if (error instanceof Error) { if (error instanceof Error) {
message = error.message; return error.message;
} else if (typeof error === "string") { } else if (typeof error === "string") {
message = error; return error;
} else { } else {
message = "Unknown error"; return "Unknown error";
} }
}
export function emitError(Client: UserSocket, error: unknown): void {
const message = getMessageFromError(error);
const errorMessage = new ErrorMessage(); const errorMessage = new ErrorMessage();
errorMessage.setMessage(message); errorMessage.setMessage(message);
@ -32,8 +35,9 @@ export function emitError(Client: UserSocket, error: unknown): void {
console.warn(message); console.warn(message);
} }
export function emitErrorOnRoomSocket(Client: RoomSocket, message: string): void { export function emitErrorOnRoomSocket(Client: RoomSocket, error: unknown): void {
console.error(message); console.error(error);
const message = getMessageFromError(error);
const errorMessage = new ErrorMessage(); const errorMessage = new ErrorMessage();
errorMessage.setMessage(message); errorMessage.setMessage(message);
@ -50,8 +54,9 @@ export function emitErrorOnRoomSocket(Client: RoomSocket, message: string): void
console.warn(message); console.warn(message);
} }
export function emitErrorOnZoneSocket(Client: ZoneSocket, message: string): void { export function emitErrorOnZoneSocket(Client: ZoneSocket, error: unknown): void {
console.error(message); console.error(error);
const message = getMessageFromError(error);
const errorMessage = new ErrorMessage(); const errorMessage = new ErrorMessage();
errorMessage.setMessage(message); errorMessage.setMessage(message);

View File

@ -197,7 +197,7 @@ export class SocketManager {
webrtcSignalToClient.setSignal(data.getSignal()); webrtcSignalToClient.setSignal(data.getSignal());
// TODO: only compute credentials if data.signal.type === "offer" // TODO: only compute credentials if data.signal.type === "offer"
if (TURN_STATIC_AUTH_SECRET !== "") { if (TURN_STATIC_AUTH_SECRET !== "") {
const { username, password } = this.getTURNCredentials("" + user.id, TURN_STATIC_AUTH_SECRET); const { username, password } = this.getTURNCredentials(user.id.toString(), TURN_STATIC_AUTH_SECRET);
webrtcSignalToClient.setWebrtcusername(username); webrtcSignalToClient.setWebrtcusername(username);
webrtcSignalToClient.setWebrtcpassword(password); webrtcSignalToClient.setWebrtcpassword(password);
} }
@ -227,7 +227,7 @@ export class SocketManager {
webrtcSignalToClient.setSignal(data.getSignal()); webrtcSignalToClient.setSignal(data.getSignal());
// TODO: only compute credentials if data.signal.type === "offer" // TODO: only compute credentials if data.signal.type === "offer"
if (TURN_STATIC_AUTH_SECRET !== "") { if (TURN_STATIC_AUTH_SECRET !== "") {
const { username, password } = this.getTURNCredentials("" + user.id, TURN_STATIC_AUTH_SECRET); const { username, password } = this.getTURNCredentials(user.id.toString(), TURN_STATIC_AUTH_SECRET);
webrtcSignalToClient.setWebrtcusername(username); webrtcSignalToClient.setWebrtcusername(username);
webrtcSignalToClient.setWebrtcpassword(password); webrtcSignalToClient.setWebrtcpassword(password);
} }
@ -310,7 +310,7 @@ export class SocketManager {
if (thing instanceof User) { if (thing instanceof User) {
const userJoinedZoneMessage = new UserJoinedZoneMessage(); const userJoinedZoneMessage = new UserJoinedZoneMessage();
if (!Number.isInteger(thing.id)) { if (!Number.isInteger(thing.id)) {
throw new Error("clientUser.userId is not an integer " + thing.id); throw new Error(`clientUser.userId is not an integer ${thing.id}`);
} }
userJoinedZoneMessage.setUserid(thing.id); userJoinedZoneMessage.setUserid(thing.id);
userJoinedZoneMessage.setUseruuid(thing.uuid); userJoinedZoneMessage.setUseruuid(thing.uuid);
@ -446,7 +446,10 @@ export class SocketManager {
webrtcStartMessage1.setUserid(otherUser.id); webrtcStartMessage1.setUserid(otherUser.id);
webrtcStartMessage1.setInitiator(true); webrtcStartMessage1.setInitiator(true);
if (TURN_STATIC_AUTH_SECRET !== "") { if (TURN_STATIC_AUTH_SECRET !== "") {
const { username, password } = this.getTURNCredentials("" + otherUser.id, TURN_STATIC_AUTH_SECRET); const { username, password } = this.getTURNCredentials(
otherUser.id.toString(),
TURN_STATIC_AUTH_SECRET
);
webrtcStartMessage1.setWebrtcusername(username); webrtcStartMessage1.setWebrtcusername(username);
webrtcStartMessage1.setWebrtcpassword(password); webrtcStartMessage1.setWebrtcpassword(password);
} }
@ -460,7 +463,7 @@ export class SocketManager {
webrtcStartMessage2.setUserid(user.id); webrtcStartMessage2.setUserid(user.id);
webrtcStartMessage2.setInitiator(false); webrtcStartMessage2.setInitiator(false);
if (TURN_STATIC_AUTH_SECRET !== "") { if (TURN_STATIC_AUTH_SECRET !== "") {
const { username, password } = this.getTURNCredentials("" + user.id, TURN_STATIC_AUTH_SECRET); const { username, password } = this.getTURNCredentials(user.id.toString(), TURN_STATIC_AUTH_SECRET);
webrtcStartMessage2.setWebrtcusername(username); webrtcStartMessage2.setWebrtcusername(username);
webrtcStartMessage2.setWebrtcpassword(password); webrtcStartMessage2.setWebrtcpassword(password);
} }
@ -484,7 +487,7 @@ export class SocketManager {
hmac.setEncoding("base64"); hmac.setEncoding("base64");
hmac.write(username); hmac.write(username);
hmac.end(); hmac.end();
const password = hmac.read(); const password = hmac.read() as string;
return { return {
username: username, username: username,
password: password, password: password,

View File

@ -101,11 +101,11 @@ export class VariablesManager {
} }
// We store a copy of the object (to make it immutable) // We store a copy of the object (to make it immutable)
objects.set(object.name, this.iTiledObjectToVariable(object)); objects.set(object.name as string, this.iTiledObjectToVariable(object));
} }
} }
} else if (layer.type === "group") { } else if (layer.type === "group") {
for (const innerLayer of layer.layers) { for (const innerLayer of layer.layers as ITiledMapLayer[]) {
this.recursiveFindVariablesInLayer(innerLayer, objects); this.recursiveFindVariablesInLayer(innerLayer, objects);
} }
} }
@ -116,7 +116,7 @@ export class VariablesManager {
if (object.properties) { if (object.properties) {
for (const property of object.properties) { for (const property of object.properties) {
const value = property.value; const value = property.value as unknown;
switch (property.name) { switch (property.name) {
case "default": case "default":
variable.defaultValue = JSON.stringify(value); variable.defaultValue = JSON.stringify(value);

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,10 @@
import { App } from "../Server/sifrr.server"; import { App } from "../Server/sifrr.server";
import { HttpRequest, HttpResponse } from "uWebSockets.js"; import { HttpRequest, HttpResponse } from "uWebSockets.js";
const register = require("prom-client").register; import { register, collectDefaultMetrics } from "prom-client";
const collectDefaultMetrics = require("prom-client").collectDefaultMetrics;
export class PrometheusController { export class PrometheusController {
constructor(private App: App) { constructor(private App: App) {
collectDefaultMetrics({ collectDefaultMetrics({
timeout: 10000,
gcDurationBuckets: [0.001, 0.01, 0.1, 1, 2, 5], // These are the default buckets. gcDurationBuckets: [0.001, 0.01, 0.1, 1, 2, 5], // These are the default buckets.
}); });

View File

@ -1,4 +1,4 @@
const EventEmitter = require("events"); import { EventEmitter } from "events";
const clientJoinEvent = "clientJoin"; const clientJoinEvent = "clientJoin";
const clientLeaveEvent = "clientLeave"; const clientLeaveEvent = "clientLeave";