clean up comments, console logs and count errorsby triggering staticAnalysiswarning

pull/3779/head
Joseph Izang 1 year ago
parent 7cba306bf7
commit ae9e339546
  1. 3
      apps/remix-ide/src/app/tabs/analysis-tab.js
  2. 13
      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.registry = Registry.getInstance()
this.element = document.createElement('div') this.element = document.createElement('div')
this.element.setAttribute('id', 'staticAnalyserView') this.element.setAttribute('id', 'staticAnalyserView')
this.errorCount = 0
this._components = {} this._components = {}
this._components.registry = this.registry this._components.registry = this.registry
this._deps = { this._deps = {
@ -57,7 +58,7 @@ class AnalysisTab extends ViewPlugin {
} }
}) })
} }
setDispatch (dispatch) { setDispatch (dispatch) {
this.dispatch = dispatch this.dispatch = dispatch
this.renderComponent() this.renderComponent()

@ -11,7 +11,7 @@ import deprecations from 'solhint/lib/rules/deprecations'
import miscellaneous from 'solhint/lib/rules/miscellaneous' import miscellaneous from 'solhint/lib/rules/miscellaneous'
import { customAction } from '@remixproject/plugin-api' import { customAction } from '@remixproject/plugin-api'
type Report = { type Report = {
line: number, line: number,
column: number, column: number,
severity: string, severity: string,
@ -53,7 +53,7 @@ export class SolHint extends PluginClient {
this.triggerLinter = false this.triggerLinter = false
} }
/** /**
* method to handle context menu action in file explorer for * method to handle context menu action in file explorer for
* solhint plugin * solhint plugin
* @param action interface CustomAction * @param action interface CustomAction
*/ */
@ -65,7 +65,6 @@ export class SolHint extends PluginClient {
async lintContract(file: string) { async lintContract(file: string) {
const hints = await this.lint(file) const hints = await this.lint(file)
console.log({ hints })
this.emit('lintingFinished', hints) this.emit('lintingFinished', hints)
} }
@ -92,6 +91,8 @@ export class SolHint extends PluginClient {
line: report.line - 1 line: report.line - 1
} }
}) })
this.emit('lintingFinished', hints)
return hints return hints
} }
@ -99,7 +100,7 @@ export class SolHint extends PluginClient {
2: 'error', 2: 'error',
3: 'warning' 3: 'warning'
} }
rules = { rules = {
'solhint:recommended': () => { 'solhint:recommended': () => {
const enabledRules = {} const enabledRules = {}
@ -129,7 +130,7 @@ export class SolHint extends PluginClient {
return enabledRules return enabledRules
} }
} }
coreRules() { coreRules() {
return [ return [
...bestPractises(), ...bestPractises(),
@ -140,6 +141,6 @@ export class SolHint extends PluginClient {
...security() ...security()
] ]
} }
} }

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

@ -223,6 +223,12 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
setWarningState(newWarningState) setWarningState(newWarningState)
} }
useEffect(() => {
if(hints.length > 0) {
props.event.trigger('staticAnaysisWarning', [hints.length])
}
},[hints.length, state])
const showWarnings = (warningMessage, groupByKey) => { const showWarnings = (warningMessage, groupByKey) => {
const resultArray = [] const resultArray = []
warningMessage.map(x => { warningMessage.map(x => {
@ -379,7 +385,15 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
} }
const hintErrors = hints.filter(hint => hint.type === 'error') 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 = [ const tabKeys = [
{ {
@ -514,9 +528,10 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
<div className="mb-4 pt-2"> <div className="mb-4 pt-2">
{Object.entries(warningState).map((element, index) => ( {Object.entries(warningState).map((element, index) => (
<div key={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,i) => // eslint-disable-line dot-notation
x.hasWarning && !hideWarnings x.hasWarning
? ( // eslint-disable-next-line dot-notation ? ( // eslint-disable-next-line dot-notation
<div <div
data-id={`staticAnalysisModule${x.warningModuleName}${i}`} data-id={`staticAnalysisModule${x.warningModuleName}${i}`}
@ -532,7 +547,24 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
/> />
</div> </div>
) : null ) : 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> </div>
))} ))}
@ -552,9 +584,13 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
<i className="badge badge-warning rounded-circle ml-1"> <i className="badge badge-warning rounded-circle ml-1">
{slitherErrors.length} {slitherErrors.length}
</i> </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`}> <i className={`badge ${slitherErrors.length > 0 ? `badge-danger` : 'badge-warning'} rounded-circle ml-1 text-center`}>
{slitherWarnings.length} {noLibSlitherWarnings.length}
</i> </i>
) )
) : null} ) : null}
@ -567,7 +603,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
<div className="mb-4 pt-2"> <div className="mb-4 pt-2">
<Fragment> <Fragment>
{!hideWarnings {!hideWarnings
? showLibsWarning ? slitherWarnings.filter(warning => warning.isLibrary).map((warning, index) => ( ? showLibsWarning ? slitherWarnings.map((warning, index) => (
<div <div
data-id={`staticAnalysisModule${warning.warningModuleName}${index}`} data-id={`staticAnalysisModule${warning.warningModuleName}${index}`}
id={`staticAnalysisModule${warning.warningModuleName}${index}`} id={`staticAnalysisModule${warning.warningModuleName}${index}`}
@ -581,7 +617,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
editor={props.analysisModule} editor={props.analysisModule}
/> />
</div> </div>
)) : slitherWarnings.map((warning, index) => ( )) : noLibSlitherWarnings.map((warning, index) => (
<div <div
data-id={`staticAnalysisModule${warning.warningModuleName}${index}`} data-id={`staticAnalysisModule${warning.warningModuleName}${index}`}
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 */ /* eslint-disable @typescript-eslint/no-non-null-assertion */
import React from 'react' import React, { useEffect } from 'react'
import { BadgeStatus } from './Icon' import { BadgeStatus } from './Icon'
import { CustomTooltip } from '@remix-ui/helper' import { CustomTooltip } from '@remix-ui/helper'
import { FormattedMessage } from 'react-intl' import { FormattedMessage } from 'react-intl'
@ -49,21 +50,14 @@ function Badge ({ badgeStatus }: BadgeProps) {
<> <>
{ {
badgeStatus && checkStatusKeyValue(badgeStatus.key, badgeStatus.type) ? ( 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 <i
className={`${resolveClasses(badgeStatus.key, badgeStatus.type!)}`} className={`${resolveClasses(badgeStatus.key, badgeStatus.type!)}`}
aria-hidden="true" aria-hidden="true"
> >
{ badgeStatus.pluginName && badgeStatus.pluginName === 'solidityStaticAnalysis' ? badgeStatus.type === 'warning' || badgeStatus.type === 'error' ? <span> { badgeStatus.pluginName && badgeStatus.pluginName === 'solidityStaticAnalysis' ? badgeStatus.type === 'warning' || badgeStatus.type === 'error' ? <span>
<i className="far fa-exclamation-triangle"></i></span> <i className="far fa-exclamation-triangle"></i></span>
: <span>:nbsp;</span> : badgeStatus.text } : <span>&nbsp;</span> : badgeStatus.text }
</i> </i>
// </CustomTooltip>
) : null ) : null
} }
</> </>

Loading…
Cancel
Save