From a84f2d5eb609bedb2fd2dcbe7a787e62f9f262a0 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Wed, 21 Oct 2020 21:51:04 +0200 Subject: [PATCH] Use strict equality checking Remove usage of == and != in favour of === and !==. --- .eslintrc.js | 2 +- packages/lib/database.js | 4 ++-- packages/lib/factorio/server.js | 2 +- packages/lib/link/connectors.js | 2 +- packages/lib/objectOps.js | 2 +- plugins/research_sync/master.js | 2 +- plugins/subspace_storage/dole.js | 4 +++- plugins/subspace_storage/dole_nn_base.js | 8 ++++++-- plugins/subspace_storage/test/routes.js | 4 +++- test/integration/index.js | 2 +- test/integration/server.js | 2 +- test/lib/prometheus.js | 14 +++++++------- test/slave.js | 2 +- 13 files changed, 29 insertions(+), 21 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 587057d2..bfc5b434 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -73,7 +73,7 @@ module.exports = { "dot-location": ["error", "property"], "dot-notation": ["warn", { "allowKeywords": true }], "eol-last": "error", - "eqeqeq": "warn", + "eqeqeq": "error", "func-call-spacing": "error", "func-name-matching": "error", "func-names": "off", diff --git a/packages/lib/database.js b/packages/lib/database.js index 7dce0451..b6bd5646 100644 --- a/packages/lib/database.js +++ b/packages/lib/database.js @@ -55,7 +55,7 @@ async function loadJsonAsMap(filePath) { return new Map(Object.entries(parsed)); } catch (err) { - if (err.code == "ENOENT") { + if (err.code === "ENOENT") { // File does not exist, return empty map return new Map(); @@ -117,7 +117,7 @@ async function loadJsonArrayAsMap(filePath) { return map; } catch (err) { - if (err.code == "ENOENT") { + if (err.code === "ENOENT") { // File does not exist, return empty map return new Map(); diff --git a/packages/lib/factorio/server.js b/packages/lib/factorio/server.js index 04c88e87..6904c982 100644 --- a/packages/lib/factorio/server.js +++ b/packages/lib/factorio/server.js @@ -183,7 +183,7 @@ async function generatePassword(length) { if (validChar(byte)) { password += String.fromCharCode(byte); - if (password.length == length) { + if (password.length === length) { return password; } } diff --git a/packages/lib/link/connectors.js b/packages/lib/link/connectors.js index d3f3fe1f..094146e1 100644 --- a/packages/lib/link/connectors.js +++ b/packages/lib/link/connectors.js @@ -352,7 +352,7 @@ class WebSocketClientConnector extends WebSocketBaseConnector { } let { seq, type, data } = message; - if (type == "hello") { + if (type === "hello") { console.log(`SOCKET | received hello from master version ${data.version}`); this.emit("hello", data); if (this._sessionToken) { diff --git a/packages/lib/objectOps.js b/packages/lib/objectOps.js index 47b9a4fa..cecc7bcb 100644 --- a/packages/lib/objectOps.js +++ b/packages/lib/objectOps.js @@ -39,7 +39,7 @@ module.exports.isJSON = function(string){ } catch (e){ return false; } - if(typeof x == "object" || typeof string == "object"){ + if (typeof x === "object" || typeof string === "object"){ stringIsJson = true; } return stringIsJson; diff --git a/plugins/research_sync/master.js b/plugins/research_sync/master.js index 14d4104d..5f43fd35 100644 --- a/plugins/research_sync/master.js +++ b/plugins/research_sync/master.js @@ -118,7 +118,7 @@ class MasterPlugin extends plugin.BaseMasterPlugin { this.technologies.set(name, { level, progress, researched }); if (progress) { this.progressToBroadcast.add(name); - } else if (researched || baseLevel(name) != level) { + } else if (researched || baseLevel(name) !== level) { this.broadcastEventToSlaves(this.info.messages.finished, { name, level }); } diff --git a/plugins/subspace_storage/dole.js b/plugins/subspace_storage/dole.js index 3f49a27a..8ccb64d2 100644 --- a/plugins/subspace_storage/dole.js +++ b/plugins/subspace_storage/dole.js @@ -25,7 +25,9 @@ class neuralDole { for (var i = 1; i <= samples; i++) { sum+=this.stats[itemname][i].req; } - if (sum==0) return 0.1; + if (sum === 0) { + return 0.1; + } return sum/samples; } diff --git a/plugins/subspace_storage/dole_nn_base.js b/plugins/subspace_storage/dole_nn_base.js index dc978ebc..f4fb8905 100644 --- a/plugins/subspace_storage/dole_nn_base.js +++ b/plugins/subspace_storage/dole_nn_base.js @@ -46,7 +46,9 @@ function Dose(numreq,instore,store_last_tick,dole,carry,prev_req,numreq_total_ad numreq=Number(numreq); instore=Number(instore); var instore_adj=instore; - if (instore_adj==0) instore_adj=0.1; + if (instore_adj === 0) { + instore_adj = 0.1; + } var b=Math.trunc(prev_req/instore_adj*numreq); var inp1=[numreq,instore_adj,store_last_tick/numreq,dole,carry];//0..4 @@ -97,7 +99,9 @@ function Dose(numreq,instore,store_last_tick,dole,carry,prev_req,numreq_total_ad function Tick(instore,dole,store_last_tick,numreq_total_adj) { var instore_adj=instore; - if (instore_adj==0) instore_adj=0.1; + if (instore_adj === 0) { + instore_adj = 0.1; + } var inputs=[instore,dole,store_last_tick/instore_adj,store_last_tick/numreq_total_adj,store_last_tick,numreq_total_adj]; var internal=new Array(10).fill(0); var outputs=[0,0]; diff --git a/plugins/subspace_storage/test/routes.js b/plugins/subspace_storage/test/routes.js index cd6c9366..fe770729 100644 --- a/plugins/subspace_storage/test/routes.js +++ b/plugins/subspace_storage/test/routes.js @@ -17,7 +17,9 @@ describe("subspace_storage endpoints", function() { let contains20SteelPlate = false; inventory.forEach(itemStack => { - if(itemStack.name == "steel-plate" && itemStack.count >= 20) contains20SteelPlate = true; + if (itemStack.name === "steel-plate" && itemStack.count >= 20) { + contains20SteelPlate = true; + } }); assert(contains20SteelPlate, "Please ensure there are at least 20 steel plate in the inventory"); }); diff --git a/test/integration/index.js b/test/integration/index.js index 873dacc1..49f1a1f7 100644 --- a/test/integration/index.js +++ b/test/integration/index.js @@ -50,7 +50,7 @@ async function get(path) { url: `https://localhost:4443${path}`, core: { rejectUnauthorized: false }, }); - if (res.statusCode != 200) { + if (res.statusCode !== 200) { throw new Error(`Got response code ${res.statusCode}, content: ${res.body}`); } return res; diff --git a/test/integration/server.js b/test/integration/server.js index 0fe8f915..d5c472e0 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -204,7 +204,7 @@ describe("Integration of lib/factorio/server", function() { describe(".start() termination detection", function() { it("should tell if Factorio got killed", async function() { // This does not work on Windows - if (process.platform == "win32") { + if (process.platform === "win32") { this.skip(); } slowTest(this); diff --git a/test/lib/prometheus.js b/test/lib/prometheus.js index f693c183..51b70039 100644 --- a/test/lib/prometheus.js +++ b/test/lib/prometheus.js @@ -87,7 +87,7 @@ describe("lib/prometheus", function() { prometheus.defaultRegistry.unregister(collector); } assert( - prometheus.defaultRegistry.collectors.length == 0, + prometheus.defaultRegistry.collectors.length === 0, "Collectors left over after removing the default ones" ); }); @@ -367,7 +367,7 @@ describe("lib/prometheus", function() { gauge.labels({ a: "3", b: "4" }); gauge.labels({ a: "5", b: "6" }); gauge.clear(); - assert(gauge._values.size == 0, "values was not cleared"); + assert(gauge._values.size === 0, "values was not cleared"); }); it("should throw when used on an unlabled metric", function() { let gauge = new prometheus.Gauge("test", "Help", { register: false }); @@ -389,7 +389,7 @@ describe("lib/prometheus", function() { } assert( - results.length == 1, + results.length === 1, "collector did not give exactly one result" ); @@ -409,7 +409,7 @@ describe("lib/prometheus", function() { } assert( - results.length == 1, + results.length === 1, "collector did not give exactly one result" ); @@ -430,7 +430,7 @@ describe("lib/prometheus", function() { } assert( - results.length == 1, + results.length === 1, "collector did not give exactly one result" ); @@ -451,7 +451,7 @@ describe("lib/prometheus", function() { } assert( - results.length == 1, + results.length === 1, "collector did not give exactly one result" ); @@ -604,7 +604,7 @@ describe("lib/prometheus", function() { it("should not have any collectors in the default registry", function() { this.skip(); // XXX Doesn't work in Clusterio's shared testing env assert( - prometheus.defaultRegistry.collectors.length == 0, + prometheus.defaultRegistry.collectors.length === 0, "Collectors left over by test code" ); }); diff --git a/test/slave.js b/test/slave.js index bb10399e..f3c079d4 100644 --- a/test/slave.js +++ b/test/slave.js @@ -140,7 +140,7 @@ describe("Slave testing", function() { it("should unlink removed mods", async function() { // This does not work on Windows - if (process.platform == "win32") { + if (process.platform === "win32") { this.skip(); }