From 4967d176b9ec7ace3eff099d281ca50b3177c90f Mon Sep 17 00:00:00 2001 From: Itms Date: Sun, 16 Jun 2019 20:48:28 +0000 Subject: [PATCH] Define variables before mentioning them in scripted component tests, and add a linter rule for this. Patch By: Krinkle Differential Revision: https://code.wildfiregames.com/D1986 This was SVN commit r22380. --- .../simulation/components/tests/test_Barter.js | 3 +-- .../components/tests/test_Foundation.js | 15 ++++++++------- build/jenkins/lint-config/eslintrc.json | 1 + 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/tests/test_Barter.js b/binaries/data/mods/public/simulation/components/tests/test_Barter.js index e4fd99ee60..a1ae64ea06 100644 --- a/binaries/data/mods/public/simulation/components/tests/test_Barter.js +++ b/binaries/data/mods/public/simulation/components/tests/test_Barter.js @@ -36,6 +36,7 @@ let multiplier = { "metal": 1.0 } }; +let cmpBarter = ConstructComponent(SYSTEM_ENTITY, "Barter"); AddMock(SYSTEM_ENTITY, IID_Timer, { "CancelTimer": id => { timerActivated = false; }, @@ -47,8 +48,6 @@ AddMock(SYSTEM_ENTITY, IID_Timer, { } }); -let cmpBarter = ConstructComponent(SYSTEM_ENTITY, "Barter"); - // Init TS_ASSERT_EQUALS(cmpBarter.restoreTimer, undefined); TS_ASSERT_UNEVAL_EQUALS(cmpBarter.priceDifferences, { "wood": 0, "stone": 0, "metal": 0 }); diff --git a/binaries/data/mods/public/simulation/components/tests/test_Foundation.js b/binaries/data/mods/public/simulation/components/tests/test_Foundation.js index a5b902d4fe..2ffa5b351e 100644 --- a/binaries/data/mods/public/simulation/components/tests/test_Foundation.js +++ b/binaries/data/mods/public/simulation/components/tests/test_Foundation.js @@ -18,6 +18,13 @@ function testFoundation(...mocks) { ResetState(); + let finalTemplate = "structures/athen_civil_centre.xml"; + let foundationHP = 1; + let maxHP = 100; + let rot = new Vector3D(1, 2, 3); + let pos = new Vector2D(4, 5); + let cmpFoundation; + AddMock(SYSTEM_ENTITY, IID_Trigger, { "CallEvent": () => {}, }); @@ -40,12 +47,6 @@ function testFoundation(...mocks) }); Engine.RegisterGlobal("MT_EntityRenamed", "entityRenamed"); - let finalTemplate = "structures/athen_civil_centre.xml"; - let foundationHP = 1; - let maxHP = 100; - let rot = new Vector3D(1, 2, 3); - let pos = new Vector2D(4, 5); - AddMock(foundationEnt, IID_Cost, { "GetBuildTime": () => 50, "GetResourceCosts": () => ({ "wood": 100 }), @@ -119,7 +120,7 @@ function testFoundation(...mocks) TS_ASSERT_EQUALS(template, "construction|" + finalTemplate); return previewEnt; }; - let cmpFoundation = ConstructComponent(foundationEnt, "Foundation", {}); + cmpFoundation = ConstructComponent(foundationEnt, "Foundation", {}); cmpFoundation.InitialiseConstruction(player, finalTemplate); TS_ASSERT_EQUALS(cmpFoundation.owner, player); diff --git a/build/jenkins/lint-config/eslintrc.json b/build/jenkins/lint-config/eslintrc.json index f2b34ff325..38f701a708 100644 --- a/build/jenkins/lint-config/eslintrc.json +++ b/build/jenkins/lint-config/eslintrc.json @@ -19,6 +19,7 @@ "no-negated-in-lhs": 1, "no-obj-calls": 1, "no-unreachable": 1, + "no-use-before-define": ["error", "nofunc"], "use-isnan": 1, "valid-jsdoc": 0, "valid-typeof": 1,