Commit 94c834cb authored by aniket-engg's avatar aniket-engg Committed by Aniket

check variable declaration too

parent a3358c38
...@@ -53,7 +53,8 @@ export default class similarVariableNames implements AnalyzerModule { ...@@ -53,7 +53,8 @@ export default class similarVariableNames implements AnalyzerModule {
// Walk through all statements of function // Walk through all statements of function
astWalker.walk(functionBody, (node) => { astWalker.walk(functionBody, (node) => {
// check if these is an identifier node which is one of the tracked similar variables // 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({ warnings.push({
warning: `${funcName} : Variables have very similar names "${sim.var1}" and "${sim.var2}". ${hasModifiersComments} ${multipleContractsWithSameNameComments}`, warning: `${funcName} : Variables have very similar names "${sim.var1}" and "${sim.var2}". ${hasModifiersComments} ${multipleContractsWithSameNameComments}`,
location: node['src'] location: node['src']
......
...@@ -283,7 +283,7 @@ test('Integration test similarVariableNames module', function (t: test.Test) { ...@@ -283,7 +283,7 @@ test('Integration test similarVariableNames module', function (t: test.Test) {
'inheritance.sol': 0, 'inheritance.sol': 0,
'modifier1.sol': 0, 'modifier1.sol': 0,
'modifier2.sol': 0, 'modifier2.sol': 0,
'notReentrant.sol': 3, 'notReentrant.sol': 4,
'structReentrant.sol': 0, 'structReentrant.sol': 0,
'thisLocal.sol': 0, 'thisLocal.sol': 0,
'globals.sol': 0, 'globals.sol': 0,
......
...@@ -279,13 +279,13 @@ test('Integration test similarVariableNames module', function (t: test.Test) { ...@@ -279,13 +279,13 @@ test('Integration test similarVariableNames module', function (t: test.Test) {
'KingOfTheEtherThrone.sol': 0, 'KingOfTheEtherThrone.sol': 0,
'assembly.sol': 0, 'assembly.sol': 0,
'ballot.sol': 7, 'ballot.sol': 7,
'ballot_reentrant.sol': 24, 'ballot_reentrant.sol': 40,
'ballot_withoutWarnings.sol': 0, 'ballot_withoutWarnings.sol': 0,
'cross_contract.sol': 0, 'cross_contract.sol': 0,
'inheritance.sol': 0, 'inheritance.sol': 0,
'modifier1.sol': 0, 'modifier1.sol': 0,
'modifier2.sol': 0, 'modifier2.sol': 0,
'notReentrant.sol': 3, 'notReentrant.sol': 4,
'structReentrant.sol': 0, 'structReentrant.sol': 0,
'thisLocal.sol': 0, 'thisLocal.sol': 0,
'globals.sol': 0, 'globals.sol': 0,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment