cleanup, remove redundant warnings

pull/3838/head
Joseph Izang 1 year ago
parent 76d77c17a4
commit daefd70527
  1. 36
      libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts
  2. 6
      libs/remix-ui/static-analyser/src/lib/components/BasicTabBody.tsx
  3. 48
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx

@ -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<React.SetStateAction<boolean>>) => {
// 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 * Run the analysis on the currently compiled contract
* @param lastCompilationResult * @param lastCompilationResult
@ -44,7 +64,7 @@ export const compilation = (analysisModule: AnalysisTab,
*/ */
// 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>>) { slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<boolean>>, solhintEnabled: boolean, basicEnabled: boolean) {
setStartAnalysis(true) setStartAnalysis(true)
setHints([]) setHints([])
setSsaWarnings([]) setSsaWarnings([])
@ -57,12 +77,16 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<b
const warningErrors = [] const warningErrors = []
// 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 = hintsResult // props.analysisModule.hints = solhintEnabled === false ? 0 : hintsResult
setHints(hintsResult) // setHints(hintsResult)
const warningResult = calculateWarningStateEntries(Object.entries(warningState)) 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'})
runLinting(solhintEnabled, setHints, hints, warningResult, isSupportedVersion, state, props, setStartAnalysis)
//---------------------------- RunLinting End ----------------------------
// Remix Analysis // Remix Analysis
_paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'remixAnalyzer']) _paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'remixAnalyzer'])

@ -12,9 +12,7 @@ type BasicTabBodyProps = {
analysisModule: any analysisModule: any
} }
export function BasicTabBody({ state, hideWarnings, ssaWarnings, ssaWarningsNoLibs, showLibsWarning, warningState, startAnalysis, analysisModule}: BasicTabBodyProps) { export function BasicTabBody({ state, hideWarnings, ssaWarnings, ssaWarningsNoLibs, showLibsWarning, warningState, startAnalysis, analysisModule}: BasicTabBodyProps) {
const test = ssaWarningsNoLibs.filter(x => x.options.isLibrary === false)
const test1 = ssaWarningsNoLibs.filter(x => x.options.isLibrary)
console.log({test, test1 })
return ( return (
<> <>
{ssaWarningsNoLibs.length > 0 ? ( {ssaWarningsNoLibs.length > 0 ? (
@ -32,7 +30,7 @@ console.log({test, test1 })
name={`staticAnalysisModule${item.warningModuleName}${index}`} name={`staticAnalysisModule${item.warningModuleName}${index}`}
message={item.msg} message={item.msg}
opt={item.options} opt={item.options}
warningErrors={item.warningErrors} warningErrors={''}
editor={analysisModule} editor={analysisModule}
/> />
</div> </div>

@ -9,7 +9,7 @@ import * as semver from 'semver'
import { TreeView, TreeViewItem } from '@remix-ui/tree-view' // eslint-disable-line import { TreeView, TreeViewItem } from '@remix-ui/tree-view' // eslint-disable-line
import { RemixUiCheckbox } from '@remix-ui/checkbox' // eslint-disable-line import { RemixUiCheckbox } from '@remix-ui/checkbox' // eslint-disable-line
import ErrorRenderer from './ErrorRenderer' // 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 { initialState, analysisReducer } from './reducers/staticAnalysisReducer'
import { CodeAnalysis } from '@remix-project/remix-analyzer' import { CodeAnalysis } from '@remix-project/remix-analyzer'
import Tab from 'react-bootstrap/Tab' import Tab from 'react-bootstrap/Tab'
@ -116,6 +116,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
setSlitherWarnings([]) setSlitherWarnings([])
setSsaWarnings([]) setSsaWarnings([])
compilation(props.analysisModule, dispatch) compilation(props.analysisModule, dispatch)
props.event.trigger('staticAnaysisWarning', [-1])
}, [props]) }, [props])
useEffect(() => { useEffect(() => {
@ -125,9 +126,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
setSlitherWarnings([]) setSlitherWarnings([])
setSsaWarnings([]) setSsaWarnings([])
const runAnalysis = async () => { 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 () => { } return () => { }
}, [state]) }, [state])
@ -146,19 +146,13 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
checkRemixdActive() checkRemixdActive()
}, [props]) }, [props])
useEffect(() => {
if(hints.length > 0) {
props.event.trigger('staticAnaysisWarning', [hints.length])
}
}, [hints.length])
useEffect(() => { useEffect(() => {
props.analysisModule.on('filePanel', 'setWorkspace', (currentWorkspace) => { props.analysisModule.on('filePanel', 'setWorkspace', (currentWorkspace) => {
// Reset warning state // Reset warning state
allWarnings.current = {} allWarnings.current = {}
setWarningState({}) setWarningState({})
// Reset badge // Reset badge
props.event.trigger('staticAnaysisWarning', [0]) props.event.trigger('staticAnaysisWarning', [-1])
// Reset state // Reset state
dispatch({ type: '', payload: initialState }) dispatch({ type: '', payload: initialState })
setHints([]) setHints([])
@ -184,7 +178,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
setSlitherEnabled(false) setSlitherEnabled(false)
setSsaWarnings([]) setSsaWarnings([])
// Reset badge // Reset badge
props.event.trigger('staticAnaysisWarning', [0]) props.event.trigger('staticAnaysisWarning', [-1])
// Reset state // Reset state
dispatch({ type: '', payload: initialState }) dispatch({ type: '', payload: initialState })
setShowSlither(false) setShowSlither(false)
@ -257,6 +251,19 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
} }
}, [ssaWarnings.length]) }, [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) => { const showWarnings = (warningMessage, groupByKey) => {
@ -326,7 +333,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
} }
} }
const handleLinterEnabled = () => { const handleLinterEnabled = async () => {
if (solhintEnabled) { if (solhintEnabled) {
setSolhintEnabled(false) setSolhintEnabled(false)
} else { } else {
@ -414,8 +421,6 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
setHideWarnings(!hideWarnings) setHideWarnings(!hideWarnings)
} }
console.log({ ssaWarnings, remixAnalysisNoLibs, slitherWarnings, hints })
const tabKeys = [ const tabKeys = [
{ {
tabKey: "linter", tabKey: "linter",
@ -502,7 +507,6 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
{hint.formattedMessage} {hint.formattedMessage}
</span> </span>
<br /> <br />
<span>{hint.type}</span>
<br /> <br />
<span>{`${hint.column}:${hint.line}`}</span> <span>{`${hint.column}:${hint.line}`}</span>
</div> </div>
@ -516,7 +520,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
), ),
title: ( title: (
<span> <span>
Linter Solhint
{hints.length > 0 ? ( {hints.length > 0 ? (
hideWarnings ? ( hideWarnings ? (
<i className={`badge ${hints.filter(x => x.type === 'error').length > 0 <i className={`badge ${hints.filter(x => x.type === 'error').length > 0
@ -610,7 +614,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
name={`staticAnalysisModule${warning.warningModuleName}${index}`} name={`staticAnalysisModule${warning.warningModuleName}${index}`}
message={warning.msg} message={warning.msg}
opt={warning.options} opt={warning.options}
warningErrors={warning.warningErrors} warningErrors={''}
editor={props.analysisModule} editor={props.analysisModule}
/> />
</div> </div>
@ -625,7 +629,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
name={`staticAnalysisModule${warning.warningModuleName}${index}`} name={`staticAnalysisModule${warning.warningModuleName}${index}`}
message={warning.msg} message={warning.msg}
opt={warning.options} opt={warning.options}
warningErrors={warning.warningErrors} warningErrors={''}
editor={props.analysisModule} editor={props.analysisModule}
/> />
</div> </div>
@ -673,7 +677,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
<RemixUiCheckbox <RemixUiCheckbox
id="solhintstaticanalysis" id="solhintstaticanalysis"
inputType="checkbox" inputType="checkbox"
title="SolHint lints the selected contract." title="Solhint lints Solidity code for security and style guide validations."
onClick={handleLinterEnabled} onClick={handleLinterEnabled}
checked={solhintEnabled } checked={solhintEnabled }
label="Solhint" label="Solhint"
@ -697,11 +701,11 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
</div> </div>
{state.data && state.file.length > 0 && state.source ? <Button {state.data && state.file.length > 0 && state.source ? <Button
buttonText={`Analyse ${state.file}`} buttonText={`Analyse ${state.file}`}
title={`${runButtonTitle}`}
classList="btn btn-sm btn-primary btn-block" classList="btn btn-sm btn-primary btn-block"
onClick={async () => { onClick={async () => {
await run(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq, 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) 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, 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) message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis)
} }
@ -712,7 +716,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
title={`${runButtonTitle}`} title={`${runButtonTitle}`}
classList="btn btn-sm btn-primary btn-block" 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, 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)} message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis, solhintEnabled, basicEnabled)}
disabled={(state.data === null || !isSupportedVersion) || (!solhintEnabled && !basicEnabled) } disabled={(state.data === null || !isSupportedVersion) || (!solhintEnabled && !basicEnabled) }
/>} />}
{state && state.data !== null && state.source !== null && state.file.length > 0 ? (<div className="d-flex border-top flex-column"> {state && state.data !== null && state.source !== null && state.file.length > 0 ? (<div className="d-flex border-top flex-column">

Loading…
Cancel
Save