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

slither results on UI

parent bee567ac
...@@ -105,6 +105,27 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { ...@@ -105,6 +105,27 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
) )
} }
const showWarnings = (warningMessage, groupByKey) => {
const resultArray = []
warningMessage.map(x => {
resultArray.push(x)
})
function groupBy (objectArray, property) {
return objectArray.reduce((acc, obj) => {
const key = obj[property]
if (!acc[key]) {
acc[key] = []
}
// Add object to list for given key's value
acc[key].push(obj)
return acc
}, {})
}
const groupedCategory = groupBy(resultArray, groupByKey)
setWarningState(groupedCategory)
}
const run = (lastCompilationResult, lastCompilationSource, currentFile) => { const run = (lastCompilationResult, lastCompilationSource, currentFile) => {
if (state.data !== null) { if (state.data !== null) {
if (lastCompilationResult && categoryIndex.length > 0) { if (lastCompilationResult && categoryIndex.length > 0) {
...@@ -112,7 +133,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { ...@@ -112,7 +133,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
const warningMessage = [] const warningMessage = []
const warningErrors = [] const warningErrors = []
/******************** Remix Analyzer ********************/ /******************** Remix Analysis ********************/
runner.run(lastCompilationResult, categoryIndex, results => { runner.run(lastCompilationResult, categoryIndex, results => {
results.map((result) => { results.map((result) => {
let moduleName let moduleName
...@@ -166,85 +187,60 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { ...@@ -166,85 +187,60 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
warningMessage.push({ msg, options, hasWarning: true, warningModuleName: moduleName }) warningMessage.push({ msg, options, hasWarning: true, warningModuleName: moduleName })
}) })
}) })
}) /******************** Slither Analysis ********************/
if (slitherEnabled) {
/******************** Slither Analyzer Start ********************/ props.analysisModule.call('solidity-logic', 'getCompilerState').then((compilerState) => {
const { currentVersion, optimize, evmVersion } = compilerState
if (slitherEnabled) { props.analysisModule.call('slither', 'analyse', state.file, { currentVersion, optimize, evmVersion }).then((result) => {
props.analysisModule.call('solidity-logic', 'getCompilerState').then((compilerState) => { if (result.status) {
const { currentVersion, optimize, evmVersion } = compilerState const report = result.data
props.analysisModule.call('slither', 'analyse', state.file, { currentVersion, optimize, evmVersion }).then((result) => { report.map((item) => {
console.log('slither result') let location: any = {}
if (result.status) { let locationString = 'not available'
const report = result.data let column = 0
report.map((item) => { let row = 0
let location: any = {} let fileName = currentFile
let locationString = 'not available' if (item.sourceMap & item.sourceMap.length) {
let column = 0 location = {
let row = 0 start: item.sourceMap[0].source_mapping.start,
let fileName = currentFile length: item.sourceMap[0].source_mapping.length
if (item.sourceMap & item.sourceMap.length) { }
location = { location = props.analysisModule._deps.offsetToLineColumnConverter.offsetToLineColumn(
start: item.sourceMap[0].source_mapping.start, location,
length: item.sourceMap[0].source_mapping.length 0,
lastCompilationSource.sources,
lastCompilationResult.sources
)
console.log('location:', location)
row = location.start.line
column = location.start.column
locationString = row + 1 + ':' + column + ':'
fileName = Object.keys(lastCompilationResult.contracts)[0]
} }
location = props.analysisModule._deps.offsetToLineColumnConverter.offsetToLineColumn( warningCount++
location, const msg = message(item.title, item.description, item.more, fileName, locationString)
0, const options = {
lastCompilationSource.sources, type: 'warning',
lastCompilationResult.sources useSpan: true,
) errFile: fileName,
console.log('location:', location) fileName,
row = location.start.line errLine: row,
column = location.start.column errCol: column,
locationString = row + 1 + ':' + column + ':' item: { warning: item.description},
fileName = Object.keys(lastCompilationResult.contracts)[0] name: item.title,
} locationString,
warningCount++ more: item.more,
const msg = message(item.title, item.description, item.more, fileName, locationString) location: location
const options = { }
type: 'warning', warningErrors.push(options)
useSpan: true, warningMessage.push({ msg, options, hasWarning: true, warningModuleName: item.title })
errFile: fileName, })
fileName, showWarnings(warningMessage, 'warningModuleName')
errLine: row, }
errCol: column,
item: item,
name: item.title,
locationString,
more: item.more,
location: location
}
warningErrors.push(options)
warningMessage.push({ msg, options, hasWarning: true, warningModuleName: item.title })
})
}
const resultArray = []
warningMessage.map(x => {
resultArray.push(x)
}) })
function groupBy (objectArray, property) {
return objectArray.reduce((acc, obj) => {
const key = obj[property]
if (!acc[key]) {
acc[key] = []
}
// Add object to list for given key's value
acc[key].push(obj)
return acc
}, {})
}
const groupedCategory = groupBy(resultArray, 'warningModuleName')
setWarningState(groupedCategory)
}) })
}) } else showWarnings(warningMessage, 'warningModuleName')
})
}
/******************** Slither Analyzer Finish ********************/
if (categoryIndex.length > 0) { if (categoryIndex.length > 0) {
props.event.trigger('staticAnaysisWarning', [warningCount]) props.event.trigger('staticAnaysisWarning', [warningCount])
} }
......
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