Commit a6a173d3 authored by aniket-engg's avatar aniket-engg Committed by Aniket

handle similar names location

parent c0e9da3b
...@@ -4,6 +4,7 @@ import { default as algorithm } from './algorithmCategories' ...@@ -4,6 +4,7 @@ import { default as algorithm } from './algorithmCategories'
import AbstractAst from './abstractAstView' import AbstractAst from './abstractAstView'
import { get } from 'fast-levenshtein' import { get } from 'fast-levenshtein'
import { util } from '@remix-project/remix-lib' import { util } from '@remix-project/remix-lib'
import { AstWalker } from '@remix-project/remix-astwalker'
import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, ContractHLAst, FunctionHLAst, VariableDeclarationAstNode, VisitFunction, ReportFunction, SupportedVersion} from './../../types' import { AnalyzerModule, ModuleAlgorithm, ModuleCategory, ReportObj, ContractHLAst, FunctionHLAst, VariableDeclarationAstNode, VisitFunction, ReportFunction, SupportedVersion} from './../../types'
interface SimilarRecord { interface SimilarRecord {
...@@ -43,13 +44,20 @@ export default class similarVariableNames implements AnalyzerModule { ...@@ -43,13 +44,20 @@ export default class similarVariableNames implements AnalyzerModule {
if (multipleContractsWithSameName) { if (multipleContractsWithSameName) {
multipleContractsWithSameNameComments = 'Note: Import aliases are currently not supported by this static analysis.' multipleContractsWithSameNameComments = 'Note: Import aliases are currently not supported by this static analysis.'
} }
const vars: string[] = this.getFunctionVariables(contract, func).map(getDeclaredVariableName) const vars: string[] = this.getFunctionVariables(contract, func).map(getDeclaredVariableName)
this.findSimilarVarNames(vars).map((sim) => { this.findSimilarVarNames(vars).map((sim) => {
warnings.push({ if(func.node.implemented) {
warning: `${funcName} : Variables have very similar names "${sim.var1}" and "${sim.var2}". ${hasModifiersComments} ${multipleContractsWithSameNameComments}`, const astWalker = new AstWalker()
location: func.node['src'] const functionBody: any = func.node.body
}) astWalker.walk(functionBody, (node) => {
if (node.nodeType === "Identifier" && (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: func.node['src']
})
}
})
}
}) })
}) })
}) })
......
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