fixes to rectify bug

pull/3838/head
Joseph Izang 1 year ago
parent a92411bc6b
commit 83cb764646
  1. 6
      apps/remix-ide/src/app/tabs/analysis-tab.js
  2. 5
      libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts
  3. 13
      libs/remix-ui/static-analyser/src/lib/components/BasicTitle.tsx
  4. 79
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx

@ -59,7 +59,7 @@ class AnalysisTab extends ViewPlugin {
this.event.register('staticAnaysisWarning', (count) => { this.event.register('staticAnaysisWarning', (count) => {
let payloadType = '' let payloadType = ''
// let totalCount = 0
this.hints && this.hints.length > 0 ? this.hints.forEach(hint => { this.hints && this.hints.length > 0 ? this.hints.forEach(hint => {
if (hint.type === 'error') { if (hint.type === 'error') {
payloadType = 'error' payloadType = 'error'
@ -69,9 +69,7 @@ class AnalysisTab extends ViewPlugin {
}) : payloadType = 'warning' }) : payloadType = 'warning'
if (count > 0) { if (count > 0) {
console.log('staticAnaysisWarning', count) this.emit('statusChanged', { key: count, title: `${count} warning${count === 1 ? '' : 's'}`, type: payloadType })
this.internalCount = this.internalCount !== 0 ? count : count
this.emit('statusChanged', { key: this.internalCount, title: `${this.internalCount} warning${this.internalCount === 1 ? '' : 's'}`, type: payloadType })
} else if (count === 0) { } else if (count === 0) {
this.emit('statusChanged', { key: 'succeed', title: 'no warning', type: 'success' }) this.emit('statusChanged', { key: 'succeed', title: 'no warning', type: 'success' })
} else { } else {

@ -35,6 +35,8 @@ export const runLinting = async (solhintEnabled, setHints, hints: SolHintReport[
const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file) const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file)
props.analysisModule.hints = solhintEnabled === false ? 0 : hintsResult props.analysisModule.hints = solhintEnabled === false ? 0 : hintsResult
setHints(hintsResult) setHints(hintsResult)
// props.analysisModule.emit('statusChanged', { key: hints.length,
// title: `${hints.length} warning${hints.length === 1 ? '' : 's'}`, type: 'warning'})
return hintsResult return hintsResult
} }
} }
@ -77,7 +79,6 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<b
// const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file) // const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file)
// props.analysisModule.hints = solhintEnabled === false ? 0 : hintsResult // props.analysisModule.hints = solhintEnabled === false ? 0 : hintsResult
// setHints(hintsResult) // setHints(hintsResult)
const lintResult = await (await runLinting(solhintEnabled, setHints, hints, isSupportedVersion, state, props, setStartAnalysis))
// 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'})
@ -141,7 +142,7 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<b
warningErrors.push(options) warningErrors.push(options)
warningMessage.push({ msg, options, hasWarning: true, warningModuleName: moduleName }) warningMessage.push({ msg, options, hasWarning: true, warningModuleName: moduleName })
setSsaWarnings(warningMessage) setSsaWarnings(warningMessage)
// setHints(lintResult) props.event.trigger('staticAnaysisWarning', [warningMessage.length])
} }
} }
} else { } else {

@ -1,4 +1,4 @@
import React, { useEffect } from 'react' import React from 'react'
import { ErrorRendererOptions } from '../../staticanalyser' import { ErrorRendererOptions } from '../../staticanalyser'
type BasicTitleProps = { type BasicTitleProps = {
@ -7,6 +7,8 @@ type BasicTitleProps = {
showLibsWarnings?: boolean showLibsWarnings?: boolean
ssaWarnings: any[] ssaWarnings: any[]
ssaWarningsNoLibs: any[] ssaWarningsNoLibs: any[]
ssaWarningsTotal: number
ssaWarningsNoLibsTotal: number
} }
type warningResultOption = { type warningResultOption = {
@ -42,15 +44,16 @@ export function BasicTitle(props: BasicTitleProps) {
props.showLibsWarnings === false ? ( props.showLibsWarnings === false ? (
<span <span
data-id="RemixStaticAnalysisErrorCount" data-id="RemixStaticAnalysisErrorCount"
className={`badge ${props.ssaWarningsNoLibs.length > 0 ? "badge-warning" className={`badge ${props.ssaWarningsNoLibsTotal > 0 ? "badge-warning"
: "badge-danger" : props.ssaWarnings.filter(x => x.options.type === 'error').length > 0 ? "badge-danger"
: "badge-info"
} badge-pill ml-1 px-1 text-center`} } 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}
</span> </span>
) : ( ) : (
<span data-id="RemixStaticAnalysisErrorCount" className="badge badge-warning rounded-circle ml-1 text-center"> <span data-id="RemixStaticAnalysisErrorCount" className="badge badge-warning rounded-circle ml-1 text-center">
{props.ssaWarnings.length} {props.ssaWarningsTotal}
</span> </span>
) )
) : null ) : null

@ -135,6 +135,13 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
props.analysisModule.call('solidity', 'getCompilerState').then((compilerState) => setDisableForRun(compilerState.currentVersion)) 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(() => { useEffect(() => {
const checkRemixdActive = async () => { const checkRemixdActive = async () => {
const remixdActive = await props.analysisModule.call('manager', 'isActive', 'remixd') const remixdActive = await props.analysisModule.call('manager', 'isActive', 'remixd')
@ -239,72 +246,65 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
useEffect(() => { useEffect(() => {
// if hideWarnings is true // if hideWarnings is true
if(basicEnabled && !solhintEnabled && !slitherEnabled && state.data && state.source !== null ) { if(basicEnabled && hideWarnings && !solhintEnabled && !slitherEnabled && state.data && state.source !== null ) {
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', props.event.trigger('staticAnaysisWarning',
[hideWarnings ? remixAnalysisLessWarnings.length : ssaWarnings.length]) [hideWarnings ? remixAnalysisLessWarnings.length : remixAnalysisNoLibs.length])
} }
if (solhintEnabled && !basicEnabled && !slitherEnabled && state.data && state.source !== null) { if (solhintEnabled && hideWarnings && !basicEnabled && !slitherEnabled && state.data && state.source !== null) {
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', [hideWarnings ? hintErrors.length : hints?.length]) 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) { && state.data && state.source !== null) {
console.log('solhint and remix are enabled here') console.log('solhint and remix are enabled here')
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', [hideWarnings 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) { if (slitherEnabled && hideWarnings && !basicEnabled && !solhintEnabled && state.data && state.source !== null) {
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', [hideWarnings ? slitherErrors.length : slitherWarnings.length]) props.event.trigger('staticAnaysisWarning', [hideWarnings ? slitherErrors.length : slitherWarnings.length])
} }
if (slitherEnabled && basicEnabled && solhintEnabled && state.data && state.source !== null) { if (slitherEnabled && basicEnabled && solhintEnabled && hideWarnings && state.data && state.source !== null) {
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', [hideWarnings props.event.trigger('staticAnaysisWarning', [hideWarnings
? hintErrors.length + remixAnalysisLessWarnings.length + slitherErrors.length ? hintErrors.length + remixAnalysisLessWarnings.length + slitherErrors.length
: hints?.length + ssaWarnings.length + slitherWarnings.length]) : hints?.length + ssaWarnings.length + slitherWarnings.length])
} }
}, [hideWarnings, state])
useEffect(() => {
// if showLibsWarning is true // if showLibsWarning is true
if(basicEnabled && !solhintEnabled && !slitherEnabled && !hideWarnings && state.data && state.source !== null ) { if(basicEnabled && !solhintEnabled && !slitherEnabled && !hideWarnings && state.data && state.source !== null ) {
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', props.event.trigger('staticAnaysisWarning',
[showLibsWarning ? ssaWarnings.length : remixAnalysisNoLibs.length]) [showLibsWarning ? ssaWarnings.length : remixAnalysisNoLibs.length])
} }
if (solhintEnabled && !basicEnabled && !slitherEnabled && !hideWarnings && state.data && state.source !== null) { if (solhintEnabled && !basicEnabled && !slitherEnabled && !hideWarnings && state.data && state.source !== null) {
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', [showLibsWarning ? hints?.length : hints?.length]) props.event.trigger('staticAnaysisWarning', [showLibsWarning ? hints?.length : hints?.length])
} }
if (solhintEnabled && basicEnabled && !slitherEnabled && !hideWarnings && state.data && state.source !== null) { if (solhintEnabled && basicEnabled && !slitherEnabled && !hideWarnings && state.data && state.source !== null && state.data && state.source !== null) {
console.log('solhint and remix are enabled here')
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', [showLibsWarning props.event.trigger('staticAnaysisWarning', [showLibsWarning
? hints?.length + ssaWarnings.length : hints?.length + remixAnalysisNoLibs.length]) ? hints?.length + ssaWarnings.length : hints?.length + remixAnalysisNoLibs.length])
} }
if (slitherEnabled && !basicEnabled && !solhintEnabled && !hideWarnings && state.data && state.source !== null) { if (slitherEnabled && !basicEnabled && !solhintEnabled && !hideWarnings && state.data && state.source !== null && state.data && state.source !== null) {
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', [showLibsWarning && noLibSlitherWarnings.length]) props.event.trigger('staticAnaysisWarning', [showLibsWarning && noLibSlitherWarnings.length])
} }
if (slitherEnabled && basicEnabled && solhintEnabled && !hideWarnings && state.data && state.source !== null) { if (slitherEnabled && basicEnabled && solhintEnabled && !hideWarnings && state.data && state.source !== null && state.data && state.source !== null) {
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', [showLibsWarning props.event.trigger('staticAnaysisWarning', [showLibsWarning
? hints?.length + ssaWarnings.length + slitherWarnings.length : hints?.length + remixAnalysisNoLibs.length + noLibSlitherWarnings.length]) ? hints?.length + ssaWarnings.length + slitherWarnings.length : hints?.length + remixAnalysisNoLibs.length + noLibSlitherWarnings.length])
} }
if(basicEnabled && solhintEnabled && !slitherEnabled && !hideWarnings && !showLibsWarning) { }, [showLibsWarning, state])
props.analysisModule.internalCount = 0
useEffect(() => {
if(basicEnabled && solhintEnabled && !slitherEnabled && !hideWarnings && !showLibsWarning && state.data && state.source !== null) {
props.event.trigger('staticAnaysisWarning', [hints?.length + remixAnalysisNoLibs.length]) props.event.trigger('staticAnaysisWarning', [hints?.length + remixAnalysisNoLibs.length])
} }
if(solhintEnabled && basicEnabled && slitherEnabled && !hideWarnings && !showLibsWarning) { if(solhintEnabled && basicEnabled && slitherEnabled && !hideWarnings && !showLibsWarning && state.data && state.source !== null) {
props.analysisModule.internalCount = 0
props.analysisModule.hints = [] props.analysisModule.hints = []
props.event.trigger('staticAnaysisWarning', [hints?.length + remixAnalysisNoLibs.length + slitherWarnings.length]) props.event.trigger('staticAnaysisWarning', [hints?.length + remixAnalysisNoLibs.length + slitherWarnings.length])
} }
if(solhintEnabled && basicEnabled && !slitherEnabled && hideWarnings && showLibsWarning) { if(solhintEnabled && basicEnabled && !slitherEnabled && hideWarnings && showLibsWarning && state.data && state.source !== null) {
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', [hintErrors.length + remixAnalysisLessWarnings.length]) 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(() => { useEffect(() => {
if(solhintEnabled === false) { if(solhintEnabled === false) {
@ -312,6 +312,14 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
} }
}, [solhintEnabled]) }, [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) => { const showWarnings = (warningMessage, groupByKey) => {
@ -381,7 +389,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
} }
} }
const handleLinterEnabled = async () => { const handleLinterEnabled = () => {
if (solhintEnabled) { if (solhintEnabled) {
setSolhintEnabled(false) setSolhintEnabled(false)
} else { } else {
@ -591,6 +599,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
ssaWarnings={ssaWarnings} ssaWarnings={ssaWarnings}
ssaWarningsNoLibs={remixAnalysisNoLibs} ssaWarningsNoLibs={remixAnalysisNoLibs}
warningStateEntries={Object.entries(warningState)} warningStateEntries={Object.entries(warningState)}
ssaWarningsNoLibsTotal={remixAnalysisNoLibs.length}
ssaWarningsTotal={ssaWarnings.length}
/> />
), ),
child: ( child: (
@ -705,12 +715,11 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
id="checkAllEntries" id="checkAllEntries"
inputType="checkbox" inputType="checkbox"
title="Remix analysis runs a basic analysis." title="Remix analysis runs a basic analysis."
// checked={Object.values(groupedModules).map((value: any) => { checked={basicEnabled && Object.values(groupedModules).map((value: any) => {
// return (value.map(x => { return (value.map(x => {
// return x._index.toString() return x._index.toString()
// })) }))
// }).flat().every(el => categoryIndex.includes(el))} }).flat().every(el => categoryIndex.includes(el))}
checked={basicEnabled}
onClick={handleBasicEnabled} onClick={handleBasicEnabled}
label="Remix" label="Remix"
onChange={() => {}} onChange={() => {}}

Loading…
Cancel
Save