From 8586dfb95fea90a9b221816bc913ea9f39b052c4 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Thu, 22 Oct 2020 03:21:23 +0200 Subject: [PATCH] Fix capitalization of constructors Enforce new-cap rule and fix capitalization and mistakes related to constructors. --- .eslintrc.js | 2 +- packages/lib/factorio/patch.js | 6 +++--- packages/master/master.js | 2 +- packages/master/web/components/data-table.jsx | 2 ++ plugins/subspace_storage/dole.js | 8 ++++---- plugins/subspace_storage/dole_nn_base.js | 8 +++----- plugins/subspace_storage/master.js | 2 +- test/integration/patch.js | 6 +++--- test/lib/factorio/patch.js | 12 ++++++------ test/lib/prometheus.js | 2 +- 10 files changed, 25 insertions(+), 25 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 58be78bd..14045381 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -111,7 +111,7 @@ module.exports = { "max-statements-per-line": "off", "multiline-comment-style": ["warn", "separate-lines"], "multiline-ternary": "off", - "new-cap": "warn", + "new-cap": "error", "new-parens": "error", "newline-after-var": "off", "newline-before-return": "off", diff --git a/packages/lib/factorio/patch.js b/packages/lib/factorio/patch.js index e4150a53..7e9fbec6 100644 --- a/packages/lib/factorio/patch.js +++ b/packages/lib/factorio/patch.js @@ -3,7 +3,7 @@ "use strict"; const events = require("events"); const fs = require("fs-extra"); -const jszip = require("jszip"); +const JSZip = require("jszip"); const path = require("path"); const semver = require("semver"); @@ -27,7 +27,7 @@ const knownScenarios = { * Returns the name of the folder that all files in the zip file is * contained in. Throws an error if there are multiple such folders. * - * @param {module:jszip.JSZip} zip - Zip to search through. + * @param {JSZip} zip - Zip to search through. * @returns {string} name of the root folder. * @memberof module:lib/factorio * @private @@ -213,7 +213,7 @@ function reorderDependencies(modules) { * @memberof module:lib/factorio */ async function patch(savePath, modules) { - let zip = await jszip.loadAsync(await fs.readFile(savePath)); + let zip = await JSZip.loadAsync(await fs.readFile(savePath)); let root = zip.folder(findRoot(zip)); let patchInfoFile = root.file("clusterio.json"); diff --git a/packages/master/master.js b/packages/master/master.js index fc1d5081..b1c866f8 100755 --- a/packages/master/master.js +++ b/packages/master/master.js @@ -1751,7 +1751,7 @@ async function startServer() { // Only start listening for connections after all plugins have loaded if (httpPort) { - httpServer = require("http").Server(app); + httpServer = new (require("http").Server)(app); await listen(httpServer, httpPort); console.log("Listening for HTTP on port %s...", httpServer.address().port); } diff --git a/packages/master/web/components/data-table.jsx b/packages/master/web/components/data-table.jsx index e8b5d4fd..9299a1ec 100644 --- a/packages/master/web/components/data-table.jsx +++ b/packages/master/web/components/data-table.jsx @@ -56,6 +56,7 @@ class DataTable extends Component { sorter = sorter || this.state.sorter; // console.log(pagination, filters, sorter) + // eslint-disable-next-line new-cap let data = await this.props.DataFunction(); // await fetchApi(this.state.dataUrl, "post", { // database: this.props.Database, @@ -69,6 +70,7 @@ class DataTable extends Component { console.log(data); data = data || {}; this.setState({ + // eslint-disable-next-line new-cap tableData: this.props.CustomDataFilterFunction ? this.props.CustomDataFilterFunction(data) : data, pagination: { ...pagination, ...data.pagination }, sorter, diff --git a/plugins/subspace_storage/dole.js b/plugins/subspace_storage/dole.js index 67243162..74d995d6 100644 --- a/plugins/subspace_storage/dole.js +++ b/plugins/subspace_storage/dole.js @@ -15,7 +15,7 @@ const prometheusDoleFactorGauge = new Gauge( { labels: ["resource"] } ); -class neuralDole { +class NeuralDole { getRequestStats(itemname,samples) { @@ -46,7 +46,7 @@ class neuralDole { doMagic() { for (let [name, count] of this.items._items) { - let magicData = doleNN.Tick( + let magicData = doleNN.tick( count, this.dole[name], this.itemsLastTick.get(name), @@ -64,7 +64,7 @@ class neuralDole { } divider(object) { - let magicData = doleNN.Dose( + let magicData = doleNN.dose( object.count, // numReq this.items.getItemCount(object.name), this.itemsLastTick.get(object.name) || 0, @@ -131,5 +131,5 @@ function doleDivider({ module.exports = { doleDivider, - neuralDole, + NeuralDole, }; diff --git a/plugins/subspace_storage/dole_nn_base.js b/plugins/subspace_storage/dole_nn_base.js index f4fb8905..7afbf2cf 100644 --- a/plugins/subspace_storage/dole_nn_base.js +++ b/plugins/subspace_storage/dole_nn_base.js @@ -41,8 +41,7 @@ function sigmoid3(x) //1.New dole for item X //2.New carry for item X slave Y //3.New debt -function Dose(numreq,instore,store_last_tick,dole,carry,prev_req,numreq_total_adj,debt) -{ +function dose(numreq, instore, store_last_tick, dole, carry, prev_req, numreq_total_adj, debt) { numreq=Number(numreq); instore=Number(instore); var instore_adj=instore; @@ -96,8 +95,7 @@ function Dose(numreq,instore,store_last_tick,dole,carry,prev_req,numreq_total_ad //Returns: Array of 2 elements //0.New dole for item X //1.Guessed percentage average of items supplied in last 10 ticks -function Tick(instore,dole,store_last_tick,numreq_total_adj) -{ +function tick(instore, dole, store_last_tick, numreq_total_adj) { var instore_adj=instore; if (instore_adj === 0) { instore_adj = 0.1; @@ -121,4 +119,4 @@ function Tick(instore,dole,store_last_tick,numreq_total_adj) return [sigmoid0(outputs[0]),avg]; } -module.exports = { Dose,Tick }; +module.exports = { dose, tick }; diff --git a/plugins/subspace_storage/master.js b/plugins/subspace_storage/master.js index 079ac384..cd51f3dd 100644 --- a/plugins/subspace_storage/master.js +++ b/plugins/subspace_storage/master.js @@ -40,7 +40,7 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin { }); }, this.master.config.get("subspace_storage.autosave_interval") * 1000); - this.neuralDole = new dole.neuralDole({ items: this.items }); + this.neuralDole = new dole.NeuralDole({ items: this.items }); this.doleMagicId = setInterval(() => { if (this.master.config.get("subspace_storage.division_method") === "neural_dole") { this.neuralDole.doMagic(); diff --git a/test/integration/patch.js b/test/integration/patch.js index 8ce16eb6..74d3c849 100644 --- a/test/integration/patch.js +++ b/test/integration/patch.js @@ -1,7 +1,7 @@ "use strict"; const assert = require("assert").strict; const fs = require("fs-extra"); -const jszip = require("jszip"); +const JSZip = require("jszip"); const path = require("path"); const libFactorio = require("@clusterio/lib/factorio"); @@ -33,14 +33,14 @@ describe("Integration of lib/factorio/patch", function() { require: [], }]); - let zip = await jszip.loadAsync(await fs.readFile(savePath)); + let zip = await JSZip.loadAsync(await fs.readFile(savePath)); assert.equal(await zip.file("test/modules/test/test.lua").async("string"), "-- test\n"); assert.equal(await zip.file("test/modules/subdir/dir/test.lua").async("string"), "-- test\n"); }); it("should remove old modules in a save", async function() { slowTest(this); await libFactorio.patch(savePath, []); - let zip = await jszip.loadAsync(await fs.readFile(savePath)); + let zip = await JSZip.loadAsync(await fs.readFile(savePath)); assert.equal(zip.file("test/modules/test/test.lua"), null); }); }); diff --git a/test/lib/factorio/patch.js b/test/lib/factorio/patch.js index 85cc65e1..d5d1bdfb 100644 --- a/test/lib/factorio/patch.js +++ b/test/lib/factorio/patch.js @@ -1,7 +1,7 @@ "use strict"; const assert = require("assert").strict; const fs = require("fs-extra"); -const jszip = require("jszip"); +const JSZip = require("jszip"); const path = require("path"); const libFactorio = require("@clusterio/lib/factorio"); @@ -10,7 +10,7 @@ const libFactorio = require("@clusterio/lib/factorio"); describe("lib/factorio", function() { describe("findRoot()", function() { it("should find the root of a zip", function() { - let zip = new jszip(); + let zip = new JSZip(); zip.file("root/foo.txt", ""); zip.file("root/bar.txt", ""); @@ -18,7 +18,7 @@ describe("lib/factorio", function() { }); it("should throw if files are at the root of the zip", function() { - let zip = new jszip(); + let zip = new JSZip(); zip.file("root/foo.txt", ""); zip.file("bar.txt", ""); @@ -29,7 +29,7 @@ describe("lib/factorio", function() { }); it("should throw if there are multiple root dirs", function() { - let zip = new jszip(); + let zip = new JSZip(); zip.file("root-1/foo.txt", ""); zip.file("root-2/bar.txt", ""); @@ -40,7 +40,7 @@ describe("lib/factorio", function() { }); it("should throw if given an empty zip file", function() { - let zip = new jszip(); + let zip = new JSZip(); assert.throws( () => libFactorio._findRoot(zip), @@ -211,7 +211,7 @@ describe("lib/factorio", function() { describe("patch()", function() { it("should throw on unknown scenario", async function() { - let zip = new jszip(); + 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" })); diff --git a/test/lib/prometheus.js b/test/lib/prometheus.js index 51b70039..adef36c5 100644 --- a/test/lib/prometheus.js +++ b/test/lib/prometheus.js @@ -582,7 +582,7 @@ describe("lib/prometheus", function() { }); it("should throw on unrecoginzed option", function() { assert.throws( - () => new prometheus.serializeResult({ + () => prometheus.serializeResult({ metric: new prometheus.Metric("type", "name", "Help"), samples: new Map([["", 3]]), }, { invalid: true }),