From f0720036e769f8459a2e3393667fcfce33612442 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Mon, 26 Jun 2023 12:23:01 +0100 Subject: [PATCH] fixing case of incorrect badge total --- apps/remix-ide/src/app/tabs/analysis-tab.js | 8 +--- .../src/lib/remix-ui-static-analyser.tsx | 39 ++++++++++++++++++- .../static-analyser/src/staticanalyser.d.ts | 6 +-- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/analysis-tab.js b/apps/remix-ide/src/app/tabs/analysis-tab.js index e4df06e423..4ffe2ec4c2 100644 --- a/apps/remix-ide/src/app/tabs/analysis-tab.js +++ b/apps/remix-ide/src/app/tabs/analysis-tab.js @@ -58,7 +58,7 @@ class AnalysisTab extends ViewPlugin { this.event.register('staticAnaysisWarning', (count) => { let payloadType = '' - let totalCount = 0 + // let totalCount = 0 this.hints && this.hints.length > 0 ? this.hints.forEach(hint => { if (hint.type === 'error') { payloadType = 'error' @@ -68,11 +68,7 @@ class AnalysisTab extends ViewPlugin { }) : payloadType = 'warning' if (count > 0) { - if (this.hints && this.hints.length > 0) { - totalCount = count === this.hints.length ? count : count + this.hints.length - } - totalCount += count - this.emit('statusChanged', { key: totalCount, title: `${totalCount} warning${totalCount === 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/remix-ui-static-analyser.tsx b/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx index 62368d73e2..62f915d39a 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 @@ -196,6 +196,10 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { const slitherErrors = noLibSlitherWarnings.filter(slitherError => slitherError.options.type === 'error') const remixAnalysisNoLibs = ssaWarnings.filter(ssa => ssa.options.isLibrary === false) + console.log({ + hints, ssaWarnings, slitherWarnings, state + }) + const message = (name: string, warning: any, more?: string, fileName?: string, locationString?: string) : string => { return (` @@ -230,12 +234,43 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { } } } - if (newWarningCount > 0 && state.data && state.source !== null) { - props.event.trigger('staticAnaysisWarning', [newWarningCount]) + if (ssaWarnings.length > 0 && state.data && state.source !== null) { + props.event.trigger('staticAnaysisWarning', [ssaWarnings.length]) setWarningState(newWarningState) } } + useEffect(() => { + if(solhintEnabled && basicEnabled) { + if(ssaWarnings.length > 0 && hints.length > 0) { + props.event.trigger('staticAnaysisWarning', [ssaWarnings.length + hints.length]) + } + } + }, [showLibsWarning]) + + useEffect(() => { + if(basicEnabled && !solhintEnabled && !slitherEnabled && state.data && state.source !== null ) { + props.event.trigger('staticAnaysisWarning', + [hideWarnings ? remixAnalysisNoLibs.length : ssaWarnings.length]) + } + if (solhintEnabled && !basicEnabled && !slitherEnabled && state.data && state.source !== null) { + props.event.trigger('staticAnaysisWarning', [hideWarnings ? hints.length : hintErrors.length]) + } + if (solhintEnabled && basicEnabled && !slitherEnabled && state.data && state.source !== null) { + props.event.trigger('staticAnaysisWarning', [hideWarnings + ? hintErrors.length + remixAnalysisNoLibs.length : hints.length + ssaWarnings.length]) + } + if (slitherEnabled && !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.event.trigger('staticAnaysisWarning', [hideWarnings + ? hintErrors.length + remixAnalysisNoLibs.length + slitherErrors.length + : hints.length + ssaWarnings.length + slitherWarnings.length]) + } + // props.event.trigger('staticAnaysisWarning', [-1]) + }, [hideWarnings]) + useEffect(() => { if(hints.length > 0) { props.event.trigger('staticAnaysisWarning', [hints.length]) diff --git a/libs/remix-ui/static-analyser/src/staticanalyser.d.ts b/libs/remix-ui/static-analyser/src/staticanalyser.d.ts index 002b6956e5..215acf70d3 100644 --- a/libs/remix-ui/static-analyser/src/staticanalyser.d.ts +++ b/libs/remix-ui/static-analyser/src/staticanalyser.d.ts @@ -58,10 +58,10 @@ type RemixUiStaticAnalyserReducerActionType = { interface ErrorRendererProps { message: any; - opt: ErrorRendererOptions, - warningErrors: any + options: ErrorRendererOptions, + hasWarning: boolean, editor: any, - name: string, + warningModuleName: string, } type ErrorRendererOptions = {