Fix code style errors

Remove extra whitespace, use more consistent spacing, add missing
semicolons, using dangling commas, break up long lines, consistent
multiline operator placement, add missing JSDoc strings and so on.
This commit is contained in:
Hornwitser committed 2023-11-19 04:48:38 +01:00
1 parent 97e05c0610
commit 7314dc99c8
71 files changed
+403 -290

No files matched your search

-1
View File
@@ -1,4 +1,3 @@
"use strict";
import fs from "fs-extra";
import path from "path";
import events from "events";
+2 -2
View File
@@ -11,7 +11,7 @@ import * as lib from "@clusterio/lib";
import { FactorioServer } from "./server";
import { SaveModule, patch } from "./patch";
import { exportData } from "./export";
import type Host from "./Host"
import type Host from "./Host";
const instanceRconCommandDuration = new lib.Histogram(
@@ -99,7 +99,7 @@ export default class Instance extends lib.Link {
/**
* ID of this instance, equivalenet to `instance.config.get("instance.id")`.
*/
readonly id: number
readonly id: number;
plugins: Map<string, lib.BaseInstancePlugin>;
config: lib.InstanceConfig;
logger: lib.Logger;
-1
View File
@@ -1,5 +1,4 @@
// Export of item icons and locale
"use strict";
import fs from "fs-extra";
import path from "path";
import Jimp from "jimp";
+5 -5
View File
@@ -18,7 +18,7 @@ export class SaveModule {
/** Module */
public info: lib.ModuleInfo,
/** Files and their content that will be patched into the save */
public files = new Map<string, Buffer>,
public files = new Map<string, Buffer>(),
) { }
static moduleFilePath(filePath: string, moduleName: string) {
@@ -47,7 +47,7 @@ export class SaveModule {
if (entry.isFile()) {
let savePath = SaveModule.moduleFilePath(relativePath, this.info.name);
this.files.set(savePath, await fs.readFile(fsPath));
if (relativePath == "module_exports.lua") {
if (relativePath === "module_exports.lua") {
this.files.set(
`modules/${this.info.name}.lua`,
Buffer.from(`return require("modules/${this.info.name}/module_exports")`, "utf-8")
@@ -96,7 +96,7 @@ export class SaveModule {
version: plugin.info.version,
dependencies: { "clusterio": "*" },
...JSON.parse(await fs.readFile(moduleJsonPath, "utf8")),
}
};
} catch (err: any) {
throw new Error(`Loading module/module.json in plugin ${plugin.info.name} failed: ${err.message}`);
}
@@ -173,7 +173,7 @@ export class PatchInfo {
interface PatchInfoV0 {
patch_number: number;
scenario: ScenarioInfoV0;
modules: { name: string, files: { path: string, load: boolean, require: boolean }[], }[];
modules: { name: string, files: { path: string, load: boolean, require: boolean }[], }[];
}
const info = json as unknown as PatchInfoV0;
@@ -394,7 +394,7 @@ export async function patch(savePath: string, modules: SaveModule[]) {
} else {
for (let module of patchInfo.modules) {
for (let file of module.files.keys()) {
zip.remove(root.file(file)!.name)
zip.remove(root.file(file)!.name);
}
}
patchInfo.modules = [];
+51 -55
View File
@@ -220,65 +220,61 @@ function parseOutput(line: string, source: "stdout" | "stderr"): lib.ParsedFacto
level: secLogMatch[1],
file: secLogMatch[2],
message: secLogMatch[5],
}
};
}
// The other possibility is that the content is a generic message
} else {
return {
source,
format,
time,
type: "generic",
message: secContent,
};
}
// The second category of output starts with a date stamp of the format
// "yyyy-mm-dd hh:mm:ss message"
const dateRegex = /^(\d{4}-\d\d-\d\d \d\d:\d\d:\d\d) (.*)$/;
let dateMatch = dateRegex.exec(line);
if (dateMatch) {
const format = "date";
const time = dateMatch[1];
let dateContent = dateMatch[2];
// A date output has two general formats. The first is an action
// followed by a message and has a format of "[ACTION] message"
const dateActionRegex = /^\[(\w+)\] (.*)$/;
let dateActionMatch = dateActionRegex.exec(dateContent);
if (dateActionMatch) {
return {
source,
format,
time,
type: "generic",
message: secContent,
}
type: "action",
action: dateActionMatch[1],
message: dateActionMatch[2],
};
}
// The second category of output starts with a date stamp of the format
// "yyyy-mm-dd hh:mm:ss message"
} else {
const dateRegex = /^(\d{4}-\d\d-\d\d \d\d:\d\d:\d\d) (.*)$/;
let dateMatch = dateRegex.exec(line);
if (dateMatch) {
const format = "date";
const time = dateMatch[1];
let dateContent = dateMatch[2];
// A date output has two general formats. The first is an action
// followed by a message and has a format of "[ACTION] message"
const dateActionRegex = /^\[(\w+)\] (.*)$/;
let dateActionMatch = dateActionRegex.exec(dateContent);
if (dateActionMatch) {
return {
source,
format,
time,
type: "action",
action: dateActionMatch[1],
message: dateActionMatch[2],
}
// The other format is a generic message
} else {
return {
source,
format,
time,
type: "generic",
message: dateContent,
}
}
// The last category of output is simply a generic message with no
// formating.
} else {
return {
source,
format: "none",
type: "generic",
message: line,
}
}
// The other format is a generic message
return {
source,
format,
time,
type: "generic",
message: dateContent,
};
}
// The last category of output is simply a generic message with no
// formating.
return {
source,
format: "none",
type: "generic",
message: line,
};
}
// https://stackoverflow.com/a/49402091
@@ -465,7 +461,7 @@ export class FactorioServer extends events.EventEmitter {
/** Enable Factorio.com based multiplayer bans **/
enableAuthserverBans: boolean;
/** Enable verbose logging */
verboseLogging: boolean
verboseLogging: boolean;
/** Timeout in ms to wait for a response to a shutdown command */
hangTimeout = 5000;
@@ -852,8 +848,8 @@ export class FactorioServer extends events.EventEmitter {
"--config", this.writePath("config.ini"),
"--create", this.writePath("saves", name),
...(seed !== undefined ? ["--map-gen-seed", String(seed)] : []),
...(mapGenSettings !== undefined ?
["--map-gen-settings", this.writePath("map-gen-settings.json")] : []
...(mapGenSettings !== undefined
? ["--map-gen-settings", this.writePath("map-gen-settings.json")] : []
),
...(mapSettings !== undefined ? ["--map-settings", this.writePath("map-settings.json")] : []),
...(this.verboseLogging ? ["--verbose"] : []),
@@ -944,8 +940,8 @@ export class FactorioServer extends events.EventEmitter {
"--config", this.writePath("config.ini"),
"--start-server-load-scenario", scenario,
...(seed !== undefined ? ["--map-gen-seed", String(seed)] : []),
...(mapGenSettings !== undefined ?
["--map-gen-settings", this.writePath("map-gen-settings.json")] : []
...(mapGenSettings !== undefined
? ["--map-gen-settings", this.writePath("map-gen-settings.json")] : []
),
...(mapSettings !== undefined ? ["--map-settings", this.writePath("map-settings.json")] : []),
"--port", String(this.gamePort),