diff --git a/apps/remix-ide/src/app/tabs/analysis-tab.js b/apps/remix-ide/src/app/tabs/analysis-tab.js index 8f2174cd22..ee67278706 100644 --- a/apps/remix-ide/src/app/tabs/analysis-tab.js +++ b/apps/remix-ide/src/app/tabs/analysis-tab.js @@ -59,7 +59,7 @@ class AnalysisTab extends ViewPlugin { this.event.register('staticAnaysisWarning', (count) => { let payloadType = '' - // let totalCount = 0 + this.hints && this.hints.length > 0 ? this.hints.forEach(hint => { if (hint.type === 'error') { payloadType = 'error' @@ -69,9 +69,7 @@ class AnalysisTab extends ViewPlugin { }) : payloadType = 'warning' if (count > 0) { - console.log('staticAnaysisWarning', count) - this.internalCount = this.internalCount !== 0 ? count : count - this.emit('statusChanged', { key: this.internalCount, title: `${this.internalCount} warning${this.internalCount === 1 ? '' : 's'}`, type: payloadType }) + this.emit('statusChanged', { key: count, title: `${count} warning${count === 1 ? '' : 's'}`, type: payloadType }) } else if (count === 0) { this.emit('statusChanged', { key: 'succeed', title: 'no warning', type: 'success' }) } else { 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 3b7ce818d0..b17799d345 100644 --- a/libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts +++ b/libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts @@ -35,6 +35,8 @@ export const runLinting = async (solhintEnabled, setHints, hints: SolHintReport[ 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 } } @@ -77,7 +79,6 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch 0 ? "badge-warning" - : "badge-danger" + className={`badge ${props.ssaWarningsNoLibsTotal > 0 ? "badge-warning" + : props.ssaWarnings.filter(x => x.options.type === 'error').length > 0 ? "badge-danger" + : "badge-info" } badge-pill ml-1 px-1 text-center`} > - {props.ssaWarnings.filter(x => x.options.isLibrary === false).length} + {props.ssaWarnings.filter(x => !x.options.isLibrary).length} ) : ( - {props.ssaWarnings.length} + {props.ssaWarningsTotal} ) ) : null 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 1bd6761a5c..46a1941b2b 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 @@ -135,6 +135,13 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { props.analysisModule.call('solidity', 'getCompilerState').then((compilerState) => setDisableForRun(compilerState.currentVersion)) }, []) + useEffect(() => { + props.analysisModule.on('solidity', 'compilationFinished', (file, source, languageVersion, data) => { + props.event.trigger('staticAnaysisWarning', [-1]) + }) + return () => { props.event.trigger('staticAnalysisWarning', [-1]) } + }, [state.data, state.source]) + useEffect(() => { const checkRemixdActive = async () => { const remixdActive = await props.analysisModule.call('manager', 'isActive', 'remixd') @@ -239,72 +246,65 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { useEffect(() => { // if hideWarnings is true - if(basicEnabled && !solhintEnabled && !slitherEnabled && state.data && state.source !== null ) { - props.analysisModule.internalCount = 0 + if(basicEnabled && hideWarnings && !solhintEnabled && !slitherEnabled && state.data && state.source !== null ) { props.event.trigger('staticAnaysisWarning', - [hideWarnings ? remixAnalysisLessWarnings.length : ssaWarnings.length]) + [hideWarnings ? remixAnalysisLessWarnings.length : remixAnalysisNoLibs.length]) } - if (solhintEnabled && !basicEnabled && !slitherEnabled && state.data && state.source !== null) { - props.analysisModule.internalCount = 0 + if (solhintEnabled && hideWarnings && !basicEnabled && !slitherEnabled && state.data && state.source !== null) { props.event.trigger('staticAnaysisWarning', [hideWarnings ? hintErrors.length : hints?.length]) } - if (solhintEnabled && basicEnabled && !slitherEnabled && !showLibsWarning + if (solhintEnabled && basicEnabled && hideWarnings && !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 + remixAnalysisNoLibs.length]) } - if (slitherEnabled && !basicEnabled && !solhintEnabled && state.data && state.source !== null) { - props.analysisModule.internalCount = 0 + if (slitherEnabled && hideWarnings && !basicEnabled && !solhintEnabled && state.data && state.source !== null) { props.event.trigger('staticAnaysisWarning', [hideWarnings ? slitherErrors.length : slitherWarnings.length]) } - if (slitherEnabled && basicEnabled && solhintEnabled && state.data && state.source !== null) { - props.analysisModule.internalCount = 0 + if (slitherEnabled && basicEnabled && solhintEnabled && hideWarnings && state.data && state.source !== null) { props.event.trigger('staticAnaysisWarning', [hideWarnings ? hintErrors.length + remixAnalysisLessWarnings.length + slitherErrors.length : hints?.length + ssaWarnings.length + slitherWarnings.length]) } + }, [hideWarnings, state]) + + useEffect(() => { // if showLibsWarning is true if(basicEnabled && !solhintEnabled && !slitherEnabled && !hideWarnings && state.data && state.source !== null ) { - props.analysisModule.internalCount = 0 props.event.trigger('staticAnaysisWarning', [showLibsWarning ? ssaWarnings.length : remixAnalysisNoLibs.length]) } if (solhintEnabled && !basicEnabled && !slitherEnabled && !hideWarnings && state.data && state.source !== null) { - props.analysisModule.internalCount = 0 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 + if (solhintEnabled && basicEnabled && !slitherEnabled && !hideWarnings && state.data && state.source !== null && state.data && state.source !== null) { props.event.trigger('staticAnaysisWarning', [showLibsWarning ? hints?.length + ssaWarnings.length : hints?.length + remixAnalysisNoLibs.length]) } - if (slitherEnabled && !basicEnabled && !solhintEnabled && !hideWarnings && state.data && state.source !== null) { - props.analysisModule.internalCount = 0 + if (slitherEnabled && !basicEnabled && !solhintEnabled && !hideWarnings && state.data && state.source !== null && state.data && state.source !== null) { props.event.trigger('staticAnaysisWarning', [showLibsWarning && noLibSlitherWarnings.length]) } - if (slitherEnabled && basicEnabled && solhintEnabled && !hideWarnings && state.data && state.source !== null) { - props.analysisModule.internalCount = 0 + if (slitherEnabled && basicEnabled && solhintEnabled && !hideWarnings && state.data && state.source !== null && state.data && state.source !== null) { props.event.trigger('staticAnaysisWarning', [showLibsWarning ? hints?.length + ssaWarnings.length + slitherWarnings.length : hints?.length + remixAnalysisNoLibs.length + noLibSlitherWarnings.length]) } - if(basicEnabled && solhintEnabled && !slitherEnabled && !hideWarnings && !showLibsWarning) { - props.analysisModule.internalCount = 0 + }, [showLibsWarning, state]) + + useEffect(() => { + if(basicEnabled && solhintEnabled && !slitherEnabled && !hideWarnings && !showLibsWarning && state.data && state.source !== null) { props.event.trigger('staticAnaysisWarning', [hints?.length + remixAnalysisNoLibs.length]) } - if(solhintEnabled && basicEnabled && slitherEnabled && !hideWarnings && !showLibsWarning) { - props.analysisModule.internalCount = 0 + if(solhintEnabled && basicEnabled && slitherEnabled && !hideWarnings && !showLibsWarning && state.data && state.source !== null) { props.analysisModule.hints = [] props.event.trigger('staticAnaysisWarning', [hints?.length + remixAnalysisNoLibs.length + slitherWarnings.length]) } - if(solhintEnabled && basicEnabled && !slitherEnabled && hideWarnings && showLibsWarning) { - props.analysisModule.internalCount = 0 + if(solhintEnabled && basicEnabled && !slitherEnabled && hideWarnings && showLibsWarning && state.data && state.source !== null) { props.event.trigger('staticAnaysisWarning', [hintErrors.length + remixAnalysisLessWarnings.length]) } - }, [ssaWarnings.length, hints?.length, hideWarnings, showLibsWarning, state]) + // props.event.trigger('staticAnaysisWarning', [-1]) + }, [ssaWarnings.length, remixAnalysisNoLibs.length, remixAnalysisLessWarnings.length, hints?.length, hintErrors?.length, state, state.data, state.source]) useEffect(() => { if(solhintEnabled === false) { @@ -312,6 +312,14 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { } }, [solhintEnabled]) + useEffect(() => { + if(solhintEnabled && basicEnabled) { + if(ssaWarnings.length > 0 && hints.length > 0) { + props.event.trigger('staticAnaysisWarning', [ssaWarnings.length + hints.length]) + } + } + }, [showLibsWarning]) + const showWarnings = (warningMessage, groupByKey) => { @@ -381,7 +389,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { } } - const handleLinterEnabled = async () => { + const handleLinterEnabled = () => { if (solhintEnabled) { setSolhintEnabled(false) } else { @@ -591,6 +599,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { ssaWarnings={ssaWarnings} ssaWarningsNoLibs={remixAnalysisNoLibs} warningStateEntries={Object.entries(warningState)} + ssaWarningsNoLibsTotal={remixAnalysisNoLibs.length} + ssaWarningsTotal={ssaWarnings.length} /> ), child: ( @@ -705,12 +715,11 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { id="checkAllEntries" inputType="checkbox" title="Remix analysis runs a basic analysis." - // checked={Object.values(groupedModules).map((value: any) => { - // return (value.map(x => { - // return x._index.toString() - // })) - // }).flat().every(el => categoryIndex.includes(el))} - checked={basicEnabled} + checked={basicEnabled && Object.values(groupedModules).map((value: any) => { + return (value.map(x => { + return x._index.toString() + })) + }).flat().every(el => categoryIndex.includes(el))} onClick={handleBasicEnabled} label="Remix" onChange={() => {}}