Skip to content

Commit 6900a51

Browse files
committed
fix analysis running based on enabled tools
1 parent caac2bf commit 6900a51

File tree

1 file changed

+69
-59
lines changed

1 file changed

+69
-59
lines changed

libs/remix-ui/static-analyser/src/lib/actions/staticAnalysisActions.ts

Lines changed: 69 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -56,73 +56,82 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<b
5656
const warningErrors = []
5757
props.analysisModule.hints = []
5858
// Run solhint
59+
if (solhintEnabled) {
5960
_paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'solHint'])
6061
const hintsResult = await props.analysisModule.call('solhint', 'lint', state.file)
61-
props.analysisModule.hints = solhintEnabled === false ? 0 : hintsResult
62+
props.analysisModule.hints = hintsResult
6263
setHints(hintsResult)
64+
} else {
65+
props.analysisModule.hints = []
66+
setHints([])
67+
}
6368
// Remix Analysis
64-
_paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'remixAnalyzer'])
65-
const results = runner.run(lastCompilationResult, categoryIndex)
66-
for (const result of results) {
67-
let moduleName
68-
Object.keys(groupedModules).map(key => {
69-
groupedModules[key].forEach(el => {
70-
if (el.name === result.name) {
71-
moduleName = groupedModules[key][0].categoryDisplayName
72-
}
69+
if (basicEnabled) {
70+
_paq.push(['trackEvent', 'solidityStaticAnalyzer', 'analyze', 'remixAnalyzer'])
71+
const results = runner.run(lastCompilationResult, categoryIndex)
72+
for (const result of results) {
73+
let moduleName
74+
Object.keys(groupedModules).map(key => {
75+
groupedModules[key].forEach(el => {
76+
if (el.name === result.name) {
77+
moduleName = groupedModules[key][0].categoryDisplayName
78+
}
79+
})
7380
})
74-
})
75-
// iterate over the warnings and create an object
76-
for (const item of result.report) {
77-
let location: any = {}
78-
let locationString = 'not available'
79-
let column = 0
80-
let row = 0
81-
let fileName = currentFile
82-
let isLibrary = false
81+
// iterate over the warnings and create an object
82+
for (const item of result.report) {
83+
let location: any = {}
84+
let locationString = 'not available'
85+
let column = 0
86+
let row = 0
87+
let fileName = currentFile
88+
let isLibrary = false
8389

84-
if (item.location) {
85-
const split = item.location.split(':')
86-
const file = split[2]
87-
location = {
88-
start: parseInt(split[0]),
89-
length: parseInt(split[1])
90+
if (item.location) {
91+
const split = item.location.split(':')
92+
const file = split[2]
93+
location = {
94+
start: parseInt(split[0]),
95+
length: parseInt(split[1])
96+
}
97+
location = props.analysisModule._deps.offsetToLineColumnConverter.offsetToLineColumn(
98+
location,
99+
parseInt(file),
100+
lastCompilationSource.sources,
101+
lastCompilationResult.sources
102+
)
103+
row = location.start.line
104+
column = location.start.column
105+
locationString = row + 1 + ':' + column + ':'
106+
fileName = Object.keys(lastCompilationResult.sources)[file]
90107
}
91-
location = props.analysisModule._deps.offsetToLineColumnConverter.offsetToLineColumn(
92-
location,
93-
parseInt(file),
94-
lastCompilationSource.sources,
95-
lastCompilationResult.sources
96-
)
97-
row = location.start.line
98-
column = location.start.column
99-
locationString = row + 1 + ':' + column + ':'
100-
fileName = Object.keys(lastCompilationResult.sources)[file]
101-
}
102-
if(fileName !== currentFile) {
103-
const {file, provider} = await props.analysisModule.call('fileManager', 'getPathFromUrl', fileName)
104-
if (file.startsWith('.deps') || (provider.type === 'localhost' && file.startsWith('localhost/node_modules'))) isLibrary = true
105-
}
106-
const msg = message(result.name, item.warning, item.more, state.file, locationString)
107-
const options = {
108-
type: 'warning',
109-
useSpan: true,
110-
errFile: state.file,
111-
fileName,
112-
isLibrary,
113-
errLine: row,
114-
errCol: column,
115-
item: item,
116-
name: result.name,
117-
locationString,
118-
more: item.more,
119-
location: location
108+
if (fileName !== currentFile) {
109+
const { file, provider } = await props.analysisModule.call('fileManager', 'getPathFromUrl', fileName)
110+
if (file.startsWith('.deps') || (provider.type === 'localhost' && file.startsWith('localhost/node_modules'))) isLibrary = true
111+
}
112+
const msg = message(result.name, item.warning, item.more, state.file, locationString)
113+
const options = {
114+
type: 'warning',
115+
useSpan: true,
116+
errFile: state.file,
117+
fileName,
118+
isLibrary,
119+
errLine: row,
120+
errCol: column,
121+
item: item,
122+
name: result.name,
123+
locationString,
124+
more: item.more,
125+
location: location
126+
}
127+
warningErrors.push(options)
128+
warningMessage.push({ msg, options, hasWarning: true, warningModuleName: moduleName })
129+
setSsaWarnings(warningMessage)
120130
}
121-
warningErrors.push(options)
122-
warningMessage.push({ msg, options, hasWarning: true, warningModuleName: moduleName })
123-
setSsaWarnings(warningMessage)
124131
}
125-
}
132+
} else {
133+
setSsaWarnings([])
134+
}
126135
// Slither Analysis
127136
if (showSlither && slitherEnabled) {
128137
setSlitherWarnings([])
@@ -198,12 +207,13 @@ slitherEnabled: boolean, setStartAnalysis: React.Dispatch<React.SetStateAction<b
198207
props.analysisModule.call('terminal', 'log', { type: 'error', value: '[Slither Analysis]: Error occured! See remixd console for details.' })
199208
showWarnings(warningMessage, 'warningModuleName')
200209
}
201-
} else showWarnings(warningMessage, 'warningModuleName')
210+
} else //showWarnings(warningMessage, 'warningModuleName')
202211
setStartAnalysis(false)
203212
} else {
204213
if (categoryIndex.length) {
205214
warningContainer.current.innerText = 'No compiled AST available'
206215
}
216+
207217
props.event.trigger('staticAnaysisWarning', [-1])
208218
}
209219
}

0 commit comments

Comments
 (0)