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) => {
let payloadType = ''
// let totalCount = 0
this.hints && this.hints.length > 0 ? this.hints.forEach(hint => {
if (hint.type === 'error') {
payloadType = 'error'
@ -69,9 +69,7 @@ class AnalysisTab extends ViewPlugin {
}) : payloadType = 'warning'
if (count > 0) {
console.log('staticAnaysisWarning', count)
this.internalCount = this.internalCount !== 0 ? count : count
this.emit('statusChanged', { key: this.internalCount, title: `${this.internalCount} warning${this.internalCount === 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 {

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

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

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

Loading…
Cancel
Save