From daefd70527cf4282407e6311890edf543b3b6469 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Thu, 22 Jun 2023 22:43:17 +0100 Subject: [PATCH] cleanup, remove redundant warnings --- .../src/lib/actions/staticAnalysisActions.ts | 36 +++++++++++--- .../src/lib/components/BasicTabBody.tsx | 6 +-- .../src/lib/remix-ui-static-analyser.tsx | 48 ++++++++++--------- 3 files changed, 58 insertions(+), 32 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 18da143ad1..e94189ba29 100644 --- a/libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts +++ b/libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts @@ -23,6 +23,26 @@ export const compilation = (analysisModule: AnalysisTab, } } +export const runLinting = async (solhintEnabled, setHints, hints: SolHintReport[], warningResult, isSupportedVersion, state: RemixUiStaticAnalyserState, + props: RemixUiStaticAnalyserProps, setStartAnalysis: React.Dispatch>) => { + // Run solhint + setStartAnalysis(true) + props.analysisModule.hints = [] + if (!isSupportedVersion) return + if (solhintEnabled === false) return + if (state.data !== null) { + if (state.data && solhintEnabled) { + props.analysisModule.hints = [] + setHints([]) + 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+warningResult.length, + title: `${hints.length+warningResult.length} warning${hints.length+warningResult.length === 1 ? '' : 's'}`, type: 'warning'}) + } + } +} + /** * Run the analysis on the currently compiled contract * @param lastCompilationResult @@ -44,7 +64,7 @@ export const compilation = (analysisModule: AnalysisTab, */ // 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, warningContainer: React.RefObject, calculateWarningStateEntries: (e:[string, any][]) => {length: number, errors: any[] }, warningState, setHints: React.Dispatch>, hints: SolHintReport[], setSlitherWarnings: React.Dispatch>, setSsaWarnings: React.Dispatch>, -slitherEnabled: boolean, setStartAnalysis: React.Dispatch>) { +slitherEnabled: boolean, setStartAnalysis: React.Dispatch>, solhintEnabled: boolean, basicEnabled: boolean) { setStartAnalysis(true) setHints([]) setSsaWarnings([]) @@ -57,12 +77,16 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch x.options.isLibrary === false) -const test1 = ssaWarningsNoLibs.filter(x => x.options.isLibrary) -console.log({test, test1 }) + return ( <> {ssaWarningsNoLibs.length > 0 ? ( @@ -32,7 +30,7 @@ console.log({test, test1 }) name={`staticAnalysisModule${item.warningModuleName}${index}`} message={item.msg} opt={item.options} - warningErrors={item.warningErrors} + warningErrors={''} editor={analysisModule} /> 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 b63e0e89d7..a79502ad37 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 @@ -9,7 +9,7 @@ import * as semver from 'semver' import { TreeView, TreeViewItem } from '@remix-ui/tree-view' // eslint-disable-line import { RemixUiCheckbox } from '@remix-ui/checkbox' // eslint-disable-line import ErrorRenderer from './ErrorRenderer' // eslint-disable-line -import { compilation, runSlitherAnalysis } from './actions/staticAnalysisActions' +import { compilation, runLinting, runSlitherAnalysis } from './actions/staticAnalysisActions' import { initialState, analysisReducer } from './reducers/staticAnalysisReducer' import { CodeAnalysis } from '@remix-project/remix-analyzer' import Tab from 'react-bootstrap/Tab' @@ -116,6 +116,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { setSlitherWarnings([]) setSsaWarnings([]) compilation(props.analysisModule, dispatch) + props.event.trigger('staticAnaysisWarning', [-1]) }, [props]) useEffect(() => { @@ -125,9 +126,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { setSlitherWarnings([]) setSsaWarnings([]) const runAnalysis = 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) + 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) } - props.event.trigger('staticAnaysisWarning', [0]) return () => { } }, [state]) @@ -146,19 +146,13 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { checkRemixdActive() }, [props]) - useEffect(() => { - if(hints.length > 0) { - props.event.trigger('staticAnaysisWarning', [hints.length]) - } - }, [hints.length]) - useEffect(() => { props.analysisModule.on('filePanel', 'setWorkspace', (currentWorkspace) => { // Reset warning state allWarnings.current = {} setWarningState({}) // Reset badge - props.event.trigger('staticAnaysisWarning', [0]) + props.event.trigger('staticAnaysisWarning', [-1]) // Reset state dispatch({ type: '', payload: initialState }) setHints([]) @@ -184,7 +178,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { setSlitherEnabled(false) setSsaWarnings([]) // Reset badge - props.event.trigger('staticAnaysisWarning', [0]) + props.event.trigger('staticAnaysisWarning', [-1]) // Reset state dispatch({ type: '', payload: initialState }) setShowSlither(false) @@ -257,6 +251,19 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { } }, [ssaWarnings.length]) + useEffect(() => { + if(hints.length === 0) { + props.analysisModule.hints = [] + props.event.trigger('staticAnaysisWarning', []) + } + }, [hints.length]) + + useEffect(() => { + if(solhintEnabled === false) { + props.analysisModule.hints = [] + } + }, [solhintEnabled]) + const showWarnings = (warningMessage, groupByKey) => { @@ -326,7 +333,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { } } - const handleLinterEnabled = () => { + const handleLinterEnabled = async () => { if (solhintEnabled) { setSolhintEnabled(false) } else { @@ -414,8 +421,6 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { setHideWarnings(!hideWarnings) } - console.log({ ssaWarnings, remixAnalysisNoLibs, slitherWarnings, hints }) - const tabKeys = [ { tabKey: "linter", @@ -502,7 +507,6 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { {hint.formattedMessage}
- {hint.type}
{`${hint.column}:${hint.line}`} @@ -516,7 +520,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { ), title: ( - Linter + Solhint {hints.length > 0 ? ( hideWarnings ? ( x.type === 'error').length > 0 @@ -610,7 +614,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { name={`staticAnalysisModule${warning.warningModuleName}${index}`} message={warning.msg} opt={warning.options} - warningErrors={warning.warningErrors} + warningErrors={''} editor={props.analysisModule} /> @@ -625,7 +629,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { name={`staticAnalysisModule${warning.warningModuleName}${index}`} message={warning.msg} opt={warning.options} - warningErrors={warning.warningErrors} + warningErrors={''} editor={props.analysisModule} /> @@ -673,7 +677,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { { {state.data && state.file.length > 0 && state.source ?