From b254e4189d03467b0a5e7b74827df32a6dc07374 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Tue, 16 Jun 2020 19:01:21 +0200 Subject: [PATCH] Use more consistent spacing in objects literals --- clusterctl.js | 2 +- lib/factorio/export.js | 4 +- lib/factorio/patch.js | 2 +- lib/generateSSLcert.js | 2 +- lib/link/messages.js | 10 ++--- master.js | 6 +-- plugins/subspace_storage/dole.js | 2 +- plugins/subspace_storage/dole_nn_base.js | 2 +- plugins/subspace_storage/master.js | 2 +- slave.js | 2 +- test/integration/clusterio.js | 4 +- test/lib/config/classes.js | 4 +- test/lib/database.js | 30 +++++++-------- test/lib/factorio/patch.js | 2 +- test/lib/link/messages.js | 8 ++-- test/lib/objectOps.js | 2 +- test/lib/prometheus.js | 48 ++++++++++++------------ 17 files changed, 66 insertions(+), 66 deletions(-) diff --git a/clusterctl.js b/clusterctl.js index 27764075..f4aabf70 100644 --- a/clusterctl.js +++ b/clusterctl.js @@ -6,7 +6,7 @@ const jwt = require("jsonwebtoken"); const fs = require("fs-extra"); const yargs = require("yargs"); const version = require("./package").version; -const asTable = require("as-table").configure({delimiter: " | "}); +const asTable = require("as-table").configure({ delimiter: " | " }); const chalk = require("chalk"); const events = require("events"); diff --git a/lib/factorio/export.js b/lib/factorio/export.js index d1c104ec..c2bafaed 100644 --- a/lib/factorio/export.js +++ b/lib/factorio/export.js @@ -248,7 +248,7 @@ async function exportItems(server, modVersions, items) { iconSheet.crop(0, 0, width, Math.ceil(pos / (width / size)) * size); - return {iconSheet, itemData}; + return { iconSheet, itemData }; } /** @@ -338,7 +338,7 @@ async function exportData(server) { throw new Error("No items got exported"); } - let {iconSheet, itemData} = await exportItems(server, modVersions, items); + let { iconSheet, itemData } = await exportItems(server, modVersions, items); let locale = await exportLocale(server, modVersions, modOrder, "en"); // Free up the memory used by zip files loaded during the export. diff --git a/lib/factorio/patch.js b/lib/factorio/patch.js index 3aa0f6dd..24f458b0 100644 --- a/lib/factorio/patch.js +++ b/lib/factorio/patch.js @@ -282,7 +282,7 @@ async function patch(savePath, modules) { root.file("clusterio.json", JSON.stringify(patchInfo, null, 4)); // Write back the save - let stream = zip.generateNodeStream({compression: "DEFLATE"}); + let stream = zip.generateNodeStream({ compression: "DEFLATE" }); let pipe = stream.pipe(fs.createWriteStream(savePath)); await events.once(pipe, "finish"); } diff --git a/lib/generateSSLcert.js b/lib/generateSSLcert.js index 5657f9ae..6592047f 100644 --- a/lib/generateSSLcert.js +++ b/lib/generateSSLcert.js @@ -17,7 +17,7 @@ module.exports = async function({ log("Generating SSL certificate with "+bits+" bits at "+sslCertPath); let startNs = hrtime(); - let keypair = await util.promisify(forge.pki.rsa.generateKeyPair)({bits: bits, e: 0x10001}); + let keypair = await util.promisify(forge.pki.rsa.generateKeyPair)({ bits: bits, e: 0x10001 }); log("Generated 2048bit keypair in: "+(Number(hrtime()-startNs) / 1e6)+" ms"); startNs = hrtime(); diff --git a/lib/link/messages.js b/lib/link/messages.js index 683c41ed..d1fdf050 100644 --- a/lib/link/messages.js +++ b/lib/link/messages.js @@ -79,7 +79,7 @@ class Request extends Message { if (forwardTo === "instance") { requestProperties = Object.assign( - {"instance_id": { type: "integer" }}, requestProperties + { "instance_id": { type: "integer" }}, requestProperties ); } else if (forwardTo !== "master" && forwardTo !== null) { @@ -185,7 +185,7 @@ class Request extends Message { response = {}; } - if (!this._responseValidator({ seq: 0, type: this.responseType, response})) { + if (!this._responseValidator({ seq: 0, type: this.responseType, response })) { console.error(this._responseValidator.errors); throw new Error(`Validation failed responding to ${this.requestType}`); } @@ -212,7 +212,7 @@ class Request extends Message { */ async send(link, data = {}) { // XXX validate link target/source? - if (!this._requestValidator({ seq: 0, type: this.requestType, data})) { + if (!this._requestValidator({ seq: 0, type: this.requestType, data })) { console.error(this._requestValidator.errors); throw new Error(`Validation failed sending ${this.requestType}`); } @@ -634,7 +634,7 @@ class Event extends Message { if (forwardTo === "instance") { eventProperties = Object.assign( - {"instance_id": { type: "integer" }}, eventProperties + { "instance_id": { type: "integer" }}, eventProperties ); } else if (forwardTo !== "master" && forwardTo !== null) { @@ -728,7 +728,7 @@ class Event extends Message { * Sends the given event data over the link. */ send(link, data = {}) { - if (!this._eventValidator({ seq: 0, type: this.eventType, data})) { + if (!this._eventValidator({ seq: 0, type: this.eventType, data })) { console.error(this._eventValidator.errors); throw new Error(`Validation failed sending ${this.eventType}`); } diff --git a/master.js b/master.js index 7e8b4df0..33c3be9b 100644 --- a/master.js +++ b/master.js @@ -685,7 +685,7 @@ class ControlConnection extends BaseConnection { throw new errors.RequestError(`Instance with ID ${message.data.instance_id} does not exist`); } - let {field, prop, value} = message.data; + let { field, prop, value } = message.data; instance.config.setProp(field, prop, value); await this.updateInstanceConfig(instance); } @@ -750,7 +750,7 @@ class ControlConnection extends BaseConnection { // Start at 5 to leave space for future default roles let id = Math.max(5, lastId+1); - db.roles.set(id, new users.Role({ id, ...message.data})); + db.roles.set(id, new users.Role({ id, ...message.data })); return { id }; } @@ -951,7 +951,7 @@ class SlaveConnection extends BaseConnection { } async playerEventEventHandler(message) { - let {instance_id, name, type} = message.data; + let { instance_id, name, type } = message.data; let user = db.users.get(name); if (!user) { user = createUser(name); diff --git a/plugins/subspace_storage/dole.js b/plugins/subspace_storage/dole.js index a792301c..e7515038 100644 --- a/plugins/subspace_storage/dole.js +++ b/plugins/subspace_storage/dole.js @@ -49,7 +49,7 @@ class neuralDole { this.getRequestStats(name,5) ); this.stats[name]=this.stats[name] || []; - this.stats[name].unshift({req:0,given:0});//stats[name][0] is the one we currently collect + this.stats[name].unshift({ req:0,given:0 });//stats[name][0] is the one we currently collect if (this.stats[name].length>10) this.stats[name].pop();//remove if too many samples in stats this.dole[name] = magicData[0]; diff --git a/plugins/subspace_storage/dole_nn_base.js b/plugins/subspace_storage/dole_nn_base.js index a5c90bd0..7938e609 100644 --- a/plugins/subspace_storage/dole_nn_base.js +++ b/plugins/subspace_storage/dole_nn_base.js @@ -116,4 +116,4 @@ outputs[1]=sigmoid3(outputs[1]); return [sigmoid0(outputs[0]),avg]; } -module.exports = {Dose,Tick}; \ No newline at end of file +module.exports = { Dose,Tick }; \ No newline at end of file diff --git a/plugins/subspace_storage/master.js b/plugins/subspace_storage/master.js index ea254b2b..9a6bdab5 100644 --- a/plugins/subspace_storage/master.js +++ b/plugins/subspace_storage/master.js @@ -136,7 +136,7 @@ class MasterPlugin extends plugin.BaseMasterPlugin { } else if (method === "dole") { for (let item of message.data.items) { let count = dole.doleDivider({ - object: { name: item[0], count: item[1], instanceId, instanceName}, + object: { name: item[0], count: item[1], instanceId, instanceName }, items: this.items, logItemTransfers: this.master.config.get("subspace_storage.log_item_transfers"), }); diff --git a/slave.js b/slave.js index f340a6b1..b28ea6b0 100644 --- a/slave.js +++ b/slave.js @@ -1253,7 +1253,7 @@ function hashMods(instance, callback) { return null; } else { return hashFile(instance.path("mods", name)).then(hash => ( - {modName: name, hash: hash} + { modName: name, hash: hash } )); } } diff --git a/test/integration/clusterio.js b/test/integration/clusterio.js index 43d34d9c..4d6b8f28 100644 --- a/test/integration/clusterio.js +++ b/test/integration/clusterio.js @@ -202,7 +202,7 @@ describe("Integration of Clusterio", function() { await exec(`node clusterctl --config ${controlConfigPath} create-role --name temp --description "A temp role" --permissions core.control.connect`); let result = await link.messages.listRoles.send(getControl()); let role = result.list.find(role => role.name === "temp"); - assert.deepEqual(role, { id: 5, name: "temp", description: "A temp role", permissions: ["core.control.connect"]}); + assert.deepEqual(role, { id: 5, name: "temp", description: "A temp role", permissions: ["core.control.connect"] }); }); }); @@ -211,7 +211,7 @@ describe("Integration of Clusterio", function() { await exec(`node clusterctl --config ${controlConfigPath} edit-role --role temp --name new --description "A new role" --permissions`); let result = await link.messages.listRoles.send(getControl()); let role = result.list.find(role => role.name === "new"); - assert.deepEqual(role, { id: 5, name: "new", description: "A new role", permissions: []}); + assert.deepEqual(role, { id: 5, name: "new", description: "A new role", permissions: [] }); }); }); diff --git a/test/lib/config/classes.js b/test/lib/config/classes.js index 7c99d305..438f9224 100644 --- a/test/lib/config/classes.js +++ b/test/lib/config/classes.js @@ -253,11 +253,11 @@ describe("lib/config/classes", function() { new Error("Expected fields to be an object, not undefined") ); assert.throws( - () => testInstance.update({ name: "test_group", fields: []}, false), + () => testInstance.update({ name: "test_group", fields: [] }, false), new Error("Expected fields to be an object, not array") ); assert.throws( - () => testInstance.update({ name: "test_group", fields: null}, false), + () => testInstance.update({ name: "test_group", fields: null }, false), new Error("Expected fields to be an object, not null") ); }); diff --git a/test/lib/database.js b/test/lib/database.js index 86c13472..b9329770 100644 --- a/test/lib/database.js +++ b/test/lib/database.js @@ -20,7 +20,7 @@ describe("lib/database", function() { it("should throw convert a map to an object", function() { assert.deepEqual( database.mapToObject(new Map([["a", 1], ["b", true]])), - {"a": 1, "b": true} + { "a": 1, "b": true } ); }); }); @@ -79,7 +79,7 @@ describe("lib/database", function() { ); assert.equal( - await fs.readFile(testFile, {encoding: "utf-8"}), + await fs.readFile(testFile, { encoding: "utf-8" }), '{\n "c": {},\n "d": "foo"\n}' ); }); @@ -121,7 +121,7 @@ describe("lib/database", function() { it("should work on array JSON", async function() { assert.deepEqual( await database.loadJsonArrayAsMap(path.join("test", "file", "json", "load_array_map.json")), - new Map([["a", {id: "a"}], ["b", {id: "b"}]]) + new Map([["a", { id: "a" }], ["b", { id: "b" }]]) ); }); @@ -149,11 +149,11 @@ describe("lib/database", function() { await deleteTestFile(); await database.saveMapAsJsonArray( - testFile, new Map([["c", {id: "c"}], ["d", {id: "d"}]]) + testFile, new Map([["c", { id: "c" }], ["d", { id: "d" }]]) ); assert.equal( - await fs.readFile(testFile, {encoding: "utf-8"}), + await fs.readFile(testFile, { encoding: "utf-8" }), '[\n {\n "id": "c"\n },\n {\n "id": "d"\n }\n]' ); }); @@ -167,18 +167,18 @@ describe("lib/database", function() { }); it("should restore the passed serialized database", function() { - let items = new database.ItemDatabase({"a": 1, "b": 2}); + let items = new database.ItemDatabase({ "a": 1, "b": 2 }); assert.deepEqual(items._items, new Map([["a", 1], ["b", 2]])); }); it("should throw on invalid serialized database", function() { assert.throws( - () => new database.ItemDatabase({"a": NaN}), + () => new database.ItemDatabase({ "a": NaN }), new Error("count must be a number") ); assert.throws( - () => new database.ItemDatabase({"a": "a"}), + () => new database.ItemDatabase({ "a": "a" }), new Error("count must be a number") ); }); @@ -186,26 +186,26 @@ describe("lib/database", function() { describe(".serialize()", function() { it("should return a serialized database", function() { - let items = new database.ItemDatabase({"a": 10}); - assert.deepEqual(items.serialize(), {"a": 10}); + let items = new database.ItemDatabase({ "a": 10 }); + assert.deepEqual(items.serialize(), { "a": 10 }); }); it("should remove zero count entries", function() { - let items = new database.ItemDatabase({"a": 0}); + let items = new database.ItemDatabase({ "a": 0 }); assert.deepEqual(items.serialize(), {}); }); }); describe(".size", function() { it("should give an approximate size of the database", function() { - let items = new database.ItemDatabase({"a": 10}); + let items = new database.ItemDatabase({ "a": 10 }); assert.equal(items.size, 1); }); }); describe(".getItemCount()", function() { it("should return the count of the given item", function() { - let items = new database.ItemDatabase({"a": 10}); + let items = new database.ItemDatabase({ "a": 10 }); assert.equal(items.getItemCount("a"), 10); }); @@ -231,7 +231,7 @@ describe("lib/database", function() { }); it("should add an existing item", function() { - let items = new database.ItemDatabase({"a": 10}); + let items = new database.ItemDatabase({ "a": 10 }); items.addItem("a", 10); assert.deepEqual(items._items, new Map([["a", 20]])); }); @@ -259,7 +259,7 @@ describe("lib/database", function() { describe(".removeItem()", function() { it("should remove an existing item", function() { - let items = new database.ItemDatabase({"a": 20}); + let items = new database.ItemDatabase({ "a": 20 }); items.removeItem("a", 10); assert.deepEqual(items._items, new Map([["a", 10]])); }); diff --git a/test/lib/factorio/patch.js b/test/lib/factorio/patch.js index 21b7a5ac..f6ebb975 100644 --- a/test/lib/factorio/patch.js +++ b/test/lib/factorio/patch.js @@ -213,7 +213,7 @@ describe("lib/factorio", function() { let zip = new jszip(); zip.file("world/control.lua", "-- unknown\n"); let zipPath = path.join("temp", "test", "patch.zip"); - await fs.outputFile(zipPath, await zip.generateAsync({type: "nodebuffer"})); + await fs.outputFile(zipPath, await zip.generateAsync({ type: "nodebuffer" })); await assert.rejects( factorio.patch(zipPath, []), diff --git a/test/lib/link/messages.js b/test/lib/link/messages.js index 1b8ec793..7008f7c6 100644 --- a/test/lib/link/messages.js +++ b/test/lib/link/messages.js @@ -24,7 +24,7 @@ describe("lib/link/messages", function() { describe("constructor", function() { it("should throw on invalid forwardTo", function() { assert.throws( - () => new link.Request({ links: [], forwardTo: "invalid"}), + () => new link.Request({ links: [], forwardTo: "invalid" }), new Error("Invalid forwardTo value invalid") ); }); @@ -87,7 +87,7 @@ describe("lib/link/messages", function() { }; assert.deepEqual( await testRequest.send(testSourceLink, { test: "request" }), - { type: "test_response", request: { type: "test_request", data: {test: "request" }}} + { type: "test_response", request: { type: "test_request", data: { test: "request" }}} ); delete testSourceLink.connector.send; delete testSourceLink.waitFor; @@ -117,13 +117,13 @@ describe("lib/link/messages", function() { describe("constructor", function() { it("should throw on invalid forwardTo", function() { assert.throws( - () => new link.Event({ forwardTo: "invalid"}), + () => new link.Event({ forwardTo: "invalid" }), new Error("Invalid forwardTo value invalid") ); }); it("should throw on invalid broadcastTo", function() { assert.throws( - () => new link.Event({ broadcastTo: "invalid"}), + () => new link.Event({ broadcastTo: "invalid" }), new Error("Invalid broadcastTo value invalid") ); }); diff --git a/test/lib/objectOps.js b/test/lib/objectOps.js index 9943f2f6..ec906df4 100644 --- a/test/lib/objectOps.js +++ b/test/lib/objectOps.js @@ -23,7 +23,7 @@ describe("objectOps.js", function(){ });*/ describe("objectOps.deepclone()", function(){ it("deep clones javascript objects", function(){ - var obj1 = {hello:"world", cat:{legs:4, name:"Kitty", colors:["brown", "yellow", "purple"]}}; + var obj1 = { hello:"world", cat:{ legs:4, name:"Kitty", colors:["brown", "yellow", "purple"] }}; var obj2 = {}; obj2 = objectOps.deepclone(obj1); diff --git a/test/lib/prometheus.js b/test/lib/prometheus.js index 175bd723..34933259 100644 --- a/test/lib/prometheus.js +++ b/test/lib/prometheus.js @@ -258,15 +258,15 @@ describe("lib/prometheus", function() { }); it("should require all labels set at creation", function() { assert.throws( - () => gauge.labels({a: "1"}), + () => gauge.labels({ a: "1" }), new Error("Missing label 'b'") ); assert.throws( - () => gauge.labels({b: "1"}), + () => gauge.labels({ b: "1" }), new Error("Missing label 'a'") ); assert.throws( - () => gauge.labels({a: "1", b: "2", c: "3"}), + () => gauge.labels({ a: "1", b: "2", c: "3" }), new Error("Extra label 'c'") ); assert.throws( @@ -280,7 +280,7 @@ describe("lib/prometheus", function() { }); it("should throw if label value is not a string", function() { assert.throws( - () => gauge.labels({a: "1", b: 2}), + () => gauge.labels({ a: "1", b: 2 }), new Error("Expected value for label 'b' to be a string") ); assert.throws( @@ -289,13 +289,13 @@ describe("lib/prometheus", function() { ); }); it("should initialize a value for the label set", function() { - gauge.labels({ a: "1", b: "2"}); + gauge.labels({ a: "1", b: "2" }); assert(gauge._values.has('a="1",b="2"'), "value was not set"); gauge.labels("4", "5"); assert(gauge._values.has('a="4",b="5"'), "value was not set"); }); it("should return a child supporting the usual methods", function() { - let child = gauge.labels({ a: "1", b: "2"}); + let child = gauge.labels({ a: "1", b: "2" }); child.get(); child.inc(); child.dec(); @@ -316,8 +316,8 @@ describe("lib/prometheus", function() { let gauge = new prometheus.Gauge( "test", "Help", { register: false, labels: ["a", "b"] } ); - gauge.labels({ a: "1", b: "2"}); - gauge.remove({ a: "1", b: "2"}); + gauge.labels({ a: "1", b: "2" }); + gauge.remove({ a: "1", b: "2" }); assert(!gauge._values.has('a="1",b="2"'), "value was not removed"); }); it("should throw when removing the empty label set", function() { @@ -335,7 +335,7 @@ describe("lib/prometheus", function() { gauge.labels("1", "2"); gauge.labels("1", "3"); gauge.labels("4", "6"); - gauge.removeAll({a: "1"}); + gauge.removeAll({ a: "1" }); assert(gauge._values.size <= 1, "Matching labels remained"); assert( gauge._values.has('a="4",b="6"'), @@ -353,7 +353,7 @@ describe("lib/prometheus", function() { "test", "Help", { register: false, labels: ["a", "b"] } ); gauge.labels('x\\\\\n\"\"\n\\', "2"); - gauge.removeAll({a: 'x\\\\\n\"\"\n\\'}); + gauge.removeAll({ a: 'x\\\\\n\"\"\n\\' }); assert(gauge._values.size === 0, "Matching labels remained"); }); }); @@ -362,9 +362,9 @@ describe("lib/prometheus", function() { let gauge = new prometheus.Gauge( "test", "Help", { register: false, labels: ["a", "b"] } ); - gauge.labels({ a: "1", b: "2"}); - gauge.labels({ a: "3", b: "4"}); - gauge.labels({ a: "5", b: "6"}); + gauge.labels({ a: "1", b: "2" }); + gauge.labels({ a: "3", b: "4" }); + gauge.labels({ a: "5", b: "6" }); gauge.clear(); assert(gauge._values.size == 0, "values was not cleared"); }); @@ -485,10 +485,10 @@ describe("lib/prometheus", function() { it("should format labeled metrics", async function() { let registry = new prometheus.CollectorRegistry(); let gauge = new prometheus.Gauge( - "test", "Help", { register: false, labels: ["a", "b"]} + "test", "Help", { register: false, labels: ["a", "b"] } ); - gauge.labels({a: "1", b: "2"}); - gauge.labels({b: "y", a: "x"}); + gauge.labels({ a: "1", b: "2" }); + gauge.labels({ b: "y", a: "x" }); registry.register(gauge); let exposition = await prometheus.exposition(registry.collect()); assert.equal( @@ -502,11 +502,11 @@ describe("lib/prometheus", function() { it("should format Infinity and NaN", async function() { let registry = new prometheus.CollectorRegistry(); let gauge = new prometheus.Gauge( - "test", "Help", { register: false, labels: ["n"]} + "test", "Help", { register: false, labels: ["n"] } ); - gauge.labels({n: "1"}).set(Infinity); - gauge.labels({n: "2"}).set(-Infinity); - gauge.labels({n: "3"}).set(NaN); + gauge.labels({ n: "1" }).set(Infinity); + gauge.labels({ n: "2" }).set(-Infinity); + gauge.labels({ n: "3" }).set(NaN); registry.register(gauge); let exposition = await prometheus.exposition(registry.collect()); assert.equal( @@ -542,7 +542,7 @@ describe("lib/prometheus", function() { samples: new Map([["", 2]]), }, { addLabels: { c: "8" }}), { - metric: {type: "type", name: "name", help: "Help", labels: ["c"]}, + metric: { type: "type", name: "name", help: "Help", labels: ["c"] }, samples: [['c="8"', 2]], } ); @@ -552,7 +552,7 @@ describe("lib/prometheus", function() { samples: new Map([['a="4"', 3]]), }, { addLabels: { c: "8" }}), { - metric: {type: "type", name: "name", help: "Help", labels: ["a", "c"]}, + metric: { type: "type", name: "name", help: "Help", labels: ["a", "c"] }, samples: [['a="4",c="8"', 3]], } ); @@ -564,7 +564,7 @@ describe("lib/prometheus", function() { samples: new Map([["", 2]]), }, { metricName: "new", }), { - metric: {type: "type", name: "new", help: "Help", labels: []}, + metric: { type: "type", name: "new", help: "Help", labels: [] }, samples: [["", 2]], } ); @@ -574,7 +574,7 @@ describe("lib/prometheus", function() { samples: new Map([["", 2]]), }, { metricHelp: "old", }), { - metric: {type: "type", name: "name", help: "old", labels: []}, + metric: { type: "type", name: "name", help: "old", labels: [] }, samples: [["", 2]], } );