remix analysis report fix

pull/2187/head
Aniket-Engg 3 years ago committed by yann300
parent 7521e18f12
commit 21a55b7212
  1. 8
      libs/remix-analyzer/src/solidity-analyzer/index.ts
  2. 27
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx

@ -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
}
/**

@ -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={() => {}}
/>
<Button buttonText="Run" onClick={() => run(state.data, state.source, state.file)} disabled={(state.data === null || categoryIndex.length === 0) && !slitherEnabled }/>
<Button buttonText="Run" onClick={async () => await run(state.data, state.source, state.file)} disabled={(state.data === null || categoryIndex.length === 0) && !slitherEnabled }/>
</div>
{ showSlither &&
<div className="d-flex mt-2" id="enableSlitherAnalysis">

Loading…
Cancel
Save