simplify static analysis actions

pull/3838/head
Joseph Izang 1 year ago
parent 1f41cbce7f
commit d5d826ac46
  1. 78
      libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts

@ -23,24 +23,6 @@ export const compilation = (analysisModule: AnalysisTab,
} }
} }
export const runLinting = async (solhintEnabled, setHints, hints: SolHintReport[], isSupportedVersion, state: RemixUiStaticAnalyserState,
props: RemixUiStaticAnalyserProps, setStartAnalysis: React.Dispatch<React.SetStateAction<boolean>>) => {
// Run solhint
setStartAnalysis(true)
props.analysisModule.hints = []
if (!isSupportedVersion) return
if (solhintEnabled === false) return
if (state.data !== null) {
props.analysisModule.hints = []
const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file)
props.analysisModule.hints = solhintEnabled === false ? 0 : hintsResult
setHints(hintsResult)
// props.analysisModule.emit('statusChanged', { key: hints.length,
// title: `${hints.length} warning${hints.length === 1 ? '' : 's'}`, type: 'warning'})
return hintsResult
}
}
/** /**
* Run the analysis on the currently compiled contract * Run the analysis on the currently compiled contract
* @param lastCompilationResult * @param lastCompilationResult
@ -62,27 +44,27 @@ export const runLinting = async (solhintEnabled, setHints, hints: SolHintReport[
*/ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function run (lastCompilationResult, lastCompilationSource, currentFile: string, state: RemixUiStaticAnalyserState, props: RemixUiStaticAnalyserProps, isSupportedVersion, showSlither, categoryIndex: number[], groupedModules, runner, _paq, message, showWarnings, allWarnings: React.RefObject<any>, warningContainer: React.RefObject<any>, calculateWarningStateEntries: (e:[string, any][]) => {length: number, errors: any[] }, warningState, setHints: React.Dispatch<React.SetStateAction<SolHintReport[]>>, hints: SolHintReport[], setSlitherWarnings: React.Dispatch<React.SetStateAction<any[]>>, setSsaWarnings: React.Dispatch<React.SetStateAction<any[]>>, export async function run (lastCompilationResult, lastCompilationSource, currentFile: string, state: RemixUiStaticAnalyserState, props: RemixUiStaticAnalyserProps, isSupportedVersion, showSlither, categoryIndex: number[], groupedModules, runner, _paq, message, showWarnings, allWarnings: React.RefObject<any>, warningContainer: React.RefObject<any>, calculateWarningStateEntries: (e:[string, any][]) => {length: number, errors: any[] }, warningState, setHints: React.Dispatch<React.SetStateAction<SolHintReport[]>>, hints: SolHintReport[], setSlitherWarnings: React.Dispatch<React.SetStateAction<any[]>>, setSsaWarnings: React.Dispatch<React.SetStateAction<any[]>>,
slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<boolean>>, solhintEnabled: boolean, basicEnabled: boolean) { slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<boolean>>, solhintEnabled: boolean) {
setStartAnalysis(true) setStartAnalysis(true)
setHints([]) setHints([])
setSsaWarnings([]) setSsaWarnings([])
setSlitherWarnings([]) setSlitherWarnings([])
props.analysisModule.hints = []
if (!isSupportedVersion) return if (!isSupportedVersion) return
if (state.data !== null) { if (state.data !== null) {
if (lastCompilationResult && (categoryIndex.length > 0)) { if (lastCompilationResult && (categoryIndex.length > 0 || showSlither)) {
_paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'remixAnalyzer'])
const warningMessage = [] const warningMessage = []
const warningErrors = [] const warningErrors = []
props.analysisModule.hints = []
// Run solhint // Run 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 = solhintEnabled === false ? 0 : hintsResult
// setHints(hintsResult) setHints(hintsResult)
// const warningResult = calculateWarningStateEntries(Object.entries(warningState))
// props.analysisModule.emit('statusChanged', { key: hints.length+warningResult.length, // props.analysisModule.emit('statusChanged', { key: hints.length+warningResult.length,
// title: `${hints.length+warningResult.length} warning${hints.length+warningResult.length === 1 ? '' : 's'}`, type: 'warning'}) // title: `${hints.length+warningResult.length} warning${hints.length+warningResult.length === 1 ? '' : 's'}`, type: 'warning'})
// Remix Analysis // Remix Analysis
_paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'remixAnalyzer'])
const results = runner.run(lastCompilationResult, categoryIndex) const results = runner.run(lastCompilationResult, categoryIndex)
for (const result of results) { for (const result of results) {
let moduleName let moduleName
@ -142,42 +124,8 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<b
warningErrors.push(options) warningErrors.push(options)
warningMessage.push({ msg, options, hasWarning: true, warningModuleName: moduleName }) warningMessage.push({ msg, options, hasWarning: true, warningModuleName: moduleName })
setSsaWarnings(warningMessage) setSsaWarnings(warningMessage)
props.event.trigger('staticAnaysisWarning', [warningMessage.length])
}
}
} else {
if (categoryIndex.length) {
warningContainer.current.innerText = 'No compiled AST available'
} }
props.event.trigger('staticAnaysisWarning', [-1])
} }
}
}
/**
* Run the analysis on the currently compiled contract
* @param lastCompilationResult
* @param lastCompilationSource
* @param currentFile {string} current file path
* @param state { RemixUiStaticAnalyserState}
* @param props {RemixUiStaticAnalyserProps}
* @param isSupportedVersion {boolean}
* @param slitherEnabled {boolean}
* @param categoryIndex {number[]}
* @param groupedModules {any}
* @param runner {any}
* @param _paq {any}
* @param message {any}
* @param showWarnings {boolean}
* @param allWarnings {React.RefObject<object>}
* @param warningContainer {React.RefObject<object>}
* @returns {Promise<void>}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function runSlitherAnalysis (lastCompilationResult, lastCompilationSource, currentFile: string, state: RemixUiStaticAnalyserState, props: RemixUiStaticAnalyserProps, isSupportedVersion, showSlither, categoryIndex: number[], groupedModules, runner, _paq, message, showWarnings, allWarnings: React.RefObject<any>, warningContainer: React.RefObject<any>, calculateWarningStateEntries: (e:[string, any][]) => {length: number, errors: any[] }, warningState, setHints: React.Dispatch<React.SetStateAction<SolHintReport[]>>, hints: SolHintReport[], setSlitherWarnings: React.Dispatch<React.SetStateAction<any[]>>, setSsaWarnings: React.Dispatch<React.SetStateAction<any[]>>,
slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<boolean>>) {
// Slither Analysis // Slither Analysis
if (showSlither && slitherEnabled) { if (showSlither && slitherEnabled) {
setSlitherWarnings([]) setSlitherWarnings([])
@ -247,12 +195,20 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<b
return prev return prev
}) })
} }
showWarnings(warningMessage, 'warningModuleName')
} }
} catch(error) { } catch(error) {
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')
} }
} } else showWarnings(warningMessage, 'warningModuleName')
setStartAnalysis(false) setStartAnalysis(false)
} else {
if (categoryIndex.length) {
warningContainer.current.innerText = 'No compiled AST available'
}
props.event.trigger('staticAnaysisWarning', [-1]) props.event.trigger('staticAnaysisWarning', [-1])
} }
}
}

Loading…
Cancel
Save