|
|
|
@ -14,6 +14,8 @@ import Tab from 'react-bootstrap/Tab' |
|
|
|
|
import Tabs from 'react-bootstrap/Tabs' |
|
|
|
|
import { Fade } from 'react-bootstrap' |
|
|
|
|
import { AnalysisTab } from '../staticanalyser' |
|
|
|
|
import { run } from './actions/staticAnalysisActions' |
|
|
|
|
import SolHintTabChild from './components/SolHintTabChild' |
|
|
|
|
|
|
|
|
|
declare global { |
|
|
|
|
interface Window { |
|
|
|
@ -66,8 +68,9 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
} |
|
|
|
|
return indexOfCategory |
|
|
|
|
} |
|
|
|
|
const [autoRun, setAutoRun] = useState(true) |
|
|
|
|
const [basicEnabled, setBasicEnabled] = useState(true) |
|
|
|
|
const [slitherEnabled, setSlitherEnabled] = useState(false) |
|
|
|
|
const [solhintEnabled, setSolhintEnabled] = useState(true) // assuming that solhint is always enabled
|
|
|
|
|
const [showSlither, setShowSlither] = useState(false) |
|
|
|
|
const [isSupportedVersion, setIsSupportedVersion] = useState(false) |
|
|
|
|
let [showLibsWarning, setShowLibsWarning] = useState(false) // eslint-disable-line prefer-const
|
|
|
|
@ -106,9 +109,10 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
useEffect(() => { |
|
|
|
|
setWarningState({}) |
|
|
|
|
const runAnalysis = async () => { |
|
|
|
|
await run(state.data, state.source, state.file) |
|
|
|
|
await run(state.data, state.source, state.file, allWarnings, props, isSupportedVersion, slitherEnabled, categoryIndex, groupedModules, runner,_paq, |
|
|
|
|
message, showWarnings, allWarnings, warningContainer) |
|
|
|
|
} |
|
|
|
|
if (autoRun) { |
|
|
|
|
if (basicEnabled) { |
|
|
|
|
if (state.data !== null) { |
|
|
|
|
runAnalysis().catch(console.error); |
|
|
|
|
} |
|
|
|
@ -217,159 +221,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
filterWarnings() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const run = async (lastCompilationResult, lastCompilationSource, currentFile) => { |
|
|
|
|
console.log({ state, lastCompilationResult, lastCompilationSource, currentFile }) |
|
|
|
|
if (!isSupportedVersion) return |
|
|
|
|
if (state.data !== null) { |
|
|
|
|
if (lastCompilationResult && (categoryIndex.length > 0 || slitherEnabled)) { |
|
|
|
|
const warningMessage = [] |
|
|
|
|
const warningErrors = [] |
|
|
|
|
|
|
|
|
|
const hints = await props.analysisModule.call('solhint', 'lint', currentFile) |
|
|
|
|
console.log({ hints }) |
|
|
|
|
|
|
|
|
|
// Remix Analysis
|
|
|
|
|
_paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'remixAnalyzer']) |
|
|
|
|
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 |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
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]) |
|
|
|
|
} |
|
|
|
|
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 }) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// Slither Analysis
|
|
|
|
|
if (slitherEnabled) { |
|
|
|
|
try { |
|
|
|
|
const compilerState = await props.analysisModule.call('solidity', 'getCompilerState') |
|
|
|
|
const { currentVersion, optimize, evmVersion } = compilerState |
|
|
|
|
await props.analysisModule.call('terminal', 'log', { type: 'log', value: '[Slither Analysis]: Running...' }) |
|
|
|
|
_paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'slitherAnalyzer']) |
|
|
|
|
const result = await props.analysisModule.call('slither', 'analyse', state.file, { currentVersion, optimize, evmVersion }) |
|
|
|
|
if (result.status) { |
|
|
|
|
props.analysisModule.call('terminal', 'log', { type: 'log', value: `[Slither Analysis]: Analysis Completed!! ${result.count} warnings found.` }) |
|
|
|
|
const report = result.data |
|
|
|
|
for (const item of report) { |
|
|
|
|
let location: any = {} |
|
|
|
|
let locationString = 'not available' |
|
|
|
|
let column = 0 |
|
|
|
|
let row = 0 |
|
|
|
|
let fileName = currentFile |
|
|
|
|
let isLibrary = false |
|
|
|
|
|
|
|
|
|
if (item.sourceMap && item.sourceMap.length) { |
|
|
|
|
let path = item.sourceMap[0].source_mapping.filename_relative |
|
|
|
|
let fileIndex = Object.keys(lastCompilationResult.sources).indexOf(path) |
|
|
|
|
if (fileIndex === -1) { |
|
|
|
|
path = await props.analysisModule.call('fileManager', 'getUrlFromPath', path) |
|
|
|
|
fileIndex = Object.keys(lastCompilationResult.sources).indexOf(path.file) |
|
|
|
|
} |
|
|
|
|
if (fileIndex >= 0) { |
|
|
|
|
location = { |
|
|
|
|
start: item.sourceMap[0].source_mapping.start, |
|
|
|
|
length: item.sourceMap[0].source_mapping.length |
|
|
|
|
} |
|
|
|
|
location = props.analysisModule._deps.offsetToLineColumnConverter.offsetToLineColumn( |
|
|
|
|
location, |
|
|
|
|
fileIndex, |
|
|
|
|
lastCompilationSource.sources, |
|
|
|
|
lastCompilationResult.sources |
|
|
|
|
) |
|
|
|
|
row = location.start.line |
|
|
|
|
column = location.start.column |
|
|
|
|
locationString = row + 1 + ':' + column + ':' |
|
|
|
|
fileName = Object.keys(lastCompilationResult.sources)[fileIndex] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
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(item.title, item.description, item.more, fileName, locationString) |
|
|
|
|
const options = { |
|
|
|
|
type: 'warning', |
|
|
|
|
useSpan: true, |
|
|
|
|
errFile: fileName, |
|
|
|
|
fileName, |
|
|
|
|
isLibrary, |
|
|
|
|
errLine: row, |
|
|
|
|
errCol: column, |
|
|
|
|
item: { warning: item.description }, |
|
|
|
|
name: item.title, |
|
|
|
|
locationString, |
|
|
|
|
more: item.more, |
|
|
|
|
location: location |
|
|
|
|
} |
|
|
|
|
warningErrors.push(options) |
|
|
|
|
warningMessage.push({ msg, options, hasWarning: true, warningModuleName: 'Slither Analysis' }) |
|
|
|
|
} |
|
|
|
|
showWarnings(warningMessage, 'warningModuleName') |
|
|
|
|
} |
|
|
|
|
} catch(error) { |
|
|
|
|
props.analysisModule.call('terminal', 'log', { type: 'error', value: '[Slither Analysis]: Error occured! See remixd console for details.' }) |
|
|
|
|
showWarnings(warningMessage, 'warningModuleName') |
|
|
|
|
} |
|
|
|
|
} else showWarnings(warningMessage, 'warningModuleName') |
|
|
|
|
} else { |
|
|
|
|
if (categoryIndex.length) { |
|
|
|
|
warningContainer.current.innerText = 'No compiled AST available' |
|
|
|
|
} |
|
|
|
|
props.event.trigger('staticAnaysisWarning', [-1]) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleCheckAllModules = (groupedModules) => { |
|
|
|
|
const index = groupedModuleIndex(groupedModules) |
|
|
|
|
if (index.every(el => categoryIndex.includes(el))) { |
|
|
|
@ -404,11 +256,11 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleAutoRun = () => { |
|
|
|
|
if (autoRun) { |
|
|
|
|
setAutoRun(false) |
|
|
|
|
const handleBasicEnabled = () => { |
|
|
|
|
if (basicEnabled) { |
|
|
|
|
setBasicEnabled(false) |
|
|
|
|
} else { |
|
|
|
|
setAutoRun(true) |
|
|
|
|
setBasicEnabled(true) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -488,16 +340,6 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
console.log('logging hints from solhint in useEffect') |
|
|
|
|
props.analysisModule.on('solhint' as any, 'lintOnCompilationFinished', |
|
|
|
|
(hints: any) => { |
|
|
|
|
|
|
|
|
|
console.log({ hints }) |
|
|
|
|
}) |
|
|
|
|
return () => props.analysisModule.off('solhint' as any, 'lintOnCompilationFinished') |
|
|
|
|
}, []) |
|
|
|
|
|
|
|
|
|
const handleShowLinterMessages = () => { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
@ -509,42 +351,33 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
const tabKeys = [ |
|
|
|
|
{ |
|
|
|
|
tabKey: 'linter', |
|
|
|
|
child: <div></div>, |
|
|
|
|
child: <SolHintTabChild analysisModule={props.analysisModule} currentFile={state.file} />, |
|
|
|
|
title: 'Linter' |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
tabKey: 'basic', |
|
|
|
|
title: 'Basic', |
|
|
|
|
child: <> |
|
|
|
|
<div id="staticanalysismodules" className="list-group list-group-flush"> |
|
|
|
|
{Object.keys(groupedModules).map((categoryId, i) => { |
|
|
|
|
const category = groupedModules[categoryId] |
|
|
|
|
return ( |
|
|
|
|
categorySection(category, categoryId, i) |
|
|
|
|
) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
</div> |
|
|
|
|
{Object.entries(warningState).length > 0 && |
|
|
|
|
<div id='staticanalysisresult' > |
|
|
|
|
<div className="mb-4"> |
|
|
|
|
{ |
|
|
|
|
(Object.entries(warningState).map((element, 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
|
|
|
|
|
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> |
|
|
|
|
</div> |
|
|
|
|
} |
|
|
|
|
{Object.entries(warningState).length > 0 && |
|
|
|
|
<div id='staticanalysisresult' > |
|
|
|
|
<div className="mb-4"> |
|
|
|
|
{ |
|
|
|
|
(Object.entries(warningState).map((element, 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
|
|
|
|
|
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> |
|
|
|
|
</div> |
|
|
|
|
} |
|
|
|
|
</> |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
@ -564,10 +397,10 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
inputType="checkbox" |
|
|
|
|
title="Run solhint static analysis on file save" |
|
|
|
|
onClick={handleShowLinterMessages} |
|
|
|
|
checked={autoRun} |
|
|
|
|
checked={solhintEnabled} |
|
|
|
|
label="Linter" |
|
|
|
|
onChange={() => {}} |
|
|
|
|
tooltipPlacement={'bottom-start'} |
|
|
|
|
tooltipPlacement={'top-start'} |
|
|
|
|
/> |
|
|
|
|
<RemixUiCheckbox |
|
|
|
|
id="checkAllEntries" |
|
|
|
@ -597,7 +430,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)} |
|
|
|
|
onClick={async () => await run(state.data, state.source, state.file, allWarnings, props, isSupportedVersion, slitherEnabled, categoryIndex, groupedModules, runner,_paq, |
|
|
|
|
message, showWarnings, allWarnings, warningContainer)} |
|
|
|
|
disabled={(state.data === null || categoryIndex.length === 0) && !slitherEnabled || !isSupportedVersion } |
|
|
|
|
/> |
|
|
|
|
<div className="mt-4 p-2 d-flex border-top flex-column"> |
|
|
|
|