|
|
@ -1,10 +1,11 @@ |
|
|
|
import React, { useEffect, useState } from 'react'
|
|
|
|
import React, { useEffect, useState } from 'react' |
|
|
|
import ReactDOM from 'react-dom' //eslint-disable-line
|
|
|
|
import ReactDOM from 'react-dom' //eslint-disable-line
|
|
|
|
import CheckBox from './Checkbox/StaticAnalyserCheckedBox' // eslint-disable-line
|
|
|
|
import CheckBox from './Checkbox/StaticAnalyserCheckedBox' // eslint-disable-line
|
|
|
|
import Button from './Button/StaticAnalyserButton' // eslint-disable-line
|
|
|
|
import Button from './Button/StaticAnalyserButton' // eslint-disable-line
|
|
|
|
import remixLib from '@remix-project/remix-lib' |
|
|
|
import remixLib from '@remix-project/remix-lib' |
|
|
|
import _ from 'lodash' |
|
|
|
import _ from 'lodash' |
|
|
|
import { TreeView, TreeViewItem } from '@remix-ui/tree-view' // eslint-disable-line
|
|
|
|
import { TreeView, TreeViewItem } from '@remix-ui/tree-view' // eslint-disable-line
|
|
|
|
|
|
|
|
import { RemixUiCheckbox } from '@remix-ui/checkbox' // eslint-disable-line
|
|
|
|
import ErrorRenderer from './ErrorRenderer' // eslint-disable-line
|
|
|
|
import ErrorRenderer from './ErrorRenderer' // eslint-disable-line
|
|
|
|
const StaticAnalysisRunner = require('@remix-project/remix-analyzer').CodeAnalysis |
|
|
|
const StaticAnalysisRunner = require('@remix-project/remix-analyzer').CodeAnalysis |
|
|
|
const utils = remixLib.util |
|
|
|
const utils = remixLib.util |
|
|
@ -60,12 +61,12 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
} |
|
|
|
} |
|
|
|
return indexOfCategory |
|
|
|
return indexOfCategory |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const [autoRun, setAutoRun] = useState(true) |
|
|
|
const [categoryIndex, setCategoryIndex] = useState(groupedModuleIndex(groupedModules)) |
|
|
|
const [categoryIndex, setCategoryIndex] = useState(groupedModuleIndex(groupedModules)) |
|
|
|
|
|
|
|
|
|
|
|
const warningContainer = React.useRef(null) |
|
|
|
const warningContainer = React.useRef(null) |
|
|
|
const [runButtonState, setRunButtonState] = useState(true) |
|
|
|
const [runButtonState, setRunButtonState] = useState(true) |
|
|
|
const [autoRun, setAutoRun] = useState(false) |
|
|
|
|
|
|
|
const [result, setResult] = useState({ |
|
|
|
const [result, setResult] = useState({ |
|
|
|
lastCompilationResult: null, |
|
|
|
lastCompilationResult: null, |
|
|
|
lastCompilationSource: null, |
|
|
|
lastCompilationSource: null, |
|
|
@ -81,136 +82,129 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
const [warningState, setWarningState] = useState([]) |
|
|
|
const [warningState, setWarningState] = useState([]) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
|
|
|
|
if (autoRun) { |
|
|
|
if (autoRun) { |
|
|
|
const setCompilationResult = async (data, source, file) => { |
|
|
|
const setCompilationResult = async (data, source, file) => { |
|
|
|
await setResult({ lastCompilationResult: data, lastCompilationSource: source, currentFile: file }) |
|
|
|
await setResult({ lastCompilationResult: data, lastCompilationSource: source, currentFile: file }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (props.analysisModule) { |
|
|
|
if (props.analysisModule) { |
|
|
|
|
|
|
|
|
|
|
|
props.analysisModule.on( |
|
|
|
props.analysisModule.on( |
|
|
|
'solidity', |
|
|
|
'solidity', |
|
|
|
'compilationFinished', |
|
|
|
'compilationFinished', |
|
|
|
(file, source, languageVersion, data) => { |
|
|
|
(file, source, languageVersion, data) => { |
|
|
|
if (languageVersion.indexOf('soljson') !== 0) return |
|
|
|
if (languageVersion.indexOf('soljson') !== 0) return |
|
|
|
setCompilationResult(data, source, file) |
|
|
|
setCompilationResult(data, source, file) |
|
|
|
if(categoryIndex.length > 0){ |
|
|
|
if (categoryIndex.length > 0) { |
|
|
|
run(data, source, file) |
|
|
|
run(data, source, file) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
setAutoRun(true) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return () => { } |
|
|
|
return () => { } |
|
|
|
}, [autoRun, categoryIndex]) |
|
|
|
}, [autoRun, categoryIndex]) |
|
|
|
|
|
|
|
|
|
|
|
const run = (lastCompilationResult, lastCompilationSource, currentFile) => { |
|
|
|
const run = (lastCompilationResult, lastCompilationSource, currentFile) => { |
|
|
|
// const highlightLocation = async (location, fileName) => {
|
|
|
|
if (autoRun) { |
|
|
|
// await props.analysisModule.call('editor', 'discardHighlight')
|
|
|
|
setResult({ lastCompilationResult, lastCompilationSource, currentFile }) |
|
|
|
// await props.analysisModule.call('editor', 'highlight', location, fileName)
|
|
|
|
if (lastCompilationResult && categoryIndex.length > 0) { |
|
|
|
// }
|
|
|
|
setRunButtonState(false) |
|
|
|
setResult({ lastCompilationResult, lastCompilationSource, currentFile }) |
|
|
|
let warningCount = 0 |
|
|
|
if (lastCompilationResult && categoryIndex.length) { |
|
|
|
const warningMessage = [] |
|
|
|
setRunButtonState(false) |
|
|
|
|
|
|
|
let warningCount = 0 |
|
|
|
|
|
|
|
const warningMessage = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
runner.run(lastCompilationResult, categoryIndex, results => { |
|
|
|
runner.run(lastCompilationResult, categoryIndex, results => { |
|
|
|
results.map((result) => { |
|
|
|
results.map((result) => { |
|
|
|
let moduleName
|
|
|
|
let moduleName
|
|
|
|
Object.keys(groupedModules).map(key => { |
|
|
|
Object.keys(groupedModules).map(key => { |
|
|
|
groupedModules[key].forEach(el => { |
|
|
|
groupedModules[key].forEach(el => { |
|
|
|
if (el.name === result.name) { |
|
|
|
if (el.name === result.name) { |
|
|
|
moduleName = groupedModules[key][0].categoryDisplayName |
|
|
|
moduleName = groupedModules[key][0].categoryDisplayName |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
setModuleNameResult(moduleName) |
|
|
|
setModuleNameResult(moduleName) |
|
|
|
const warningErrors = [] |
|
|
|
const warningErrors = [] |
|
|
|
result.report.map((item) => { |
|
|
|
result.report.map((item) => { |
|
|
|
let location: any = {} |
|
|
|
let location: any = {} |
|
|
|
let locationString = 'not available' |
|
|
|
let locationString = 'not available' |
|
|
|
let column = 0 |
|
|
|
let column = 0 |
|
|
|
let row = 0 |
|
|
|
let row = 0 |
|
|
|
let fileName = currentFile |
|
|
|
let fileName = currentFile |
|
|
|
if (item.location) { |
|
|
|
if (item.location) { |
|
|
|
const split = item.location.split(':') |
|
|
|
var split = item.location.split(':') |
|
|
|
const file = split[2] |
|
|
|
var file = split[2] |
|
|
|
location = { |
|
|
|
location = { |
|
|
|
start: parseInt(split[0]), |
|
|
|
start: parseInt(split[0]), |
|
|
|
length: parseInt(split[1]) |
|
|
|
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.contracts)[file] |
|
|
|
} |
|
|
|
} |
|
|
|
location = props.analysisModule._deps.offsetToLineColumnConverter.offsetToLineColumn( |
|
|
|
warningCount++ |
|
|
|
location, |
|
|
|
const msg = ` |
|
|
|
parseInt(file), |
|
|
|
<span class='d-flex flex-column'> |
|
|
|
lastCompilationSource.sources, |
|
|
|
<span class='h6 font-weight-bold'>${result.name}</span> |
|
|
|
lastCompilationResult.sources |
|
|
|
${item.warning} |
|
|
|
) |
|
|
|
${item.more |
|
|
|
row = location.start.line |
|
|
|
? `<span><a href=${item.more} target='_blank'>more</a></span>` |
|
|
|
column = location.start.column |
|
|
|
: '<span> </span>' |
|
|
|
locationString = row + 1 + ':' + column + ':' |
|
|
|
} |
|
|
|
fileName = Object.keys(lastCompilationResult.contracts)[file] |
|
|
|
<span class="" title="Position in ${fileName}">Pos: ${locationString}</span> |
|
|
|
} |
|
|
|
</span>` |
|
|
|
warningCount++ |
|
|
|
const options = { |
|
|
|
const msg = ` |
|
|
|
type: 'warning', |
|
|
|
<span class='d-flex flex-column'> |
|
|
|
useSpan: true, |
|
|
|
<span class='h6 font-weight-bold'>${result.name}</span> |
|
|
|
errFile: fileName, |
|
|
|
${item.warning} |
|
|
|
errLine: row, |
|
|
|
${item.more |
|
|
|
errCol: column, |
|
|
|
? `<span><a href=${item.more} target='_blank'>more</a></span>` |
|
|
|
item: item, |
|
|
|
: '<span> </span>' |
|
|
|
name: result.name, |
|
|
|
|
|
|
|
locationString, |
|
|
|
|
|
|
|
more: item.more |
|
|
|
} |
|
|
|
} |
|
|
|
<span class="" title="Position in ${fileName}">Pos: ${locationString}</span> |
|
|
|
warningErrors.push(options) |
|
|
|
</span>` |
|
|
|
setWarning({ msg, hasWarning: true, options, warningErrors: warningErrors }) |
|
|
|
const options = { |
|
|
|
warningMessage.push({ msg, options, hasWarning: true, warningModuleName: moduleName }) |
|
|
|
type: 'warning', |
|
|
|
}) |
|
|
|
useSpan: true, |
|
|
|
|
|
|
|
errFile: fileName, |
|
|
|
|
|
|
|
errLine: row, |
|
|
|
|
|
|
|
errCol: column, |
|
|
|
|
|
|
|
item: item, |
|
|
|
|
|
|
|
name: result.name, |
|
|
|
|
|
|
|
locationString, |
|
|
|
|
|
|
|
more: item.more |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
warningErrors.push(options) |
|
|
|
|
|
|
|
setWarning({ msg, hasWarning: true, options, warningErrors: warningErrors }) |
|
|
|
|
|
|
|
warningMessage.push({ msg, options, hasWarning: true, warningModuleName: moduleName }) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
const resultArray = [] |
|
|
|
|
|
|
|
warningMessage.map(x => { |
|
|
|
|
|
|
|
resultArray.push(x) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
function groupBy (objectArray, property) { |
|
|
|
|
|
|
|
return objectArray.reduce((acc, obj) => { |
|
|
|
|
|
|
|
const key = obj[property] |
|
|
|
|
|
|
|
if (!acc[key]) { |
|
|
|
|
|
|
|
acc[key] = [] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Add object to list for given key's value
|
|
|
|
|
|
|
|
acc[key].push(obj) |
|
|
|
|
|
|
|
return acc |
|
|
|
|
|
|
|
}, {}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const groupedCategory = groupBy(resultArray, 'warningModuleName') |
|
|
|
|
|
|
|
setWarningState(groupedCategory) |
|
|
|
}) |
|
|
|
}) |
|
|
|
const resultArray = [] |
|
|
|
if (categoryIndex.length > 0) { |
|
|
|
warningMessage.map(x => { |
|
|
|
props.event.trigger('staticAnaysisWarning', [warningCount]) |
|
|
|
resultArray.push(x) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
function groupBy (objectArray, property) { |
|
|
|
|
|
|
|
return objectArray.reduce((acc, obj) => { |
|
|
|
|
|
|
|
const key = obj[property] |
|
|
|
|
|
|
|
if (!acc[key]) { |
|
|
|
|
|
|
|
acc[key] = [] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Add object to list for given key's value
|
|
|
|
|
|
|
|
acc[key].push(obj) |
|
|
|
|
|
|
|
return acc |
|
|
|
|
|
|
|
}, {}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
const groupedCategory = groupBy(resultArray, 'warningModuleName') |
|
|
|
setRunButtonState(true) |
|
|
|
setWarningState(groupedCategory) |
|
|
|
if (categoryIndex.length) { |
|
|
|
}) |
|
|
|
warningContainer.current.innerText = 'No compiled AST available' |
|
|
|
if(categoryIndex.length > 0){ |
|
|
|
} |
|
|
|
props.event.trigger('staticAnaysisWarning', [warningCount]) |
|
|
|
props.event.trigger('staticAnaysisWarning', [-1]) |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setRunButtonState(true) |
|
|
|
|
|
|
|
if (categoryIndex.length) { |
|
|
|
|
|
|
|
warningContainer.current.innerText = 'No compiled AST available' |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
props.event.trigger('staticAnaysisWarning', [-1]) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -223,9 +217,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
}) |
|
|
|
}) |
|
|
|
) |
|
|
|
) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
setCategoryIndex(_.uniq([...categoryIndex])) |
|
|
|
setCategoryIndex(_.uniq([...categoryIndex, ...index])) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const handleCheckOrUncheckCategory = (category) => { |
|
|
|
const handleCheckOrUncheckCategory = (category) => { |
|
|
@ -261,7 +254,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
const categoryItem = (categoryId, item, i) => { |
|
|
|
const categoryItem = (categoryId, item, i) => { |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className="form-check" key={i}> |
|
|
|
<div className="form-check" key={i}> |
|
|
|
<CheckBox |
|
|
|
<RemixUiCheckbox |
|
|
|
categoryId={categoryId} |
|
|
|
categoryId={categoryId} |
|
|
|
id={`staticanalysismodule_${categoryId}_${i}`} |
|
|
|
id={`staticanalysismodule_${categoryId}_${i}`} |
|
|
|
inputType="checkbox" |
|
|
|
inputType="checkbox" |
|
|
@ -285,7 +278,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
<label |
|
|
|
<label |
|
|
|
htmlFor={`heading${categoryId}`} |
|
|
|
htmlFor={`heading${categoryId}`} |
|
|
|
style={{ cursor: 'pointer' }} |
|
|
|
style={{ cursor: 'pointer' }} |
|
|
|
className="pl-3 card-header h6 d-flex justify-content-between font-weight-bold border-left px-1 py-2 w-100" |
|
|
|
className="pl-3 card-header h6 d-flex justify-content-between font-weight-bold px-1 py-2 w-100" |
|
|
|
data-bs-toggle="collapse" |
|
|
|
data-bs-toggle="collapse" |
|
|
|
data-bs-expanded="false" |
|
|
|
data-bs-expanded="false" |
|
|
|
data-bs-controls={`heading${categoryId}`} |
|
|
|
data-bs-controls={`heading${categoryId}`} |
|
|
@ -294,10 +287,10 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
{category[0].categoryDisplayName} |
|
|
|
{category[0].categoryDisplayName} |
|
|
|
</label> |
|
|
|
</label> |
|
|
|
} |
|
|
|
} |
|
|
|
expand={true} |
|
|
|
expand={false} |
|
|
|
> |
|
|
|
> |
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<CheckBox onClick={() => handleCheckOrUncheckCategory(category)} id={categoryId} inputType="checkbox" label={`Select ${category[0].categoryDisplayName}`} name='checkCategoryEntry' checked={category.map(x => x._index.toString()).every(el => categoryIndex.includes(el))} /> |
|
|
|
<RemixUiCheckbox onClick={() => handleCheckOrUncheckCategory(category)} id={categoryId} inputType="checkbox" label={`Select ${category[0].categoryDisplayName}`} name='checkCategoryEntry' checked={category.map(x => x._index.toString()).every(el => categoryIndex.includes(el))} /> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div className="w-100 d-block px-2 my-1 entries collapse multi-collapse" id={`heading${categoryId}`}> |
|
|
|
<div className="w-100 d-block px-2 my-1 entries collapse multi-collapse" id={`heading${categoryId}`}> |
|
|
|
{category.map((item, i) => { |
|
|
|
{category.map((item, i) => { |
|
|
@ -314,31 +307,27 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div style={{ marginLeft: '10px', marginRight: '10px' }}> |
|
|
|
<div className="analysis_3ECCBV px-3 pb-1"> |
|
|
|
<div className="my-2 d-flex flex-column align-items-left"> |
|
|
|
<div className="my-2 d-flex flex-column align-items-left"> |
|
|
|
<div className="d-flex justify-content-between"> |
|
|
|
<div className="d-flex justify-content-between"> |
|
|
|
<div > |
|
|
|
<RemixUiCheckbox |
|
|
|
<CheckBox |
|
|
|
id="checkAllEntries" |
|
|
|
id="checkAllEntries" |
|
|
|
inputType="checkbox" |
|
|
|
inputType="checkbox" |
|
|
|
checked={Object.values(groupedModules).map((value: any) => { |
|
|
|
checked={Object.values(groupedModules).map((value: any) => { |
|
|
|
return (value.map(x => { |
|
|
|
return (value.map(x => { |
|
|
|
return x._index.toString() |
|
|
|
return x._index.toString() |
|
|
|
})) |
|
|
|
})) |
|
|
|
}).flat().every(el => categoryIndex.includes(el))} |
|
|
|
}).flat().every(el => categoryIndex.includes(el))} |
|
|
|
label="Select all" |
|
|
|
label="Select all" |
|
|
|
onClick={() => handleCheckAllModules(groupedModules)} |
|
|
|
onClick={() => handleCheckAllModules(groupedModules)} |
|
|
|
/> |
|
|
|
/> |
|
|
|
<RemixUiCheckbox |
|
|
|
</div> |
|
|
|
id="autorunstaticanalysis" |
|
|
|
<div className="" > |
|
|
|
inputType="checkbox" |
|
|
|
<CheckBox |
|
|
|
onClick={handleAutoRun} |
|
|
|
id="autorunstaticanalysis" |
|
|
|
checked={autoRun} |
|
|
|
inputType="checkbox" |
|
|
|
label="Autorun" |
|
|
|
onClick={handleAutoRun} |
|
|
|
/> |
|
|
|
checked={autoRun} |
|
|
|
|
|
|
|
label="Autorun" |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
<Button buttonText="Run" onClick={() => run(result.lastCompilationResult, result.lastCompilationSource, result.currentFile)} disabled={runButtonState || categoryIndex.length === 0}/> |
|
|
|
<Button buttonText="Run" onClick={() => run(result.lastCompilationResult, result.lastCompilationSource, result.currentFile)} disabled={runButtonState || categoryIndex.length === 0}/> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
@ -368,7 +357,12 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
<> |
|
|
|
<> |
|
|
|
<span className="text-dark h6">{element[0]}</span> |
|
|
|
<span className="text-dark h6">{element[0]}</span> |
|
|
|
{element[1].map(x => ( |
|
|
|
{element[1].map(x => ( |
|
|
|
x.hasWarning ? (<ErrorRenderer message={x.msg} opt={x.options} warningErrors={ x.warningErrors}/>) : null |
|
|
|
x.hasWarning ? ( |
|
|
|
|
|
|
|
<div id={`staticAnalysisModule${element[1].warningModuleName}`}> |
|
|
|
|
|
|
|
<ErrorRenderer message={x.msg} opt={x.options} warningErrors={ x.warningErrors} editor={props.analysisModule}/> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
) : null |
|
|
|
))} |
|
|
|
))} |
|
|
|
</> |
|
|
|
</> |
|
|
|
))) |
|
|
|
))) |
|
|
|