From a92411bc6bdd7b16fbb5bb3e950ed19a0e1c3aad Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Mon, 26 Jun 2023 20:41:11 +0100 Subject: [PATCH] fixing solhint no analysis for solhint --- .../src/lib/actions/staticAnalysisActions.ts | 129 +++++++++--------- .../src/lib/remix-ui-static-analyser.tsx | 104 +++++++------- 2 files changed, 111 insertions(+), 122 deletions(-) diff --git a/libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts b/libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts index fcda3e0f76..3b7ce818d0 100644 --- a/libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts +++ b/libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts @@ -23,7 +23,7 @@ export const compilation = (analysisModule: AnalysisTab, } } -export const runLinting = async (solhintEnabled, setHints, hints: SolHintReport[], warningResult, isSupportedVersion, state: RemixUiStaticAnalyserState, +export const runLinting = async (solhintEnabled, setHints, hints: SolHintReport[], isSupportedVersion, state: RemixUiStaticAnalyserState, props: RemixUiStaticAnalyserProps, setStartAnalysis: React.Dispatch>) => { // Run solhint setStartAnalysis(true) @@ -31,13 +31,11 @@ export const runLinting = async (solhintEnabled, setHints, hints: SolHintReport[ if (!isSupportedVersion) return if (solhintEnabled === false) return if (state.data !== null) { - if (solhintEnabled) { props.analysisModule.hints = [] - setHints([]) const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file) props.analysisModule.hints = solhintEnabled === false ? 0 : hintsResult + setHints(hintsResult) return hintsResult - } } } @@ -70,7 +68,7 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch 0 || showSlither)) { + if (lastCompilationResult && (categoryIndex.length > 0)) { _paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'remixAnalyzer']) const warningMessage = [] const warningErrors = [] @@ -79,76 +77,71 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch { - groupedModules[key].forEach(el => { - if (el.name === result.name) { - moduleName = groupedModules[key][0].categoryDisplayName - } + const results = runner.run(lastCompilationResult, categoryIndex) + for (const result of results) { + let moduleName + Object.keys(groupedModules).map(key => { + groupedModules[key].forEach(el => { + if (el.name === result.name) { + moduleName = groupedModules[key][0].categoryDisplayName + } + }) }) - }) - // iterate over the warnings and create an object - for (const item of result.report) { - let location: any = {} - let locationString = 'not available' - let column = 0 - let row = 0 - let fileName = currentFile - let isLibrary = false + // iterate over the warnings and create an object + for (const item of result.report) { + let location: any = {} + let locationString = 'not available' + let column = 0 + let row = 0 + let fileName = currentFile + let isLibrary = false - if (item.location) { - const split = item.location.split(':') - const file = split[2] - location = { - start: parseInt(split[0]), - length: parseInt(split[1]) + if (item.location) { + const split = item.location.split(':') + const file = split[2] + location = { + start: parseInt(split[0]), + 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( - 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] - } - 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 - } - const msg = message(result.name, item.warning, item.more, fileName, locationString) - const options = { - type: 'warning', - useSpan: true, - errFile: fileName, - fileName, - isLibrary, - 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 }) - const newHints = await lintResult - setHints(newHints) - setSsaWarnings(warningMessage) + 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 + } + const msg = message(result.name, item.warning, item.more, fileName, locationString) + const options = { + type: 'warning', + useSpan: true, + errFile: fileName, + fileName, + isLibrary, + 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) + // setHints(lintResult) } } } else { 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 1796f6ebc3..1bd6761a5c 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 @@ -191,7 +191,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { return () => { } }, [props]) - const hintErrors = hints.filter(hint => hint.type === 'error') + const hintErrors = hints && hints.filter(hint => hint.type === 'error') const noLibSlitherWarnings = slitherWarnings.filter(w => !w.options.isLibrary) const slitherErrors = noLibSlitherWarnings.filter(slitherError => slitherError.options.type === 'error') const remixAnalysisNoLibs = ssaWarnings.filter(ssa => ssa.options.isLibrary === false) @@ -246,14 +246,14 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { } if (solhintEnabled && !basicEnabled && !slitherEnabled && state.data && state.source !== null) { props.analysisModule.internalCount = 0 - props.event.trigger('staticAnaysisWarning', [hideWarnings ? hintErrors.length : hints.length]) + props.event.trigger('staticAnaysisWarning', [hideWarnings ? hintErrors.length : hints?.length]) } if (solhintEnabled && basicEnabled && !slitherEnabled && !showLibsWarning && state.data && state.source !== null) { console.log('solhint and remix are enabled here') props.analysisModule.internalCount = 0 props.event.trigger('staticAnaysisWarning', [hideWarnings - ? hintErrors.length + remixAnalysisNoLibs.filter(x => x.options.type !== 'warning').length : hints.length + ssaWarnings.length]) + ? hintErrors.length + remixAnalysisNoLibs.filter(x => x.options.type !== 'warning').length : hints?.length + ssaWarnings.length]) } if (slitherEnabled && !basicEnabled && !solhintEnabled && state.data && state.source !== null) { props.analysisModule.internalCount = 0 @@ -263,7 +263,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { props.analysisModule.internalCount = 0 props.event.trigger('staticAnaysisWarning', [hideWarnings ? hintErrors.length + remixAnalysisLessWarnings.length + slitherErrors.length - : hints.length + ssaWarnings.length + slitherWarnings.length]) + : hints?.length + ssaWarnings.length + slitherWarnings.length]) } // if showLibsWarning is true if(basicEnabled && !solhintEnabled && !slitherEnabled && !hideWarnings && state.data && state.source !== null ) { @@ -273,13 +273,13 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { } if (solhintEnabled && !basicEnabled && !slitherEnabled && !hideWarnings && state.data && state.source !== null) { props.analysisModule.internalCount = 0 - props.event.trigger('staticAnaysisWarning', [showLibsWarning ? hints.length : hints.length]) + props.event.trigger('staticAnaysisWarning', [showLibsWarning ? hints?.length : hints?.length]) } if (solhintEnabled && basicEnabled && !slitherEnabled && !hideWarnings && state.data && state.source !== null) { console.log('solhint and remix are enabled here') props.analysisModule.internalCount = 0 props.event.trigger('staticAnaysisWarning', [showLibsWarning - ? hints.length + ssaWarnings.length : hints.length + remixAnalysisNoLibs.length]) + ? hints?.length + ssaWarnings.length : hints?.length + remixAnalysisNoLibs.length]) } if (slitherEnabled && !basicEnabled && !solhintEnabled && !hideWarnings && state.data && state.source !== null) { props.analysisModule.internalCount = 0 @@ -288,42 +288,23 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { if (slitherEnabled && basicEnabled && solhintEnabled && !hideWarnings && state.data && state.source !== null) { props.analysisModule.internalCount = 0 props.event.trigger('staticAnaysisWarning', [showLibsWarning - ? hints.length + ssaWarnings.length + slitherWarnings.length : hints.length + remixAnalysisNoLibs.length + noLibSlitherWarnings.length]) - } - if(solhintEnabled && basicEnabled && !slitherEnabled && !hideWarnings && !showLibsWarning) { - props.analysisModule.internalCount = 0 - if(props.analysisModule.hints.length > 0) { - props.event.trigger('staticAnaysisWarning', [hints.length + remixAnalysisNoLibs.length]) - } - } - if(solhintEnabled && !basicEnabled && !slitherEnabled && hideWarnings && showLibsWarning) { - props.analysisModule.internalCount = 0 - if(remixAnalysisLessWarnings.length > 0) { - props.event.trigger('staticAnaysisWarning', [hints.length]) - } + ? hints?.length + ssaWarnings.length + slitherWarnings.length : hints?.length + remixAnalysisNoLibs.length + noLibSlitherWarnings.length]) } if(basicEnabled && solhintEnabled && !slitherEnabled && !hideWarnings && !showLibsWarning) { props.analysisModule.internalCount = 0 - if(props.analysisModule.hints.length > 0) { - props.event.trigger('staticAnaysisWarning', [hints.length + remixAnalysisNoLibs.length]) - } + props.event.trigger('staticAnaysisWarning', [hints?.length + remixAnalysisNoLibs.length]) } if(solhintEnabled && basicEnabled && slitherEnabled && !hideWarnings && !showLibsWarning) { props.analysisModule.internalCount = 0 - if(props.analysisModule.hints.length > 0) { - props.analysisModule.hints = [] - props.event.trigger('staticAnaysisWarning', [hints.length + remixAnalysisNoLibs.length + slitherWarnings.length]) - } + props.analysisModule.hints = [] + props.event.trigger('staticAnaysisWarning', [hints?.length + remixAnalysisNoLibs.length + slitherWarnings.length]) } if(solhintEnabled && basicEnabled && !slitherEnabled && hideWarnings && showLibsWarning) { props.analysisModule.internalCount = 0 - if(remixAnalysisLessWarnings.length > 0) { - props.event.trigger('staticAnaysisWarning', [hintErrors.length + remixAnalysisNoLibs - .filter(x => x.options.type === 'warning').length]) - } + props.event.trigger('staticAnaysisWarning', [hintErrors.length + remixAnalysisLessWarnings.length]) } - }, [ssaWarnings.length, hints.length, hideWarnings, showLibsWarning, state]) + }, [ssaWarnings.length, hints?.length, hideWarnings, showLibsWarning, state]) useEffect(() => { if(solhintEnabled === false) { @@ -491,12 +472,12 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { tabKey: "linter", child: ( <> - {hints.length > 0 ? ( + {solhintEnabled && hints?.length > 0 ? (
{!hideWarnings - ? hints.map((hint, index) => ( + ? hints?.map((hint, index) => (
{
- ) : state.data && state.file.length > 0 && state.source && startAnalysis && hints.length > 0 ? Loading... : Nothing to report} + ) : state.data && state.file.length > 0 && state.source && startAnalysis && hints?.length > 0 ? Loading... : Nothing to report} ), title: ( Solhint - {hints.length > 0 ? ( + {hints && hints?.length > 0 ? ( hideWarnings ? ( - x.type === 'error').length > 0 + x.type === 'error').length > 0 ? `badge-danger` : 'badge-warning'} badge-pill px-1 ml-1 text-center`}> {hintErrors.length} ) : ( - x.type === 'error').length > 0 + x.type === 'error').length > 0 ? `badge-danger` : 'badge-warning'} badge-pill px-1 ml-1 text-center`}> - {hints.length} + {hints?.length} ) ) : null} @@ -630,18 +611,18 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { title: ( Slither - {slitherWarnings.length > 0 ? ( + {slitherWarnings && slitherWarnings?.length > 0 ? ( hideWarnings ? ( - {slitherErrors.length} + {slitherErrors?.length} ) : showLibsWarning === true && hideWarnings === false ? ( 0 ? `badge-danger` : 'badge-warning'} badge-pill px-1 ml-1 text-center`}> {slitherWarnings.length} ) : ( - 0 ? `badge-danger` : 'badge-warning'} badge-pill px-1 ml-1 text-center`}> - {noLibSlitherWarnings.length} + 0 ? `badge-danger` : 'badge-warning'} badge-pill px-1 ml-1 text-center`}> + {noLibSlitherWarnings?.length} ) ) : null} @@ -649,12 +630,12 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { ), child: ( <> - {slitherWarnings.length > 0 ? ( + {slitherWarnings?.length > 0 ? (
{!hideWarnings - ? showLibsWarning ? slitherWarnings.map((warning, index) => ( + ? showLibsWarning ? slitherWarnings && slitherWarnings?.map((warning, index) => (
{ buttonText={`Analyse ${state.file}`} classList="btn btn-sm btn-primary btn-block" onClick={async () => { - await run(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq, - message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis, solhintEnabled, basicEnabled) - - await runSlitherAnalysis(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq, - message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis) + await runLinting(solhintEnabled, setHints, hints, isSupportedVersion, state, props, setStartAnalysis) + if(basicEnabled) { + await run(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq, + message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis, solhintEnabled, basicEnabled) + } + + if(slitherEnabled) { + await runSlitherAnalysis(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq, + message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis) + } } } disabled={(state.data === null || !isSupportedVersion || !solhintEnabled && !basicEnabled) } @@ -778,13 +764,23 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { buttonText={`Analyze ${state.file}`} title={`${runButtonTitle}`} classList="btn btn-sm btn-primary btn-block" - onClick={async () => await run(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq, - message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis, solhintEnabled, basicEnabled)} + onClick={async () => { + await runLinting(solhintEnabled, setHints, hints, isSupportedVersion, state, props, setStartAnalysis) + if(basicEnabled) { + await run(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq, + message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis, solhintEnabled, basicEnabled) + } + + if(slitherEnabled) { + await runSlitherAnalysis(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq, + message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis) + } + }} disabled={(state.data === null || !isSupportedVersion) || (!solhintEnabled && !basicEnabled) } />} {state && state.data !== null && state.source !== null && state.file.length > 0 ? (
- {slitherWarnings.length > 0 || hints.length > 0 || Object.entries(warningState).length > 0 ? ( -
0 || hints.length > 0 || Object.entries(warningState).length > 0 ? 'border-top' : ''} flex-column`}> + {slitherWarnings?.length > 0 || hints?.length > 0 || Object.entries(warningState).length > 0 ? ( +
0 || hints?.length > 0 || Object.entries(warningState).length > 0 ? 'border-top' : ''} flex-column`}> Last results for: { onSelect={(newKey) => setTabKey(newKey)} > { - checkBasicStatus() ?