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
* @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<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)
setHints([])
setSsaWarnings([])
@ -57,12 +77,16 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<b
const warningErrors = []
// Run solhint
const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file)
props.analysisModule.hints = hintsResult
setHints(hintsResult)
// const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file)
// props.analysisModule.hints = solhintEnabled === false ? 0 : hintsResult
// setHints(hintsResult)
const warningResult = calculateWarningStateEntries(Object.entries(warningState))
props.analysisModule.emit('statusChanged', { key: hints.length+warningResult.length,
title: `${hints.length+warningResult.length} warning${hints.length+warningResult.length === 1 ? '' : 's'}`, type: 'warning'})
// props.analysisModule.emit('statusChanged', { key: hints.length+warningResult.length,
// 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
_paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'remixAnalyzer'])

@ -12,9 +12,7 @@ type BasicTabBodyProps = {
analysisModule: any
}
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 (
<>
{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}
/>
</div>

@ -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}
</span>
<br />
<span>{hint.type}</span>
<br />
<span>{`${hint.column}:${hint.line}`}</span>
</div>
@ -516,7 +520,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
),
title: (
<span>
Linter
Solhint
{hints.length > 0 ? (
hideWarnings ? (
<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}`}
message={warning.msg}
opt={warning.options}
warningErrors={warning.warningErrors}
warningErrors={''}
editor={props.analysisModule}
/>
</div>
@ -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}
/>
</div>
@ -673,7 +677,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
<RemixUiCheckbox
id="solhintstaticanalysis"
inputType="checkbox"
title="SolHint lints the selected contract."
title="Solhint lints Solidity code for security and style guide validations."
onClick={handleLinterEnabled}
checked={solhintEnabled }
label="Solhint"
@ -697,11 +701,11 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
</div>
{state.data && state.file.length > 0 && state.source ? <Button
buttonText={`Analyse ${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)
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)
}
@ -712,7 +716,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
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)}
message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis, 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">

Loading…
Cancel
Save