From fa533a58d4c0de264cdf1db45f18b83569342a03 Mon Sep 17 00:00:00 2001 From: Aniket-Engg Date: Thu, 31 Mar 2022 14:06:46 +0530 Subject: [PATCH] remix analysis report fix --- .../src/solidity-analyzer/index.ts | 8 +++--- .../src/lib/remix-ui-static-analyser.tsx | 27 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/libs/remix-analyzer/src/solidity-analyzer/index.ts b/libs/remix-analyzer/src/solidity-analyzer/index.ts index da6b5bb35e..d2c45ff635 100644 --- a/libs/remix-analyzer/src/solidity-analyzer/index.ts +++ b/libs/remix-analyzer/src/solidity-analyzer/index.ts @@ -15,13 +15,13 @@ export default class staticAnalysisRunner { * @param toRun module indexes (compiled from remix IDE) * @param callback callback */ - run (compilationResult: CompilationResult, toRun: number[], callback: ((reports: AnalysisReport[]) => void)): void { + run (compilationResult: CompilationResult, toRun: number[]): AnalysisReport[] { const modules: ModuleObj[] = toRun.map((i) => { const Module = this.modules()[i] const m = new Module() return { name: m.name, mod: m } }) - this.runWithModuleList(compilationResult, modules, callback) + return this.runWithModuleList(compilationResult, modules) } /** @@ -30,7 +30,7 @@ export default class staticAnalysisRunner { * @param modules analysis module * @param callback callback */ - runWithModuleList (compilationResult: CompilationResult, modules: ModuleObj[], callback: ((reports: AnalysisReport[]) => void)): void { + runWithModuleList (compilationResult: CompilationResult, modules: ModuleObj[]): AnalysisReport[] { let reports: AnalysisReport[] = [] // Also provide convenience analysis via the AST walker. const walker = new AstWalker() @@ -64,7 +64,7 @@ export default class staticAnalysisRunner { } return { name: item.name, report: report } })) - callback(reports) + return reports } /** diff --git a/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx b/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx index 203c0dad89..8270e8e0e0 100644 --- a/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx +++ b/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx @@ -76,9 +76,12 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { useEffect(() => { setWarningState({}) + const runAnalysis = async () => { + await run(state.data, state.source, state.file) + } if (autoRun) { if (state.data !== null) { - run(state.data, state.source, state.file) + runAnalysis().catch(console.error); } } else { props.event.trigger('staticAnaysisWarning', []) @@ -152,7 +155,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { setWarningState(groupedCategory) } - const run = (lastCompilationResult, lastCompilationSource, currentFile) => { + const run = async (lastCompilationResult, lastCompilationSource, currentFile) => { if (state.data !== null) { if (lastCompilationResult && (categoryIndex.length > 0 || slitherEnabled)) { let warningCount = 0 @@ -161,8 +164,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { // Remix Analysis _paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyzeWithRemixAnalyzer']) - runner.run(lastCompilationResult, categoryIndex, results => { - results.map((result) => { + const results = runner.run(lastCompilationResult, categoryIndex) + for (const result of results) { let moduleName Object.keys(groupedModules).map(key => { groupedModules[key].forEach(el => { @@ -171,7 +174,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { } }) }) - result.report.map(async (item) => { + for (const item of result.report) { let location: any = {} let locationString = 'not available' let column = 0 @@ -199,7 +202,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { if(fileName !== currentFile) { const {file, provider} = await props.analysisModule.call('fileManager', 'getPathFromUrl', fileName) if (file.startsWith('.deps') || (provider.type === 'localhost' && file.startsWith('localhost/node_modules'))) isLibrary = true - } + } warningCount++ const msg = message(result.name, item.warning, item.more, fileName, locationString) const options = { @@ -218,8 +221,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { } warningErrors.push(options) warningMessage.push({ msg, options, hasWarning: true, warningModuleName: moduleName }) - }) - }) + } + } // Slither Analysis if (slitherEnabled) { props.analysisModule.call('solidity', 'getCompilerState').then((compilerState) => { @@ -261,10 +264,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { fileName = Object.keys(lastCompilationResult.sources)[fileIndex] } } - if(fileName !== currentFile) { - console.log('inside ------------Slither') - props.analysisModule.call('fileManager', 'getPathFromUrl', fileName).then(console.log) - } + warningCount++ const msg = message(item.title, item.description, item.more, fileName, locationString) const options = { @@ -295,7 +295,6 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { showWarnings(warningMessage, 'warningModuleName') props.event.trigger('staticAnaysisWarning', [warningCount]) } - }) } else { if (categoryIndex.length) { warningContainer.current.innerText = 'No compiled AST available' @@ -436,7 +435,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { label="Autorun" onChange={() => {}} /> -