From 5c8eb2d705db32ba0d2463bdd40b66745816c77b Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Wed, 31 May 2023 16:46:59 +0100 Subject: [PATCH] reorder params, handle lint hints reset on workspace change. fix badges --- .../src/lib/remix-ui-static-analyser.tsx | 68 +++++++++++-------- 1 file changed, 39 insertions(+), 29 deletions(-) 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 870f2223bc..f50a516710 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 @@ -108,11 +108,10 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { useEffect(() => { setWarningState({}) const runAnalysis = async () => { - await run(state.data, state.source, state.file, allWarnings, props, isSupportedVersion, slitherEnabled, categoryIndex, groupedModules, runner,_paq, - message, showWarnings, allWarnings, warningContainer) - // Run solhint - const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file) - setHints(hintsResult) + await run(state.data, state.source, state.file, state, props, isSupportedVersion, slitherEnabled, categoryIndex, groupedModules, runner,_paq, message, showWarnings, allWarnings, warningContainer,calculateWarningStateEntries, warningState, setHints, hints) + // // Run solhint + // const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file) + // setHints(hintsResult) } if (basicEnabled) { if (state.data !== null) { @@ -136,6 +135,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { props.event.trigger('staticAnaysisWarning', []) // Reset state dispatch({ type: '', payload: initialState }) + setHints([]) // Show 'Enable Slither Analysis' checkbox if (currentWorkspace && currentWorkspace.isLocalhost === true) setShowSlither(true) else { @@ -148,6 +148,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { if (plugin.name === 'remixd') { // Reset warning state setWarningState([]) + setHints([]) // Reset badge props.event.trigger('staticAnaysisWarning', []) // Reset state @@ -157,10 +158,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { } }) const warningResult = calculateWarningStateEntries(Object.entries(warningState)) - console.log({ warningResult, hintCount: hints.length }) - props.analysisModule.emit('statusChanged', 'solhint', { key: hints.length+warningResult, - title: `${hints.length+warningResult} warning${hints.length+warningResult === 1 ? '' : 's'}`, type: 'warning'}) - props.event.trigger('staticAnaysisWarning', [hints.length+warningResult]) + props.analysisModule.emit('statusChanged', { key: hints.length+warningResult.length, + title: `${hints.length+warningResult.length} warning${hints.length+warningResult.length === 1 ? '' : 's'}`, type: 'warning'}) // eslint-disable-next-line @typescript-eslint/no-unused-vars props.analysisModule.on('solidity', 'compilerLoaded', async (version: string, license: string) => { setDisableForRun(version) @@ -362,6 +361,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { setHideWarnings(!hideWarnings) } + const hintErrors = hints.filter(hint => hint.type === 'error') + const tabKeys = [ { tabKey: 'linter', @@ -370,10 +371,9 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { {hints.length > 0 &&
- { - hints.map((hint, index) => ( - -
+ {!hideWarnings ? hints.map((hint, index) => ( +
{ await props.analysisModule.call('editor', 'discardHighlight') @@ -389,25 +389,36 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { {hint.formattedMessage} {hint.type}
{`${hint.column}:${hint.line}`} -
-
- - )).sort((a, b) => { - if(a.type === 'warning' && b.type === 'error') return 1 - if(a.type === 'error' && b.type === 'warning') return -1 - return 0 - }) - } +
+
)) : hintErrors.map((hint, index) => (
+
{ + await props.analysisModule.call('editor', 'discardHighlight') + await props.analysisModule.call('editor', 'highlight', { + end: { + line: hint.line, column: hint.column+1 + }, + start: { + line: hint.line, column: hint.column + } + }, state.file, '', { focus: true }) + }}> + {hint.formattedMessage} + {hint.type}
+ {`${hint.column}:${hint.line}`} +
+
)) + } +
} ), - title: Linter{hints.length > 0 ? {hints.length} : null} + title: Linter{hints.length > 0 ? hideWarnings ? {hintErrors.length} : {hints.length} : null} }, { tabKey: 'basic', - title: , + title: , child: <> {Object.entries(warningState).length > 0 &&
@@ -415,9 +426,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { { (Object.entries(warningState).map((element, index) => (
- {/* {element[1]['length'] > 0 ? {element[0]} : null} */} {element[1]['map']((x, i) => ( // eslint-disable-line dot-notation - x.hasWarning ? ( // eslint-disable-next-line dot-notation + x.hasWarning && !hideWarnings ? ( // eslint-disable-next-line dot-notation
@@ -438,7 +448,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { child:
, } ] - + const t = Object.entries(warningState) const checkBasicStatus = () => { return Object.values(groupedModules).map((value: any) => { return (value.map(x => { @@ -491,8 +501,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { buttonText="Analyse" title={runButtonTitle} classList="btn btn-sm btn-primary btn-block" - onClick={async () => await run(state.data, state.source, state.file, allWarnings, props, isSupportedVersion, slitherEnabled, categoryIndex, groupedModules, runner,_paq, - message, showWarnings, allWarnings, warningContainer)} + onClick={async () => await run(state.data, state.source, state.file, state , props, isSupportedVersion, slitherEnabled, categoryIndex, groupedModules, runner,_paq, + message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints)} disabled={(state.data === null || categoryIndex.length === 0) && !slitherEnabled || !isSupportedVersion } />