fixing solhint no analysis for solhint

pull/3838/head
Joseph Izang 1 year ago
parent 84f4369c02
commit a92411bc6b
  1. 129
      libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts
  2. 104
      libs/remix-ui/static-analyser/src/lib/remix-ui-static-analyser.tsx

@ -23,7 +23,7 @@ export const compilation = (analysisModule: AnalysisTab,
}
}
export const runLinting = async (solhintEnabled, setHints, hints: SolHintReport[], warningResult, isSupportedVersion, state: RemixUiStaticAnalyserState,
export const runLinting = async (solhintEnabled, setHints, hints: SolHintReport[], isSupportedVersion, state: RemixUiStaticAnalyserState,
props: RemixUiStaticAnalyserProps, setStartAnalysis: React.Dispatch<React.SetStateAction<boolean>>) => {
// Run solhint
setStartAnalysis(true)
@ -31,13 +31,11 @@ export const runLinting = async (solhintEnabled, setHints, hints: SolHintReport[
if (!isSupportedVersion) return
if (solhintEnabled === false) return
if (state.data !== null) {
if (solhintEnabled) {
props.analysisModule.hints = []
setHints([])
const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file)
props.analysisModule.hints = solhintEnabled === false ? 0 : hintsResult
setHints(hintsResult)
return hintsResult
}
}
}
@ -70,7 +68,7 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<b
props.analysisModule.hints = []
if (!isSupportedVersion) return
if (state.data !== null) {
if (lastCompilationResult && (categoryIndex.length > 0 || showSlither)) {
if (lastCompilationResult && (categoryIndex.length > 0)) {
_paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'remixAnalyzer'])
const warningMessage = []
const warningErrors = []
@ -79,76 +77,71 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<b
// const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file)
// props.analysisModule.hints = solhintEnabled === false ? 0 : hintsResult
// setHints(hintsResult)
const warningResult = calculateWarningStateEntries(Object.entries(warningState))
const lintResult = await (await runLinting(solhintEnabled, setHints, hints, isSupportedVersion, state, props, setStartAnalysis))
// props.analysisModule.emit('statusChanged', { key: hints.length+warningResult.length,
// title: `${hints.length+warningResult.length} warning${hints.length+warningResult.length === 1 ? '' : 's'}`, type: 'warning'})
const lintResult = runLinting(solhintEnabled, setHints, hints, warningResult, isSupportedVersion, state, props, setStartAnalysis)
//---------------------------- RunLinting End ----------------------------
// Remix Analysis
const results = runner.run(lastCompilationResult, categoryIndex)
for (const result of results) {
let moduleName
Object.keys(groupedModules).map(key => {
groupedModules[key].forEach(el => {
if (el.name === result.name) {
moduleName = groupedModules[key][0].categoryDisplayName
}
const results = runner.run(lastCompilationResult, categoryIndex)
for (const result of results) {
let moduleName
Object.keys(groupedModules).map(key => {
groupedModules[key].forEach(el => {
if (el.name === result.name) {
moduleName = groupedModules[key][0].categoryDisplayName
}
})
})
})
// iterate over the warnings and create an object
for (const item of result.report) {
let location: any = {}
let locationString = 'not available'
let column = 0
let row = 0
let fileName = currentFile
let isLibrary = false
// iterate over the warnings and create an object
for (const item of result.report) {
let location: any = {}
let locationString = 'not available'
let column = 0
let row = 0
let fileName = currentFile
let isLibrary = false
if (item.location) {
const split = item.location.split(':')
const file = split[2]
location = {
start: parseInt(split[0]),
length: parseInt(split[1])
if (item.location) {
const split = item.location.split(':')
const file = split[2]
location = {
start: parseInt(split[0]),
length: parseInt(split[1])
}
location = props.analysisModule._deps.offsetToLineColumnConverter.offsetToLineColumn(
location,
parseInt(file),
lastCompilationSource.sources,
lastCompilationResult.sources
)
row = location.start.line
column = location.start.column
locationString = row + 1 + ':' + column + ':'
fileName = Object.keys(lastCompilationResult.sources)[file]
}
location = props.analysisModule._deps.offsetToLineColumnConverter.offsetToLineColumn(
location,
parseInt(file),
lastCompilationSource.sources,
lastCompilationResult.sources
)
row = location.start.line
column = location.start.column
locationString = row + 1 + ':' + column + ':'
fileName = Object.keys(lastCompilationResult.sources)[file]
}
if(fileName !== currentFile) {
const {file, provider} = await props.analysisModule.call('fileManager', 'getPathFromUrl', fileName)
if (file.startsWith('.deps') || (provider.type === 'localhost' && file.startsWith('localhost/node_modules'))) isLibrary = true
}
const msg = message(result.name, item.warning, item.more, fileName, locationString)
const options = {
type: 'warning',
useSpan: true,
errFile: fileName,
fileName,
isLibrary,
errLine: row,
errCol: column,
item: item,
name: result.name,
locationString,
more: item.more,
location: location
}
warningErrors.push(options)
warningMessage.push({ msg, options, hasWarning: true, warningModuleName: moduleName })
const newHints = await lintResult
setHints(newHints)
setSsaWarnings(warningMessage)
if (fileName !== currentFile) {
const { file, provider } = await props.analysisModule.call('fileManager', 'getPathFromUrl', fileName)
if (file.startsWith('.deps') || (provider.type === 'localhost' && file.startsWith('localhost/node_modules'))) isLibrary = true
}
const msg = message(result.name, item.warning, item.more, fileName, locationString)
const options = {
type: 'warning',
useSpan: true,
errFile: fileName,
fileName,
isLibrary,
errLine: row,
errCol: column,
item: item,
name: result.name,
locationString,
more: item.more,
location: location
}
warningErrors.push(options)
warningMessage.push({ msg, options, hasWarning: true, warningModuleName: moduleName })
setSsaWarnings(warningMessage)
// setHints(lintResult)
}
}
} else {

@ -191,7 +191,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
return () => { }
}, [props])
const hintErrors = hints.filter(hint => hint.type === 'error')
const hintErrors = hints && hints.filter(hint => hint.type === 'error')
const noLibSlitherWarnings = slitherWarnings.filter(w => !w.options.isLibrary)
const slitherErrors = noLibSlitherWarnings.filter(slitherError => slitherError.options.type === 'error')
const remixAnalysisNoLibs = ssaWarnings.filter(ssa => ssa.options.isLibrary === false)
@ -246,14 +246,14 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
}
if (solhintEnabled && !basicEnabled && !slitherEnabled && state.data && state.source !== null) {
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', [hideWarnings ? hintErrors.length : hints.length])
props.event.trigger('staticAnaysisWarning', [hideWarnings ? hintErrors.length : hints?.length])
}
if (solhintEnabled && basicEnabled && !slitherEnabled && !showLibsWarning
&& state.data && state.source !== null) {
console.log('solhint and remix are enabled here')
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', [hideWarnings
? hintErrors.length + remixAnalysisNoLibs.filter(x => x.options.type !== 'warning').length : hints.length + ssaWarnings.length])
? hintErrors.length + remixAnalysisNoLibs.filter(x => x.options.type !== 'warning').length : hints?.length + ssaWarnings.length])
}
if (slitherEnabled && !basicEnabled && !solhintEnabled && state.data && state.source !== null) {
props.analysisModule.internalCount = 0
@ -263,7 +263,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', [hideWarnings
? hintErrors.length + remixAnalysisLessWarnings.length + slitherErrors.length
: hints.length + ssaWarnings.length + slitherWarnings.length])
: hints?.length + ssaWarnings.length + slitherWarnings.length])
}
// if showLibsWarning is true
if(basicEnabled && !solhintEnabled && !slitherEnabled && !hideWarnings && state.data && state.source !== null ) {
@ -273,13 +273,13 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
}
if (solhintEnabled && !basicEnabled && !slitherEnabled && !hideWarnings && state.data && state.source !== null) {
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', [showLibsWarning ? hints.length : hints.length])
props.event.trigger('staticAnaysisWarning', [showLibsWarning ? hints?.length : hints?.length])
}
if (solhintEnabled && basicEnabled && !slitherEnabled && !hideWarnings && state.data && state.source !== null) {
console.log('solhint and remix are enabled here')
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', [showLibsWarning
? hints.length + ssaWarnings.length : hints.length + remixAnalysisNoLibs.length])
? hints?.length + ssaWarnings.length : hints?.length + remixAnalysisNoLibs.length])
}
if (slitherEnabled && !basicEnabled && !solhintEnabled && !hideWarnings && state.data && state.source !== null) {
props.analysisModule.internalCount = 0
@ -288,42 +288,23 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
if (slitherEnabled && basicEnabled && solhintEnabled && !hideWarnings && state.data && state.source !== null) {
props.analysisModule.internalCount = 0
props.event.trigger('staticAnaysisWarning', [showLibsWarning
? hints.length + ssaWarnings.length + slitherWarnings.length : hints.length + remixAnalysisNoLibs.length + noLibSlitherWarnings.length])
}
if(solhintEnabled && basicEnabled && !slitherEnabled && !hideWarnings && !showLibsWarning) {
props.analysisModule.internalCount = 0
if(props.analysisModule.hints.length > 0) {
props.event.trigger('staticAnaysisWarning', [hints.length + remixAnalysisNoLibs.length])
}
}
if(solhintEnabled && !basicEnabled && !slitherEnabled && hideWarnings && showLibsWarning) {
props.analysisModule.internalCount = 0
if(remixAnalysisLessWarnings.length > 0) {
props.event.trigger('staticAnaysisWarning', [hints.length])
}
? hints?.length + ssaWarnings.length + slitherWarnings.length : hints?.length + remixAnalysisNoLibs.length + noLibSlitherWarnings.length])
}
if(basicEnabled && solhintEnabled && !slitherEnabled && !hideWarnings && !showLibsWarning) {
props.analysisModule.internalCount = 0
if(props.analysisModule.hints.length > 0) {
props.event.trigger('staticAnaysisWarning', [hints.length + remixAnalysisNoLibs.length])
}
props.event.trigger('staticAnaysisWarning', [hints?.length + remixAnalysisNoLibs.length])
}
if(solhintEnabled && basicEnabled && slitherEnabled && !hideWarnings && !showLibsWarning) {
props.analysisModule.internalCount = 0
if(props.analysisModule.hints.length > 0) {
props.analysisModule.hints = []
props.event.trigger('staticAnaysisWarning', [hints.length + remixAnalysisNoLibs.length + slitherWarnings.length])
}
props.analysisModule.hints = []
props.event.trigger('staticAnaysisWarning', [hints?.length + remixAnalysisNoLibs.length + slitherWarnings.length])
}
if(solhintEnabled && basicEnabled && !slitherEnabled && hideWarnings && showLibsWarning) {
props.analysisModule.internalCount = 0
if(remixAnalysisLessWarnings.length > 0) {
props.event.trigger('staticAnaysisWarning', [hintErrors.length + remixAnalysisNoLibs
.filter(x => x.options.type === 'warning').length])
}
props.event.trigger('staticAnaysisWarning', [hintErrors.length + remixAnalysisLessWarnings.length])
}
}, [ssaWarnings.length, hints.length, hideWarnings, showLibsWarning, state])
}, [ssaWarnings.length, hints?.length, hideWarnings, showLibsWarning, state])
useEffect(() => {
if(solhintEnabled === false) {
@ -491,12 +472,12 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
tabKey: "linter",
child: (
<>
{hints.length > 0 ? (
{solhintEnabled && hints?.length > 0 ? (
<div id="solhintlintingresult" className="mb-5">
<div className="mb-4 pt-2">
<Fragment>
{!hideWarnings
? hints.map((hint, index) => (
? hints?.map((hint, index) => (
<div
key={index}
className={`${
@ -579,22 +560,22 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
</Fragment>
</div>
</div>
) : state.data && state.file.length > 0 && state.source && startAnalysis && hints.length > 0 ? <span className="ml-4 spinner-grow-sm d-flex justify-content-center">Loading...</span> : <span className="display-6 text-center">Nothing to report</span>}
) : state.data && state.file.length > 0 && state.source && startAnalysis && hints?.length > 0 ? <span className="ml-4 spinner-grow-sm d-flex justify-content-center">Loading...</span> : <span className="display-6 text-center">Nothing to report</span>}
</>
),
title: (
<span>
Solhint
{hints.length > 0 ? (
{hints && hints?.length > 0 ? (
hideWarnings ? (
<i className={`badge ${hints.filter(x => x.type === 'error').length > 0
<i className={`badge ${hints?.filter(x => x.type === 'error').length > 0
? `badge-danger` : 'badge-warning'} badge-pill px-1 ml-1 text-center`}>
{hintErrors.length}
</i>
) : (
<i className={`badge ${hints.filter(x => x.type === 'error').length > 0
<i className={`badge ${hints?.filter(x => x.type === 'error').length > 0
? `badge-danger` : 'badge-warning'} badge-pill px-1 ml-1 text-center`}>
{hints.length}
{hints?.length}
</i>
)
) : null}
@ -630,18 +611,18 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
title: (
<span>
Slither
{slitherWarnings.length > 0 ? (
{slitherWarnings && slitherWarnings?.length > 0 ? (
hideWarnings ? (
<i className="badge badge-warning badge-pill px-1 ml-1">
{slitherErrors.length}
{slitherErrors?.length}
</i>
) : showLibsWarning === true && hideWarnings === false ? (
<i className={`badge ${slitherErrors.length > 0 ? `badge-danger` : 'badge-warning'} badge-pill px-1 ml-1 text-center`}>
{slitherWarnings.length}
</i>
) : (
<i className={`badge ${slitherErrors.length > 0 ? `badge-danger` : 'badge-warning'} badge-pill px-1 ml-1 text-center`}>
{noLibSlitherWarnings.length}
<i className={`badge ${slitherErrors?.length > 0 ? `badge-danger` : 'badge-warning'} badge-pill px-1 ml-1 text-center`}>
{noLibSlitherWarnings?.length}
</i>
)
) : null}
@ -649,12 +630,12 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
),
child: (
<>
{slitherWarnings.length > 0 ? (
{slitherWarnings?.length > 0 ? (
<div id="solhintlintingresult" className="mb-5">
<div className="mb-4 pt-2">
<Fragment>
{!hideWarnings
? showLibsWarning ? slitherWarnings.map((warning, index) => (
? showLibsWarning ? slitherWarnings && slitherWarnings?.map((warning, index) => (
<div
data-id={`staticAnalysisModule${warning.warningModuleName}${index}`}
id={`staticAnalysisModule${warning.warningModuleName}${index}`}
@ -766,11 +747,16 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
buttonText={`Analyse ${state.file}`}
classList="btn btn-sm btn-primary btn-block"
onClick={async () => {
await run(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq,
message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis, solhintEnabled, basicEnabled)
await runSlitherAnalysis(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq,
message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis)
await runLinting(solhintEnabled, setHints, hints, isSupportedVersion, state, props, setStartAnalysis)
if(basicEnabled) {
await run(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq,
message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis, solhintEnabled, basicEnabled)
}
if(slitherEnabled) {
await runSlitherAnalysis(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq,
message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis)
}
}
}
disabled={(state.data === null || !isSupportedVersion || !solhintEnabled && !basicEnabled) }
@ -778,13 +764,23 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
buttonText={`Analyze ${state.file}`}
title={`${runButtonTitle}`}
classList="btn btn-sm btn-primary btn-block"
onClick={async () => await run(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq,
message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis, solhintEnabled, basicEnabled)}
onClick={async () => {
await runLinting(solhintEnabled, setHints, hints, isSupportedVersion, state, props, setStartAnalysis)
if(basicEnabled) {
await run(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq,
message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis, solhintEnabled, basicEnabled)
}
if(slitherEnabled) {
await runSlitherAnalysis(state.data, state.source, state.file, state , props, isSupportedVersion, showSlither, categoryIndex, groupedModules, runner,_paq,
message, showWarnings, allWarnings, warningContainer, calculateWarningStateEntries, warningState, setHints, hints, setSlitherWarnings, setSsaWarnings, slitherEnabled, setStartAnalysis)
}
}}
disabled={(state.data === null || !isSupportedVersion) || (!solhintEnabled && !basicEnabled) }
/>}
{state && state.data !== null && state.source !== null && state.file.length > 0 ? (<div className="d-flex border-top flex-column">
{slitherWarnings.length > 0 || hints.length > 0 || Object.entries(warningState).length > 0 ? (
<div className={`mt-4 p-2 d-flex ${slitherWarnings.length > 0 || hints.length > 0 || Object.entries(warningState).length > 0 ? 'border-top' : ''} flex-column`}>
{slitherWarnings?.length > 0 || hints?.length > 0 || Object.entries(warningState).length > 0 ? (
<div className={`mt-4 p-2 d-flex ${slitherWarnings?.length > 0 || hints?.length > 0 || Object.entries(warningState).length > 0 ? 'border-top' : ''} flex-column`}>
<span>Last results for:</span>
<span
className="text-break break-word word-break font-weight-bold"
@ -822,7 +818,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => {
onSelect={(newKey) => setTabKey(newKey)}
>
{
checkBasicStatus() ? <Tab
basicEnabled ? <Tab
key={tabKeys[1].tabKey}
title={tabKeys[1].title}
eventKey={tabKeys[1].tabKey}

Loading…
Cancel
Save