fix analysis running based on enabled tools

pull/5370/head
Joseph Izang 2 years ago
parent 7837ca2ff1
commit bc4b517209
  1. 128
      libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts

@ -56,73 +56,82 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<b
const warningErrors = [] const warningErrors = []
props.analysisModule.hints = [] props.analysisModule.hints = []
// Run solhint // Run solhint
if (solhintEnabled) {
_paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'solHint']) _paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'solHint'])
const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file) const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file)
props.analysisModule.hints = solhintEnabled === false ? 0 : hintsResult props.analysisModule.hints = hintsResult
setHints(hintsResult) setHints(hintsResult)
} else {
props.analysisModule.hints = []
setHints([])
}
// Remix Analysis // Remix Analysis
_paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'remixAnalyzer']) if (basicEnabled) {
const results = runner.run(lastCompilationResult, categoryIndex) _paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'remixAnalyzer'])
for (const result of results) { const results = runner.run(lastCompilationResult, categoryIndex)
let moduleName for (const result of results) {
Object.keys(groupedModules).map(key => { let moduleName
groupedModules[key].forEach(el => { Object.keys(groupedModules).map(key => {
if (el.name === result.name) { groupedModules[key].forEach(el => {
moduleName = groupedModules[key][0].categoryDisplayName if (el.name === result.name) {
} moduleName = groupedModules[key][0].categoryDisplayName
}
})
}) })
}) // iterate over the warnings and create an object
// iterate over the warnings and create an object for (const item of result.report) {
for (const item of result.report) { let location: any = {}
let location: any = {} let locationString = 'not available'
let locationString = 'not available' let column = 0
let column = 0 let row = 0
let row = 0 let fileName = currentFile
let fileName = currentFile let isLibrary = false
let isLibrary = false
if (item.location) { if (item.location) {
const split = item.location.split(':') const split = item.location.split(':')
const file = split[2] const file = split[2]
location = { location = {
start: parseInt(split[0]), start: parseInt(split[0]),
length: parseInt(split[1]) length: parseInt(split[1])
}
location = props.analysisModule._deps.offsetToLineColumnConverter.offsetToLineColumn(
location,
parseInt(file),
lastCompilationSource.sources,
lastCompilationResult.sources
)
row = location.start.line
column = location.start.column
locationString = row + 1 + ':' + column + ':'
fileName = Object.keys(lastCompilationResult.sources)[file]
} }
location = props.analysisModule._deps.offsetToLineColumnConverter.offsetToLineColumn( if (fileName !== currentFile) {
location, const { file, provider } = await props.analysisModule.call('fileManager', 'getPathFromUrl', fileName)
parseInt(file), if (file.startsWith('.deps') || (provider.type === 'localhost' && file.startsWith('localhost/node_modules'))) isLibrary = true
lastCompilationSource.sources, }
lastCompilationResult.sources const msg = message(result.name, item.warning, item.more, state.file, locationString)
) const options = {
row = location.start.line type: 'warning',
column = location.start.column useSpan: true,
locationString = row + 1 + ':' + column + ':' errFile: state.file,
fileName = Object.keys(lastCompilationResult.sources)[file] fileName,
} isLibrary,
if(fileName !== currentFile) { errLine: row,
const {file, provider} = await props.analysisModule.call('fileManager', 'getPathFromUrl', fileName) errCol: column,
if (file.startsWith('.deps') || (provider.type === 'localhost' && file.startsWith('localhost/node_modules'))) isLibrary = true item: item,
} name: result.name,
const msg = message(result.name, item.warning, item.more, state.file, locationString) locationString,
const options = { more: item.more,
type: 'warning', location: location
useSpan: true, }
errFile: state.file, warningErrors.push(options)
fileName, warningMessage.push({ msg, options, hasWarning: true, warningModuleName: moduleName })
isLibrary, setSsaWarnings(warningMessage)
errLine: row,
errCol: column,
item: item,
name: result.name,
locationString,
more: item.more,
location: location
} }
warningErrors.push(options)
warningMessage.push({ msg, options, hasWarning: true, warningModuleName: moduleName })
setSsaWarnings(warningMessage)
} }
} } else {
setSsaWarnings([])
}
// Slither Analysis // Slither Analysis
if (showSlither && slitherEnabled) { if (showSlither && slitherEnabled) {
setSlitherWarnings([]) setSlitherWarnings([])
@ -198,12 +207,13 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<b
props.analysisModule.call('terminal', 'log', { type: 'error', value: '[Slither Analysis]: Error occured! See remixd console for details.' }) props.analysisModule.call('terminal', 'log', { type: 'error', value: '[Slither Analysis]: Error occured! See remixd console for details.' })
showWarnings(warningMessage, 'warningModuleName') showWarnings(warningMessage, 'warningModuleName')
} }
} else showWarnings(warningMessage, 'warningModuleName') } else //showWarnings(warningMessage, 'warningModuleName')
setStartAnalysis(false) setStartAnalysis(false)
} else { } else {
if (categoryIndex.length) { if (categoryIndex.length) {
warningContainer.current.innerText = 'No compiled AST available' warningContainer.current.innerText = 'No compiled AST available'
} }
props.event.trigger('staticAnaysisWarning', [-1]) props.event.trigger('staticAnaysisWarning', [-1])
} }
} }

Loading…
Cancel
Save