From 94c834cb53556ee3a462985b1fe7c33ab94c48b2 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Fri, 29 Jan 2021 20:04:57 +0530 Subject: [PATCH] check variable declaration too --- .../src/solidity-analyzer/modules/similarVariableNames.ts | 3 ++- .../test/analysis/staticAnalysisIntegration-test-0.4.24.ts | 2 +- .../test/analysis/staticAnalysisIntegration-test-0.5.0.ts | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/remix-analyzer/src/solidity-analyzer/modules/similarVariableNames.ts b/libs/remix-analyzer/src/solidity-analyzer/modules/similarVariableNames.ts index ad6186d421..e56057d3ed 100644 --- a/libs/remix-analyzer/src/solidity-analyzer/modules/similarVariableNames.ts +++ b/libs/remix-analyzer/src/solidity-analyzer/modules/similarVariableNames.ts @@ -53,7 +53,8 @@ export default class similarVariableNames implements AnalyzerModule { // Walk through all statements of function astWalker.walk(functionBody, (node) => { // check if these is an identifier node which is one of the tracked similar variables - if (node.nodeType === "Identifier" && (node.name === sim.var1 || node.name === sim.var2)) { + if ((node.nodeType === 'Identifier' || node.nodeType === 'VariableDeclaration') + && (node.name === sim.var1 || node.name === sim.var2)) { warnings.push({ warning: `${funcName} : Variables have very similar names "${sim.var1}" and "${sim.var2}". ${hasModifiersComments} ${multipleContractsWithSameNameComments}`, location: node['src'] diff --git a/libs/remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.4.24.ts b/libs/remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.4.24.ts index 5bc5242139..67607d7a35 100644 --- a/libs/remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.4.24.ts +++ b/libs/remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.4.24.ts @@ -283,7 +283,7 @@ test('Integration test similarVariableNames module', function (t: test.Test) { 'inheritance.sol': 0, 'modifier1.sol': 0, 'modifier2.sol': 0, - 'notReentrant.sol': 3, + 'notReentrant.sol': 4, 'structReentrant.sol': 0, 'thisLocal.sol': 0, 'globals.sol': 0, diff --git a/libs/remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.5.0.ts b/libs/remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.5.0.ts index b1d9d41ef1..780cfa2b63 100644 --- a/libs/remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.5.0.ts +++ b/libs/remix-analyzer/test/analysis/staticAnalysisIntegration-test-0.5.0.ts @@ -279,13 +279,13 @@ test('Integration test similarVariableNames module', function (t: test.Test) { 'KingOfTheEtherThrone.sol': 0, 'assembly.sol': 0, 'ballot.sol': 7, - 'ballot_reentrant.sol': 24, + 'ballot_reentrant.sol': 40, 'ballot_withoutWarnings.sol': 0, 'cross_contract.sol': 0, 'inheritance.sol': 0, 'modifier1.sol': 0, 'modifier2.sol': 0, - 'notReentrant.sol': 3, + 'notReentrant.sol': 4, 'structReentrant.sol': 0, 'thisLocal.sol': 0, 'globals.sol': 0,