reorder params, handle lint hints reset on workspace change. fix badges

pull/5370/head
Joseph Izang 2 years ago
parent 5cc7bc8717
commit 5c8eb2d705
  1. 68
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx

@ -108,11 +108,10 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
useEffect(() => { useEffect(() => {
setWarningState({}) setWarningState({})
const runAnalysis = async () => { const runAnalysis = async () => {
await run(state.data, state.source, state.file, allWarnings, props, isSupportedVersion, slitherEnabled, categoryIndex, groupedModules, runner,_paq, await run(state.data, state.source, state.file, state, props, isSupportedVersion, slitherEnabled, categoryIndex, groupedModules, runner,_paq, message, showWarnings, allWarnings, warningContainer,calculateWarningStateEntries, warningState, setHints, hints)
message, showWarnings, allWarnings, warningContainer) // // Run solhint
// Run solhint // const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file)
const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file) // setHints(hintsResult)
setHints(hintsResult)
} }
if (basicEnabled) { if (basicEnabled) {
if (state.data !== null) { if (state.data !== null) {
@ -136,6 +135,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
props.event.trigger('staticAnaysisWarning', []) props.event.trigger('staticAnaysisWarning', [])
// Reset state // Reset state
dispatch({ type: '', payload: initialState }) dispatch({ type: '', payload: initialState })
setHints([])
// Show 'Enable Slither Analysis' checkbox // Show 'Enable Slither Analysis' checkbox
if (currentWorkspace && currentWorkspace.isLocalhost === true) setShowSlither(true) if (currentWorkspace && currentWorkspace.isLocalhost === true) setShowSlither(true)
else { else {
@ -148,6 +148,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
if (plugin.name === 'remixd') { if (plugin.name === 'remixd') {
// Reset warning state // Reset warning state
setWarningState([]) setWarningState([])
setHints([])
// Reset badge // Reset badge
props.event.trigger('staticAnaysisWarning', []) props.event.trigger('staticAnaysisWarning', [])
// Reset state // Reset state
@ -157,10 +158,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
} }
}) })
const warningResult = calculateWarningStateEntries(Object.entries(warningState)) const warningResult = calculateWarningStateEntries(Object.entries(warningState))
console.log({ warningResult, hintCount: hints.length }) props.analysisModule.emit('statusChanged', { key: hints.length+warningResult.length,
props.analysisModule.emit('statusChanged', 'solhint', { key: hints.length+warningResult, title: `${hints.length+warningResult.length} warning${hints.length+warningResult.length === 1 ? '' : 's'}`, type: 'warning'})
title: `${hints.length+warningResult} warning${hints.length+warningResult === 1 ? '' : 's'}`, type: 'warning'})
props.event.trigger('staticAnaysisWarning', [hints.length+warningResult])
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
props.analysisModule.on('solidity', 'compilerLoaded', async (version: string, license: string) => { props.analysisModule.on('solidity', 'compilerLoaded', async (version: string, license: string) => {
setDisableForRun(version) setDisableForRun(version)
@ -362,6 +361,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
setHideWarnings(!hideWarnings) setHideWarnings(!hideWarnings)
} }
const hintErrors = hints.filter(hint => hint.type === 'error')
const tabKeys = [ const tabKeys = [
{ {
tabKey: 'linter', tabKey: 'linter',
@ -370,10 +371,9 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
{hints.length > 0 && {hints.length > 0 &&
<div id='solhintlintingresult' className="mb-5"> <div id='solhintlintingresult' className="mb-5">
<div className="mb-4 pt-2"> <div className="mb-4 pt-2">
{ <Fragment>
hints.map((hint, index) => ( {!hideWarnings ? hints.map((hint, index) => (
<Fragment key={index}> <div key={index} className={`${hint.type === 'warning' ?
<div key={index} className={`${hint.type === 'warning' ?
'alert alert-warning' : 'alert alert-danger'}`}> 'alert alert-warning' : 'alert alert-danger'}`}>
<div onClick={async () => { <div onClick={async () => {
await props.analysisModule.call('editor', 'discardHighlight') await props.analysisModule.call('editor', 'discardHighlight')
@ -389,25 +389,36 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
<span className="text-wrap">{hint.formattedMessage}</span> <span className="text-wrap">{hint.formattedMessage}</span>
<span>{hint.type}</span><br /> <span>{hint.type}</span><br />
<span>{`${hint.column}:${hint.line}`}</span> <span>{`${hint.column}:${hint.line}`}</span>
</div> </div>
</div> </div>)) : hintErrors.map((hint, index) => (<div key={index} className='alert alert-danger'>
</Fragment> <div onClick={async () => {
)).sort((a, b) => { await props.analysisModule.call('editor', 'discardHighlight')
if(a.type === 'warning' && b.type === 'error') return 1 await props.analysisModule.call('editor', 'highlight', {
if(a.type === 'error' && b.type === 'warning') return -1 end: {
return 0 line: hint.line, column: hint.column+1
}) },
} start: {
line: hint.line, column: hint.column
}
}, state.file, '', { focus: true })
}}>
<span className="text-wrap">{hint.formattedMessage}</span>
<span>{hint.type}</span><br />
<span>{`${hint.column}:${hint.line}`}</span>
</div>
</div>))
}
</Fragment>
</div> </div>
</div> </div>
} }
</> </>
), ),
title: <span className="rounded-circle">Linter{hints.length > 0 ? <i className="badge badge-info rounded-circle ml-2">{hints.length}</i> : null}</span> title: <span className="rounded-circle">Linter{hints.length > 0 ? hideWarnings ? <i className="badge badge-danger rounded-circle ml-2">{hintErrors.length}</i> : <i className="badge badge-warning rounded-circle ml-2">{hints.length}</i> : null}</span>
}, },
{ {
tabKey: 'basic', tabKey: 'basic',
title: <BasicTitle warningStateEntries={Object.entries(warningState)}/>, title: <BasicTitle warningStateEntries={Object.entries(warningState)} hideWarnings={hideWarnings} />,
child: <> child: <>
{Object.entries(warningState).length > 0 && {Object.entries(warningState).length > 0 &&
<div id='staticanalysisresult' > <div id='staticanalysisresult' >
@ -415,9 +426,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
{ {
(Object.entries(warningState).map((element, index) => ( (Object.entries(warningState).map((element, index) => (
<div key={index}> <div key={index}>
{/* {element[1]['length'] > 0 ? <span className="text-dark h6">{element[0]}</span> : null} */}
{element[1]['map']((x, i) => ( // eslint-disable-line dot-notation {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
<div data-id={`staticAnalysisModule${x.warningModuleName}${i}`} id={`staticAnalysisModule${x.warningModuleName}${i}`} key={i}> <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}/> <ErrorRenderer name={`staticAnalysisModule${x.warningModuleName}${i}`} message={x.msg} opt={x.options} warningErrors={ x.warningErrors} editor={props.analysisModule}/>
</div> </div>
@ -438,7 +448,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
child: <div></div>, child: <div></div>,
} }
] ]
const t = Object.entries(warningState)
const checkBasicStatus = () => { const checkBasicStatus = () => {
return Object.values(groupedModules).map((value: any) => { return Object.values(groupedModules).map((value: any) => {
return (value.map(x => { return (value.map(x => {
@ -491,8 +501,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
buttonText="Analyse" buttonText="Analyse"
title={runButtonTitle} title={runButtonTitle}
classList="btn btn-sm btn-primary btn-block" 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, onClick={async () => await run(state.data, state.source, state.file, state , props, isSupportedVersion, slitherEnabled, categoryIndex, groupedModules, runner,_paq,
message, showWarnings, allWarnings, warningContainer)} message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints)}
disabled={(state.data === null || categoryIndex.length === 0) && !slitherEnabled || !isSupportedVersion } disabled={(state.data === null || categoryIndex.length === 0) && !slitherEnabled || !isSupportedVersion }
/> />
<div className="mt-4 p-2 d-flex border-top flex-column"> <div className="mt-4 p-2 d-flex border-top flex-column">

Loading…
Cancel
Save