mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-15 15:24:52 +09:00
Fix misc problems detected by ESLint
Reformat and clean up issues detected by ESLint.
This commit is contained in:
1 parent
8cb21c5fa8
commit
e9f5cae4f0
34 files changed
+132
-189
No files matched your search
+9
-11
@@ -395,7 +395,7 @@ class ConfigGroup {
|
||||
value = Number.parseFloat(value);
|
||||
}
|
||||
|
||||
} else if (def.type === "object" ) {
|
||||
} else if (def.type === "object") {
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
} catch (err) {
|
||||
@@ -409,10 +409,8 @@ class ConfigGroup {
|
||||
throw new InvalidValue(`Field ${name} cannot be null`);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (basicType(value) !== def.type) {
|
||||
throw new InvalidValue(`Expected type of ${name} to be ${def.type}, not ${basicType(value)}`);
|
||||
}
|
||||
} else if (basicType(value) !== def.type) {
|
||||
throw new InvalidValue(`Expected type of ${name} to be ${def.type}, not ${basicType(value)}`);
|
||||
}
|
||||
|
||||
let prev = this._fields.get(name);
|
||||
@@ -493,10 +491,9 @@ class ConfigGroup {
|
||||
if (value !== null && basicType(value) !== def.type) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (basicType(value) !== def.type) {
|
||||
continue;
|
||||
}
|
||||
|
||||
} else if (basicType(value) !== def.type) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (def.enum && !def.enum.includes(value)) {
|
||||
@@ -655,10 +652,11 @@ class ConfigGroup {
|
||||
throw new Error(`Config field ${item.name} has already been defined`);
|
||||
}
|
||||
|
||||
let computed = Object.assign({
|
||||
let computed = {
|
||||
optional: false,
|
||||
fullName: `${this.groupName}.${item.name}`,
|
||||
}, item);
|
||||
...item,
|
||||
};
|
||||
|
||||
if (!computed.optional && computed.initial_value === undefined) {
|
||||
throw new Error(`Non-optional field ${item.name} needs an initial_value`);
|
||||
|
||||
@@ -144,7 +144,6 @@ async function saveMapAsJsonArray(filePath, map) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
function checkName(name) {
|
||||
if (typeof name !== "string") {
|
||||
throw new Error("name must be a string");
|
||||
|
||||
@@ -196,6 +196,7 @@ async function exportItems(server, modVersions, items) {
|
||||
iconLayer.scale(realScale);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-loop-func
|
||||
iconLayer.scan(0, 0, iconLayer.bitmap.width, iconLayer.bitmap.height, function(x, y, sidx) {
|
||||
x += xs;
|
||||
y += ys;
|
||||
|
||||
@@ -167,9 +167,9 @@ function randomDynamicPort() {
|
||||
async function generatePassword(length) {
|
||||
function validChar(byte) {
|
||||
const ranges = ["az", "AZ", "09"];
|
||||
return ranges.some(range =>
|
||||
return ranges.some(range => (
|
||||
range.codePointAt(0) <= byte && byte <= range.codePointAt(1)
|
||||
);
|
||||
));
|
||||
}
|
||||
let randomBytesAsync = util.promisify(crypto.randomBytes);
|
||||
|
||||
@@ -559,9 +559,9 @@ class FactorioServer extends events.EventEmitter {
|
||||
let channel = line
|
||||
.slice(6, channelEnd)
|
||||
.toString("utf-8")
|
||||
.replace(/\\x([0-9a-f]{2})/g, (match, p1) =>
|
||||
.replace(/\\x([0-9a-f]{2})/g, (match, p1) => (
|
||||
String.fromCharCode(parseInt(p1, 16))
|
||||
)
|
||||
))
|
||||
;
|
||||
|
||||
let type = line.slice(channelEnd + 1, channelEnd + 2).toString("utf-8");
|
||||
@@ -619,10 +619,8 @@ class FactorioServer extends events.EventEmitter {
|
||||
if (!expected.includes(output[name])) {
|
||||
continue heuristicLoop;
|
||||
}
|
||||
} else {
|
||||
if (expected !== output[name]) {
|
||||
continue heuristicLoop;
|
||||
}
|
||||
} else if (expected !== output[name]) {
|
||||
continue heuristicLoop;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -651,7 +649,7 @@ class FactorioServer extends events.EventEmitter {
|
||||
};
|
||||
|
||||
this._rconClient = new rconClient.Rcon(config);
|
||||
this._rconClient.on("error", err => { /* Ignore */ });
|
||||
this._rconClient.on("error", () => { /* Ignore */ });
|
||||
this._rconClient.on("authenticated", () => { this._rconReady = true; this.emit("rcon-ready"); });
|
||||
this._rconClient.on("end", () => {
|
||||
this._rconClient = null;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"use strict";
|
||||
const fileOps = require("./fileOps");
|
||||
module.exports = fileOps;
|
||||
module.exports = fileOps;
|
||||
@@ -310,18 +310,6 @@ class WebSocketClientConnector extends WebSocketBaseConnector {
|
||||
console.error("SOCKET | Error:", err);
|
||||
});
|
||||
|
||||
/*
|
||||
this._socket.on("unexpected-response", (req, res) => {
|
||||
let data = "";
|
||||
res.on('data', (chunk) => { data += chunk; });
|
||||
res.on('end', () => {
|
||||
console.error(`SOCKET | Unexpeced Response ${res.statusCode}`);
|
||||
console.error(data);
|
||||
this._socket.emit("error", new Error(`Unexpected Response ${res.statusCode}`));
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
this._socket.on("open", () => {
|
||||
console.log("SOCKET | Open");
|
||||
});
|
||||
|
||||
+10
-8
@@ -11,8 +11,8 @@ const errors = require("lib/errors");
|
||||
class Message {
|
||||
/**
|
||||
* Name of the plugin this message belongs to, or null.
|
||||
* @returns {?string}
|
||||
**/
|
||||
* @returns {?string} - plugin name or null if not from a plugin.
|
||||
*/
|
||||
get plugin() {
|
||||
if (this._plugin === undefined) {
|
||||
let index = this.type.indexOf(":");
|
||||
@@ -78,9 +78,10 @@ class Request extends Message {
|
||||
}
|
||||
|
||||
if (forwardTo === "instance") {
|
||||
requestProperties = Object.assign(
|
||||
{ "instance_id": { type: "integer" }}, requestProperties
|
||||
);
|
||||
requestProperties = {
|
||||
"instance_id": { type: "integer" },
|
||||
...requestProperties,
|
||||
};
|
||||
|
||||
} else if (forwardTo !== "master" && forwardTo !== null) {
|
||||
throw new Error(`Invalid forwardTo value ${forwardTo}`);
|
||||
@@ -635,9 +636,10 @@ class Event extends Message {
|
||||
this.broadcastTo = broadcastTo;
|
||||
|
||||
if (forwardTo === "instance") {
|
||||
eventProperties = Object.assign(
|
||||
{ "instance_id": { type: "integer" }}, eventProperties
|
||||
);
|
||||
eventProperties = {
|
||||
"instance_id": { type: "integer" },
|
||||
...eventProperties,
|
||||
};
|
||||
|
||||
} else if (forwardTo !== "master" && forwardTo !== null) {
|
||||
throw new Error(`Invalid forwardTo value ${forwardTo}`);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// This file will be rewritten from scratch
|
||||
/* eslint-disable */
|
||||
/**
|
||||
Provides tools to manage mods in a clusterio install
|
||||
@module
|
||||
|
||||
@@ -26,7 +26,7 @@ function download(url, file, callback){
|
||||
// this might be an invalid path!
|
||||
fs.stat(pathArray.join("/"), (err, stat) => {
|
||||
if(err){
|
||||
makeDirectory(pathArray.join("/")).then(()=>{
|
||||
makeDirectory(pathArray.join("/")).then(() => {
|
||||
doDownload(url, file, callback);
|
||||
});
|
||||
} else {
|
||||
@@ -82,7 +82,7 @@ let downloadList = [
|
||||
// initiate folder creations and downloads
|
||||
function processMkdirRecursive(callback){
|
||||
let item = directories.shift();
|
||||
makeDirectory(item).then(()=>{
|
||||
makeDirectory(item).then(() => {
|
||||
if(directories.length == 0){
|
||||
if(callback) callback();
|
||||
} else {
|
||||
@@ -92,7 +92,7 @@ function processMkdirRecursive(callback){
|
||||
}
|
||||
function processDownloadRecursive(callback){
|
||||
let item = downloadList.shift();
|
||||
download(item.url, item.file, item.callback).then(()=>{
|
||||
download(item.url, item.file, item.callback).then(() => {
|
||||
if(downloadList.length == 0){
|
||||
if(callback) callback();
|
||||
} else {
|
||||
|
||||
+25
-24
@@ -1,35 +1,36 @@
|
||||
/**
|
||||
Helper functions related to objects
|
||||
@module
|
||||
*/
|
||||
* Helper functions related to objects
|
||||
* @module
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
Deep clones an object, is actually just JSON.parse(JSON.stringify()) but looks cleaner.
|
||||
@param {object} obj to clone
|
||||
@returns {object} The cloned object.
|
||||
|
||||
@example
|
||||
a = {"thingy":"with a value"};
|
||||
b = a;
|
||||
a == b; // true
|
||||
c = objectOps.deepclone(a);
|
||||
a == c; // false
|
||||
*/
|
||||
* Deep clones an object, is actually just JSON.parse(JSON.stringify()) but looks cleaner.
|
||||
* @param {object} obj to clone
|
||||
* @returns {object} The cloned object.
|
||||
*
|
||||
* @example
|
||||
* a = {"thingy":"with a value"};
|
||||
* b = a;
|
||||
* a == b; // true
|
||||
* c = objectOps.deepclone(a);
|
||||
* a == c; // false
|
||||
*/
|
||||
module.exports.deepclone = function(obj){
|
||||
return JSON.parse(JSON.stringify(obj));
|
||||
};
|
||||
/**
|
||||
Checks if a string is valid JSON using try/catch. If passed an object it will always return true.
|
||||
@param {string} string to verify
|
||||
@returns {boolean} true if valid JSON.
|
||||
|
||||
@example
|
||||
objectOps.isJSON("99 bottles of beer"); // false
|
||||
objectOps.isJSON("99"); // true
|
||||
objectOps.isJSON({"thingy":"that is an object"}); // true
|
||||
objectOps.isJSON(JSON.stringify({"thingy":"that is an object"})); // true
|
||||
*/
|
||||
/**
|
||||
* Checks if a string is valid JSON using try/catch. If passed an object it will always return true.
|
||||
* @param {string} string to verify
|
||||
* @returns {boolean} true if valid JSON.
|
||||
*
|
||||
* @example
|
||||
* objectOps.isJSON("99 bottles of beer"); // false
|
||||
* objectOps.isJSON("99"); // true
|
||||
* objectOps.isJSON({"thingy":"that is an object"}); // true
|
||||
* objectOps.isJSON(JSON.stringify({"thingy":"that is an object"})); // true
|
||||
*/
|
||||
module.exports.isJSON = function(string){
|
||||
let stringIsJson = false;
|
||||
let x;
|
||||
|
||||
+3
-3
@@ -167,9 +167,9 @@ class ValueCollector extends Collector {
|
||||
function removeMatchingLabels(mapping, labels) {
|
||||
for (let key of mapping.keys()) {
|
||||
let candidate = keyToLabels(key);
|
||||
let hasLabels = Object.entries(labels).every(([name, value]) => {
|
||||
return candidate.get(name) === value;
|
||||
});
|
||||
let hasLabels = Object.entries(labels).every(([name, value]) => (
|
||||
candidate.get(name) === value
|
||||
));
|
||||
if (hasLabels) {
|
||||
mapping.delete(key);
|
||||
}
|
||||
|
||||
+2
-2
@@ -74,7 +74,7 @@ const serverHandshake = ajv.compile({
|
||||
$schema: "http://json-schema.org/draft-07/schema#",
|
||||
title: "Server Handshake",
|
||||
description: "Message sent from the server to a client during the handshake",
|
||||
allOf: [ messageSchema ],
|
||||
allOf: [messageSchema],
|
||||
anyOf: [
|
||||
{
|
||||
properties: {
|
||||
@@ -137,7 +137,7 @@ const clientHandshake = ajv.compile({
|
||||
$schema: "http://json-schema.org/draft-07/schema#",
|
||||
title: "Client Message",
|
||||
description: "Message sent from a client to the server",
|
||||
allOf: [ messageSchema ],
|
||||
allOf: [messageSchema],
|
||||
anyOf: [
|
||||
{
|
||||
properties: {
|
||||
|
||||
Reference in new issue
Block a user