|
|
|
@ -5,6 +5,7 @@ import Button from './Button/StaticAnalyserButton' // eslint-disable-line |
|
|
|
|
import remixLib from '@remix-project/remix-lib' |
|
|
|
|
import _ from 'lodash' |
|
|
|
|
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
|
|
|
|
|
const StaticAnalysisRunner = require('@remix-project/remix-analyzer').CodeAnalysis |
|
|
|
|
const utils = remixLib.util |
|
|
|
@ -60,12 +61,12 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
} |
|
|
|
|
return indexOfCategory |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const [autoRun, setAutoRun] = useState(true) |
|
|
|
|
const [categoryIndex, setCategoryIndex] = useState(groupedModuleIndex(groupedModules)) |
|
|
|
|
|
|
|
|
|
const warningContainer = React.useRef(null) |
|
|
|
|
const [runButtonState, setRunButtonState] = useState(true) |
|
|
|
|
const [autoRun, setAutoRun] = useState(false) |
|
|
|
|
|
|
|
|
|
const [result, setResult] = useState({ |
|
|
|
|
lastCompilationResult: null, |
|
|
|
|
lastCompilationSource: null, |
|
|
|
@ -81,41 +82,33 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
const [warningState, setWarningState] = useState([]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
|
|
if (autoRun) { |
|
|
|
|
const setCompilationResult = async (data, source, file) => { |
|
|
|
|
await setResult({ lastCompilationResult: data, lastCompilationSource: source, currentFile: file }) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (props.analysisModule) { |
|
|
|
|
|
|
|
|
|
props.analysisModule.on( |
|
|
|
|
'solidity', |
|
|
|
|
'compilationFinished', |
|
|
|
|
(file, source, languageVersion, data) => { |
|
|
|
|
if (languageVersion.indexOf('soljson') !== 0) return |
|
|
|
|
setCompilationResult(data, source, file) |
|
|
|
|
if(categoryIndex.length > 0){ |
|
|
|
|
if (categoryIndex.length > 0) { |
|
|
|
|
run(data, source, file) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
setAutoRun(true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return () => { } |
|
|
|
|
}, [autoRun, categoryIndex]) |
|
|
|
|
|
|
|
|
|
const run = (lastCompilationResult, lastCompilationSource, currentFile) => { |
|
|
|
|
// const highlightLocation = async (location, fileName) => {
|
|
|
|
|
// await props.analysisModule.call('editor', 'discardHighlight')
|
|
|
|
|
// await props.analysisModule.call('editor', 'highlight', location, fileName)
|
|
|
|
|
// }
|
|
|
|
|
if (autoRun) { |
|
|
|
|
setResult({ lastCompilationResult, lastCompilationSource, currentFile }) |
|
|
|
|
if (lastCompilationResult && categoryIndex.length) { |
|
|
|
|
if (lastCompilationResult && categoryIndex.length > 0) { |
|
|
|
|
setRunButtonState(false) |
|
|
|
|
let warningCount = 0 |
|
|
|
|
const warningMessage = [] |
|
|
|
@ -139,8 +132,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
let row = 0 |
|
|
|
|
let fileName = currentFile |
|
|
|
|
if (item.location) { |
|
|
|
|
var split = item.location.split(':') |
|
|
|
|
var file = split[2] |
|
|
|
|
const split = item.location.split(':') |
|
|
|
|
const file = split[2] |
|
|
|
|
location = { |
|
|
|
|
start: parseInt(split[0]), |
|
|
|
|
length: parseInt(split[1]) |
|
|
|
@ -202,7 +195,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
const groupedCategory = groupBy(resultArray, 'warningModuleName') |
|
|
|
|
setWarningState(groupedCategory) |
|
|
|
|
}) |
|
|
|
|
if(categoryIndex.length > 0){ |
|
|
|
|
if (categoryIndex.length > 0) { |
|
|
|
|
props.event.trigger('staticAnaysisWarning', [warningCount]) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
@ -213,6 +206,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
props.event.trigger('staticAnaysisWarning', [-1]) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleCheckAllModules = (groupedModules) => { |
|
|
|
|
const index = groupedModuleIndex(groupedModules) |
|
|
|
@ -223,9 +217,8 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
}) |
|
|
|
|
) |
|
|
|
|
} else { |
|
|
|
|
setCategoryIndex(_.uniq([...categoryIndex])) |
|
|
|
|
setCategoryIndex(_.uniq([...categoryIndex, ...index])) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleCheckOrUncheckCategory = (category) => { |
|
|
|
@ -261,7 +254,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
const categoryItem = (categoryId, item, i) => { |
|
|
|
|
return ( |
|
|
|
|
<div className="form-check" key={i}> |
|
|
|
|
<CheckBox |
|
|
|
|
<RemixUiCheckbox |
|
|
|
|
categoryId={categoryId} |
|
|
|
|
id={`staticanalysismodule_${categoryId}_${i}`} |
|
|
|
|
inputType="checkbox" |
|
|
|
@ -285,7 +278,7 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
<label |
|
|
|
|
htmlFor={`heading${categoryId}`} |
|
|
|
|
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-expanded="false" |
|
|
|
|
data-bs-controls={`heading${categoryId}`} |
|
|
|
@ -294,10 +287,10 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
{category[0].categoryDisplayName} |
|
|
|
|
</label> |
|
|
|
|
} |
|
|
|
|
expand={true} |
|
|
|
|
expand={false} |
|
|
|
|
> |
|
|
|
|
<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 className="w-100 d-block px-2 my-1 entries collapse multi-collapse" id={`heading${categoryId}`}> |
|
|
|
|
{category.map((item, i) => { |
|
|
|
@ -314,11 +307,10 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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="d-flex justify-content-between"> |
|
|
|
|
<div > |
|
|
|
|
<CheckBox |
|
|
|
|
<RemixUiCheckbox |
|
|
|
|
id="checkAllEntries" |
|
|
|
|
inputType="checkbox" |
|
|
|
|
checked={Object.values(groupedModules).map((value: any) => { |
|
|
|
@ -329,16 +321,13 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
label="Select all" |
|
|
|
|
onClick={() => handleCheckAllModules(groupedModules)} |
|
|
|
|
/> |
|
|
|
|
</div> |
|
|
|
|
<div className="" > |
|
|
|
|
<CheckBox |
|
|
|
|
<RemixUiCheckbox |
|
|
|
|
id="autorunstaticanalysis" |
|
|
|
|
inputType="checkbox" |
|
|
|
|
onClick={handleAutoRun} |
|
|
|
|
checked={autoRun} |
|
|
|
|
label="Autorun" |
|
|
|
|
/> |
|
|
|
|
</div> |
|
|
|
|
<Button buttonText="Run" onClick={() => run(result.lastCompilationResult, result.lastCompilationSource, result.currentFile)} disabled={runButtonState || categoryIndex.length === 0}/> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
@ -368,7 +357,12 @@ export const RemixUiStaticAnalyser = (props: RemixUiStaticAnalyserProps) => { |
|
|
|
|
<> |
|
|
|
|
<span className="text-dark h6">{element[0]}</span> |
|
|
|
|
{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 |
|
|
|
|
))} |
|
|
|
|
</> |
|
|
|
|
))) |
|
|
|
|