From ae9e339546ccd97d523d96f9ce80daa1bea1f903 Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Wed, 14 Jun 2023 16:52:23 +0100 Subject: [PATCH] clean up comments, console logs and count errorsby triggering staticAnalysiswarning --- apps/remix-ide/src/app/tabs/analysis-tab.js | 3 +- apps/solhint/src/app/SolhintPluginClient.ts | 13 ++--- .../src/lib/actions/staticAnalysisActions.ts | 14 ++--- .../src/lib/remix-ui-static-analyser.tsx | 52 ++++++++++++++++--- .../src/lib/components/Badge.tsx | 12 ++--- 5 files changed, 64 insertions(+), 30 deletions(-) diff --git a/apps/remix-ide/src/app/tabs/analysis-tab.js b/apps/remix-ide/src/app/tabs/analysis-tab.js index dc12651991..e5d9086253 100644 --- a/apps/remix-ide/src/app/tabs/analysis-tab.js +++ b/apps/remix-ide/src/app/tabs/analysis-tab.js @@ -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 = { @@ -57,7 +58,7 @@ class AnalysisTab extends ViewPlugin { } }) } - + setDispatch (dispatch) { this.dispatch = dispatch this.renderComponent() diff --git a/apps/solhint/src/app/SolhintPluginClient.ts b/apps/solhint/src/app/SolhintPluginClient.ts index b38d6bbdc8..8cfef7fbe2 100644 --- a/apps/solhint/src/app/SolhintPluginClient.ts +++ b/apps/solhint/src/app/SolhintPluginClient.ts @@ -11,7 +11,7 @@ import deprecations from 'solhint/lib/rules/deprecations' import miscellaneous from 'solhint/lib/rules/miscellaneous' import { customAction } from '@remixproject/plugin-api' -type Report = { +type Report = { line: number, column: number, severity: string, @@ -53,7 +53,7 @@ export class SolHint extends PluginClient { 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 * @param action interface CustomAction */ @@ -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 } @@ -99,7 +100,7 @@ export class SolHint extends PluginClient { 2: 'error', 3: 'warning' } - + rules = { 'solhint:recommended': () => { const enabledRules = {} @@ -129,7 +130,7 @@ export class SolHint extends PluginClient { return enabledRules } } - + coreRules() { return [ ...bestPractises(), @@ -140,6 +141,6 @@ export class SolHint extends PluginClient { ...security() ] } - + } diff --git a/libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts b/libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts index aa9ce0e3bb..bf2bdfb8f0 100644 --- a/libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts +++ b/libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts @@ -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, warningContainer: React.RefObject, calculateWarningStateEntries: (e:[string, any][]) => {length: number, errors: any[] }, warningState, setHints: React.Dispatch>, hints: SolHintReport[], setSlitherWarnings: React.Dispatch>, setSsaWarnings: React.Dispatch>, slitherEnabled: boolean, setStartAnalysis: React.Dispatch>) { 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 0 ? item.sourceMap[0].type : '', useSpan: true, errFile: fileName, fileName, @@ -185,11 +189,9 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch { - 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') diff --git a/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx b/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx index 79b30b6923..0769df4f60 100644 --- a/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx +++ b/libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx @@ -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) => {
{Object.entries(warningState).map((element, index) => (
- {element[1]["map"]( + { !hideWarnings && element[1]['length'] > 0 ? {element[0]} : null} + {!hideWarnings ? element[1]["map"]( (x,i) => // eslint-disable-line dot-notation - x.hasWarning && !hideWarnings + x.hasWarning ? ( // eslint-disable-next-line dot-notation
{ />
) : null - )} + ) : element[1]["map"]( + (x,i) => // eslint-disable-line dot-notation + !x.hasWarning + ? ( // eslint-disable-next-line dot-notation +
+ +
+ ) : null)} {}
))} @@ -552,9 +584,13 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { {slitherErrors.length} - ) : ( + ) : showLibsWarning === true && hideWarnings === false ? ( + 0 ? `badge-danger` : 'badge-warning'} rounded-circle ml-1 text-center`}> + {slitherWarnings.length} + + ) : ( 0 ? `badge-danger` : 'badge-warning'} rounded-circle ml-1 text-center`}> - {slitherWarnings.length} + {noLibSlitherWarnings.length} ) ) : null} @@ -567,7 +603,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
{!hideWarnings - ? showLibsWarning ? slitherWarnings.filter(warning => warning.isLibrary).map((warning, index) => ( + ? showLibsWarning ? slitherWarnings.map((warning, index) => (
{ editor={props.analysisModule} />
- )) : slitherWarnings.map((warning, index) => ( + )) : noLibSlitherWarnings.map((warning, index) => (
{ badgeStatus && checkStatusKeyValue(badgeStatus.key, badgeStatus.type) ? ( - // - // ) : null }