Fix issues detected by lgtm.com

This commit is contained in:
Hornwitser committed 2022-01-03 19:45:46 +01:00
1 parent 1ff1e3e5f8
commit 61cd5bd76c
40 files changed
+46 -62

No files matched your search

-2
View File
@@ -2,7 +2,6 @@
"use strict";
const child_process = require("child_process");
const events = require("events");
const fs = require("fs-extra");
const inquirer = require("inquirer");
const os = require("os");
@@ -94,7 +93,6 @@ async function safeOutputFile(file, data, options={}) {
async function execFile(cmd, args) {
logger.verbose(`executing ${cmd} ${args.join(" ")}`);
const asyncExec = util.promisify(child_process.execFile);
return new Promise((resolve, reject) => {
let child = child_process.execFile(cmd, args, (err, stdout, stderr) => {
if (err) {
+8 -8
View File
@@ -327,7 +327,7 @@ instanceCommands.add(new libCommand.Command({
}
instanceConfig.set("instance.name", args.name);
let serialized_config = instanceConfig.serialize("master");
let response = await libLink.messages.createInstance.send(control, { serialized_config });
await libLink.messages.createInstance.send(control, { serialized_config });
},
}));
@@ -563,7 +563,7 @@ instanceCommands.add(new libCommand.Command({
let instanceId = await libCommand.resolveInstance(control, args.instance);
let { seed, mapGenSettings, mapSettings } = await loadMapSettings(args);
await control.setLogSubscriptions({ instance_ids: [instanceId] });
let response = await libLink.messages.createSave.send(control, {
await libLink.messages.createSave.send(control, {
instance_id: instanceId,
name: args.name,
seed,
@@ -611,7 +611,7 @@ instanceCommands.add(new libCommand.Command({
}
for (let requestError of result.body.request_errors || []) {
logger.error(error);
logger.error(requestError);
}
if (result.body.saves && result.body.saves.length) {
@@ -690,7 +690,7 @@ instanceCommands.add(new libCommand.Command({
handler: async function(args, control) {
let instanceId = await libCommand.resolveInstance(control, args.instance);
await control.setLogSubscriptions({ instance_ids: [instanceId] });
let response = await libLink.messages.exportData.send(control, {
await libLink.messages.exportData.send(control, {
instance_id: instanceId,
});
},
@@ -707,7 +707,7 @@ instanceCommands.add(new libCommand.Command({
handler: async function(args, control) {
let instanceId = await libCommand.resolveInstance(control, args.instance);
await control.setLogSubscriptions({ instance_ids: [instanceId] });
let response = await libLink.messages.startInstance.send(control, {
await libLink.messages.startInstance.send(control, {
instance_id: instanceId,
save: args.save || null,
});
@@ -731,7 +731,7 @@ instanceCommands.add(new libCommand.Command({
let instanceId = await libCommand.resolveInstance(control, args.instance);
await control.setLogSubscriptions({ instance_ids: [instanceId] });
let { seed, mapGenSettings, mapSettings } = await loadMapSettings(args);
let response = await libLink.messages.loadScenario.send(control, {
await libLink.messages.loadScenario.send(control, {
instance_id: instanceId,
scenario: args.scenario,
seed,
@@ -749,7 +749,7 @@ instanceCommands.add(new libCommand.Command({
handler: async function(args, control) {
let instanceId = await libCommand.resolveInstance(control, args.instance);
await control.setLogSubscriptions({ instance_ids: [instanceId] });
let response = await libLink.messages.stopInstance.send(control, {
await libLink.messages.stopInstance.send(control, {
instance_id: instanceId,
});
},
@@ -760,7 +760,7 @@ instanceCommands.add(new libCommand.Command({
yargs.positional("instance", { describe: "Instance to delete", type: "string" });
}],
handler: async function(args, control) {
let response = await libLink.messages.deleteInstance.send(control, {
await libLink.messages.deleteInstance.send(control, {
instance_id: await libCommand.resolveInstance(control, args.instance),
});
},
+2 -2
View File
@@ -83,7 +83,7 @@ async function build(args) {
for (let entry of await fs.readdir(args.outputDir)) {
let match = splitter.exec(entry);
if (match) {
let [, name, version] = match;
let name = match[1];
if (name === info.name) {
let modPath = path.join(args.outputDir, entry);
console.log(`Removing ${modPath}`);
@@ -94,7 +94,7 @@ async function build(args) {
}
if (info.variants) {
for (let [variant, variantOverrides] of Object.entries(info.variants)) {
for (let variantOverrides of info.variants) {
let variantInfo = {
...info,
...variantOverrides,
+2 -2
View File
@@ -376,9 +376,9 @@ ControlConfig.registerGroup(ControlGroup);
function validateGroup(pluginInfo, groupName) {
if (!pluginInfo[groupName] instanceof classes.PluginConfigGroup) {
if (!(pluginInfo[groupName].prototype instanceof classes.PluginConfigGroup)) {
throw new Error(
`Expected ${groupName} for ${pluginInfo.name} to be an instance of PluginConfigGroup`
`Expected ${groupName} for ${pluginInfo.name} to be a subclass of PluginConfigGroup`
);
}
+1
View File
@@ -791,6 +791,7 @@ class FactorioServer extends events.EventEmitter {
try {
let [code, signal] = await events.once(this._server, "exit");
void signal;
if (code !== 0) {
throw new Error(`Factorio exited with status ${code}`);
}
+1 -1
View File
@@ -445,7 +445,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
return;
}
let { seq, type, data } = message;
let { type, data } = message;
if (type === "hello") {
logger.verbose(`Connector | received hello from master version ${data.version}`);
this.emit("hello", data);
+1 -2
View File
@@ -4,7 +4,6 @@
const libSchema = require("../schema");
const libErrors = require("../errors");
const { logger } = require("../logging");
const messages = require("./messages");
// Some definitions for the terminology used here:
// link: Either side of a master - client connection
@@ -135,7 +134,7 @@ class Link {
* @returns {Boolean} true if a waiter was triggered.
*/
_processWaiters(message) {
let { seq, type, data } = message;
let { type, data } = message;
let waiters = this._waiters.get(type);
if (!waiters || !waiters.length) {
return false;
-1
View File
@@ -3,7 +3,6 @@
* @module lib/shared_commands
*/
"use strict";
const fs = require("fs-extra");
const path = require("path");
const libConfig = require("./config");
+4 -1
View File
@@ -89,12 +89,14 @@ const wsActiveConnectionsGauge = new libPrometheus.Gauge(
"How many WebSocket connections are currently open to the master server",
{ callback: function(gauge) { gauge.set(master.wsServer.activeConnectors.size); }}
);
void wsActiveConnectionsGauge;
const wsActiveSlavesGauge = new libPrometheus.Gauge(
"clusterio_master_active_slaves",
"How many slaves are currently connected to the master",
{ callback: function(gauge) { gauge.set(master.wsServer.slaveConnections.size); }}
);
void wsActiveSlavesGauge;
const masterConnectedClientsCount = new libPrometheus.Gauge(
"clusterio_master_connected_clients_count", "How many clients are currently connected to this master server",
@@ -105,6 +107,7 @@ const masterConnectedClientsCount = new libPrometheus.Gauge(
},
},
);
void masterConnectedClientsCount;
async function handleBootstrapCommand(args, masterConfig) {
@@ -356,7 +359,7 @@ async function startup() {
// add better stack traces on promise rejection
process.on("unhandledRejection", err => logger.error(`Unhandled rejection:\n${err.stack}`));
let { args, shouldRun, clusterLogger, pluginInfos, masterConfigPath, masterConfig } = await initialize(master);
let { args, shouldRun, clusterLogger, pluginInfos, masterConfigPath, masterConfig } = await initialize();
if (!shouldRun) {
return;
}
+1 -1
View File
@@ -385,7 +385,7 @@ class ControlConnection extends BaseConnection {
});
ready.catch(() => {});
let result = await this._master.forwardRequestToInstance(libLink.messages.pushSave, {
await this._master.forwardRequestToInstance(libLink.messages.pushSave, {
instance_id,
stream_id: stream.id,
save,
-1
View File
@@ -1,7 +1,6 @@
"use strict";
const http = require("http");
const https = require("https");
const util = require("util");
/**
* Gracefully close a Node.js HTTP(S) server
+1 -1
View File
@@ -97,7 +97,7 @@ class Master {
}
async start(args) {
if (!this._state === "new") {
if (this._state !== "new") {
throw new Error(`Cannot start in state ${this._state}`);
}
+1 -1
View File
@@ -176,7 +176,7 @@ ${err.stack}`
return;
}
let { seq, type, data } = message;
let { type, data } = message;
if (type === "resume") {
let connector;
-1
View File
@@ -1,4 +1,3 @@
import events from "events";
import React, { useEffect, useState } from "react";
import { BrowserRouter } from "react-router-dom";
@@ -1,4 +1,4 @@
import React, { useEffect, useContext, useState } from "react";
import React, { useEffect, useState } from "react";
import { Button, Card, Checkbox, Form, Input, InputNumber, Space, Spin, Tree, Typography } from "antd";
const { Title } = Typography;
@@ -1,5 +1,5 @@
import React, { useContext, useState } from "react";
import { Button, Col, Form, Input, Modal, Row, Typography } from "antd";
import { Button, Form, Input, Modal } from "antd";
import { libFactorio, libLink } from "@clusterio/lib";
+1 -3
View File
@@ -1,8 +1,6 @@
import React, { useContext } from "react";
import React from "react";
import { Typography } from "antd";
import { libLink } from "@clusterio/lib";
import PageLayout from "./PageLayout";
const { Paragraph } = Typography;
@@ -1,5 +1,4 @@
import React, { useContext } from "react";
import { Typography } from "antd";
import { libConfig, libLink } from "@clusterio/lib";
@@ -20,7 +20,7 @@ import { useInstance } from "../model/instance";
import { useSlave } from "../model/slave";
import InstanceStatusTag from "./InstanceStatusTag";
const { Title, Paragraph } = Typography;
const { Title } = Typography;
export default function InstanceViewPage(props) {
@@ -28,7 +28,7 @@ function CreateInstanceButton(props) {
await instanceConfig.init();
instanceConfig.set("instance.name", values.instanceName);
let serialized_config = instanceConfig.serialize("master");
let result = await libLink.messages.createInstance.send(control, { serialized_config });
await libLink.messages.createInstance.send(control, { serialized_config });
setVisible(false);
history.push(`/instances/${instanceConfig.get("instance.id")}/view`);
}
@@ -1,5 +1,5 @@
import React, { useContext, useState } from "react";
import { Button, Col, Form, Input, Modal, Row, Typography } from "antd";
import { Button, Form, Input, Modal } from "antd";
import { libFactorio, libLink } from "@clusterio/lib";
+3 -3
View File
@@ -1,11 +1,11 @@
import React, { Fragment, useContext } from "react";
import { Button, Card, Divider, Form, Image, Input, List, Space, Spin, Typography } from "antd";
import { Button, Card, Divider, Form, Image, Input, Space, Typography } from "antd";
import LockOutlined from "@ant-design/icons/LockOutlined";
import logo from "../images/logo.png";
import ControlContext from "./ControlContext";
const { Paragraph, Text } = Typography;
const { Paragraph } = Typography;
function TokenAuth(props) {
@@ -22,7 +22,7 @@ function TokenAuth(props) {
>
<Input
style={{ width: "14em" }}
prefix=<LockOutlined className="site-form-item-icon" />
prefix={<LockOutlined className="site-form-item-icon" />}
type="password"
placeholder="Authentication Token"
/>
@@ -1,5 +1,4 @@
import React, { useContext } from "react";
import { Typography } from "antd";
import { libConfig, libLink } from "@clusterio/lib";
@@ -1,4 +1,4 @@
import React, { useContext } from "react";
import React from "react";
import { Typography } from "antd";
import LogConsole from "./LogConsole";
@@ -1,6 +1,6 @@
import React from "react";
import { Link } from "react-router-dom";
import { Layout, Menu, Breadcrumb, Typography } from "antd";
import { Layout, Breadcrumb } from "antd";
const { Content } = Layout;
@@ -1,10 +1,9 @@
import React, { useEffect, useContext, useState } from "react";
import { useHistory, useParams } from "react-router-dom";
import { useParams } from "react-router-dom";
import { Alert, Descriptions, Spin } from "antd";
import ControlContext from "./ControlContext";
import PageLayout from "./PageLayout";
import { notifyErrorHandler } from "../util/notify";
export default function PluginViewPage() {
@@ -1,4 +1,4 @@
import React, { useContext, useState } from "react";
import React from "react";
export default function SectionHeader(props) {
return <div className="section-header">
@@ -1,4 +1,4 @@
import React, { useContext, useState } from "react";
import React from "react";
import { Descriptions, PageHeader, Spin, Tag, Typography } from "antd";
import { useParams } from "react-router-dom";
+1 -1
View File
@@ -1,4 +1,4 @@
import React, { useEffect, useContext, useState } from "react";
import { useEffect, useContext, useState } from "react";
import ControlContext from "../components/ControlContext";
import { libLink, libLogging } from "@clusterio/lib";
+1 -1
View File
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import { useEffect, useState } from "react";
let itemMetadataCache = null;
+1 -1
View File
@@ -1,4 +1,4 @@
import React, { useEffect, useContext, useState } from "react";
import { useEffect, useContext, useState } from "react";
import ControlContext from "../components/ControlContext";
import { libLink, libLogging } from "@clusterio/lib";
+1 -1
View File
@@ -1,4 +1,4 @@
import React, { useEffect, useContext, useState } from "react";
import { useEffect, useContext, useState } from "react";
import ControlContext from "../components/ControlContext";
import { libLink } from "@clusterio/lib";
-1
View File
@@ -4,7 +4,6 @@ const path = require("path");
const libFileOps = require("@clusterio/lib/file_ops");
const libPlugin = require("@clusterio/lib/plugin");
const libErrors = require("@clusterio/lib/errors");
async function loadDatabase(config, logger) {
let itemsPath = path.resolve(config.get("master.database_directory"), "inventories.json");
-1
View File
@@ -3,7 +3,6 @@
*/
"use strict";
const libPlugin = require("@clusterio/lib/plugin");
const libLuaTools = require("@clusterio/lib/lua_tools");
class InstancePlugin extends libPlugin.BaseInstancePlugin {
+1 -1
View File
@@ -78,7 +78,7 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
return;
}
for (let [player, entry] of this.players) {
for (let entry of this.players.values()) {
if (entry.playerCode === playerCode && entry.expires > Date.now()) {
let verifyCode = await generateCode(this.master.config.get("player_auth.code_length"));
let secret = Buffer.from(this.master.config.get("master.auth_secret"), "base64");
+1 -1
View File
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from "react";
import { libPlugin } from "@clusterio/lib";
import { notify, notifyErrorHandler } from "@clusterio/web_ui";
import { notifyErrorHandler } from "@clusterio/web_ui";
import { Button, Form, Input, Spin, Typography } from "antd";
import "./index.css";
+1 -1
View File
@@ -43,7 +43,7 @@ class InstancePlugin extends libPlugin.BaseInstancePlugin {
if (!this.syncStarted || !["starting", "running"].includes(this.instance.status)) {
return;
}
let { name, level, researched } = message.data;
let { name, level } = message.data;
await this.sendOrderedRcon(
`/sc research_sync.research_technology("${libLuaTools.escapeString(name)}", ${level})`, true
);
+3 -5
View File
@@ -62,7 +62,6 @@ function dose(numreq, instore, store_last_tick, dole, carry, prev_req, numreq_to
debt,
]; // 5..12
let inputs = inp1.concat(inp2);
let internal = new Array(20).fill(0);
let outputs = [0, 0, 0, 0];
// NN: Please don't touch :), code is generated
@@ -78,7 +77,7 @@ function dose(numreq, instore, store_last_tick, dole, carry, prev_req, numreq_to
outputs[0]=1.0;
}
let res1 = Number(outputs[0]) * numreq+outputs[3] + debt;
let res1 = Number(outputs[0]) * numreq + outputs[3] + debt;
let res_capped = Math.round(res1);
if (res_capped > numreq) { res_capped = numreq; }
@@ -88,7 +87,7 @@ function dose(numreq, instore, store_last_tick, dole, carry, prev_req, numreq_to
res1 = res1 || 0;
res_capped = res_capped || 0; // Safeguard against wrong values
debt = res1 - res_capped;
debt_cap = Math.round(numreq * 1.5) + 5;
let debt_cap = Math.round(numreq * 1.5) + 5;
if (debt > debt_cap) {
debt = debt_cap;
}
@@ -129,7 +128,6 @@ function tick(instore, dole, store_last_tick, numreq_total_adj) {
store_last_tick,
numreq_total_adj,
];
let internal = new Array(10).fill(0);
let outputs = [0, 0];
// NN: Please don't touch :), code is generated
@@ -139,7 +137,7 @@ function tick(instore, dole, store_last_tick, numreq_total_adj) {
outputs[1] = outputs[0] * 1.828422785;
outputs[1] = sigmoid3(outputs[1]);
avg = outputs[1];
let avg = outputs[1];
if (numreq_total_adj < 0.11) {
// When no item's are requested, result is 0.1; In that case there is
// no deficit, so return 1 = 100% demand fulfilled
-2
View File
@@ -1,6 +1,4 @@
"use strict";
const fs = require("fs-extra");
const libPlugin = require("@clusterio/lib/plugin");
const libLuaTools = require("@clusterio/lib/lua_tools");
-3
View File
@@ -1,7 +1,4 @@
"use strict";
const path = require("path");
function addApiRoutes(app, items, endpointHitCounter) {
/**