clean up comments, console logs and count errorsby triggering staticAnalysiswarning

pull/3779/head
Joseph Izang 1 year ago
parent 7cba306bf7
commit ae9e339546
  1. 1
      apps/remix-ide/src/app/tabs/analysis-tab.js
  2. 3
      apps/solhint/src/app/SolhintPluginClient.ts
  3. 14
      libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts
  4. 52
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx
  5. 12
      libs/remix-ui/vertical-icons-panel/src/lib/components/Badge.tsx

@ -30,6 +30,7 @@ class AnalysisTab extends ViewPlugin {
this.registry = Registry.getInstance()
this.element = document.createElement('div')
this.element.setAttribute('id', 'staticAnalyserView')
this.errorCount = 0
this._components = {}
this._components.registry = this.registry
this._deps = {

@ -65,7 +65,6 @@ export class SolHint extends PluginClient {
async lintContract(file: string) {
const hints = await this.lint(file)
console.log({ hints })
this.emit('lintingFinished', hints)
}
@ -92,6 +91,8 @@ export class SolHint extends PluginClient {
line: report.line - 1
}
})
this.emit('lintingFinished', hints)
return hints
}

@ -46,6 +46,9 @@ export const compilation = (analysisModule: AnalysisTab,
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>>) {
setStartAnalysis(true)
setHints([])
setSsaWarnings([])
setSlitherWarnings([])
if (!isSupportedVersion) return
if (state.data !== null) {
if (lastCompilationResult && (categoryIndex.length > 0 || showSlither)) {
@ -119,11 +122,12 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<b
}
warningErrors.push(options)
warningMessage.push({ msg, options, hasWarning: true, warningModuleName: moduleName })
setSsaWarnings(warningErrors)
setSsaWarnings(warningMessage)
}
}
// Slither Analysis
if (showSlither && slitherEnabled) {
setSlitherWarnings([])
try {
const compilerState = await props.analysisModule.call('solidity', 'getCompilerState')
const { currentVersion, optimize, evmVersion } = compilerState
@ -171,7 +175,7 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<b
}
const msg = message(item.title, item.description, item.more ?? '', fileName, locationString)
const options = {
type: item.sourceMap[0].type,
type: item.sourceMap && item.sourceMap.length > 0 ? item.sourceMap[0].type : '',
useSpan: true,
errFile: fileName,
fileName,
@ -185,11 +189,9 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<b
location: location
}
const slitherwarnings = []
setSlitherWarnings((prev) => {
slitherwarnings.push(...prev)
slitherwarnings.push({ msg, options, hasWarning: true, warningModuleName: 'Slither Analysis' })
return slitherwarnings
prev.push({ msg, options, hasWarning: true, warningModuleName: 'Slither Analysis' })
return prev
})
}
showWarnings(warningMessage, 'warningModuleName')

@ -223,6 +223,12 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
setWarningState(newWarningState)
}
useEffect(() => {
if(hints.length > 0) {
props.event.trigger('staticAnaysisWarning', [hints.length])
}
},[hints.length, state])
const showWarnings = (warningMessage, groupByKey) => {
const resultArray = []
warningMessage.map(x => {
@ -379,7 +385,15 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
}
const hintErrors = hints.filter(hint => hint.type === 'error')
const slitherErrors = slitherWarnings.filter(slitherError => slitherError.options.type === 'error')
const noLibSlitherWarnings = slitherWarnings.filter(w => !w.options.isLibrary)
const slitherErrors = noLibSlitherWarnings.filter(slitherError => slitherError.options.type === 'error')
// const noLibsRemixWarnings = ssaWarnings.filter(w => !w.options.isLibrary)
// const groupedWarnings = ssaWarnings.reduce((resultingObject, warning) => {
// if (!resultingObject[warning.warningModuleName]) resultingObject[warning.warningModuleName] = []
// resultingObject[warning.warningModuleName].push(warning)
// return resultingObject
// }, {})
// console.log({ slitherWarnings, noLibsRemixWarnings, ssaWarnings, groupedWarnings })
const tabKeys = [
{
@ -514,9 +528,10 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
<div className="mb-4 pt-2">
{Object.entries(warningState).map((element, index) => (
<div key={index}>
{element[1]["map"](
{ !hideWarnings && element[1]['length'] > 0 ? <span className="text-dark h6">{element[0]}</span> : null}
{!hideWarnings ? element[1]["map"](
(x,i) => // eslint-disable-line dot-notation
x.hasWarning && !hideWarnings
x.hasWarning
? ( // eslint-disable-next-line dot-notation
<div
data-id={`staticAnalysisModule${x.warningModuleName}${i}`}
@ -532,7 +547,24 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
/>
</div>
) : null
)}
) : element[1]["map"](
(x,i) => // eslint-disable-line dot-notation
!x.hasWarning
? ( // eslint-disable-next-line dot-notation
<div
data-id={`staticAnalysisModule${x.warningModuleName}${i}`}
id={`staticAnalysisModule${x.warningModuleName}${i}`}
key={i}
>
<ErrorRenderer
name={`staticAnalysisModule${x.warningModuleName}${i}`}
message={x.msg}
opt={x.options}
warningErrors={x.warningErrors}
editor={props.analysisModule}
/>
</div>
) : null)}
{}
</div>
))}
@ -552,9 +584,13 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
<i className="badge badge-warning rounded-circle ml-1">
{slitherErrors.length}
</i>
) : (
) : showLibsWarning === true && hideWarnings === false ? (
<i className={`badge ${slitherErrors.length > 0 ? `badge-danger` : 'badge-warning'} rounded-circle ml-1 text-center`}>
{slitherWarnings.length}
</i>
) : (
<i className={`badge ${slitherErrors.length > 0 ? `badge-danger` : 'badge-warning'} rounded-circle ml-1 text-center`}>
{slitherWarnings.length}
{noLibSlitherWarnings.length}
</i>
)
) : null}
@ -567,7 +603,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
<div className="mb-4 pt-2">
<Fragment>
{!hideWarnings
? showLibsWarning ? slitherWarnings.filter(warning => warning.isLibrary).map((warning, index) => (
? showLibsWarning ? slitherWarnings.map((warning, index) => (
<div
data-id={`staticAnalysisModule${warning.warningModuleName}${index}`}
id={`staticAnalysisModule${warning.warningModuleName}${index}`}
@ -581,7 +617,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
editor={props.analysisModule}
/>
</div>
)) : slitherWarnings.map((warning, index) => (
)) : noLibSlitherWarnings.map((warning, index) => (
<div
data-id={`staticAnalysisModule${warning.warningModuleName}${index}`}
id={`staticAnalysisModule${warning.warningModuleName}${index}`}

@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react'
import React, { useEffect } from 'react'
import { BadgeStatus } from './Icon'
import { CustomTooltip } from '@remix-ui/helper'
import { FormattedMessage } from 'react-intl'
@ -49,21 +50,14 @@ function Badge ({ badgeStatus }: BadgeProps) {
<>
{
badgeStatus && checkStatusKeyValue(badgeStatus.key, badgeStatus.type) ? (
// <CustomTooltip
// placement={'right'}
// tooltipClasses="text-nowrap"
// tooltipId="verticalItemsbadge"
// tooltipText={badgeStatus.pluginName && badgeStatus.pluginName === 'solidityStaticAnalysis' ? 'There are multiple warnings or errors that might need to be fixed.' :badgeStatus.title}
// >
<i
className={`${resolveClasses(badgeStatus.key, badgeStatus.type!)}`}
aria-hidden="true"
>
{ badgeStatus.pluginName && badgeStatus.pluginName === 'solidityStaticAnalysis' ? badgeStatus.type === 'warning' || badgeStatus.type === 'error' ? <span>
<i className="far fa-exclamation-triangle"></i></span>
: <span>:nbsp;</span> : badgeStatus.text }
: <span>&nbsp;</span> : badgeStatus.text }
</i>
// </CustomTooltip>
) : null
}
</>

Loading…
Cancel
Save