Merge pull request #773 from ethereum/warnstaticanalyisis

In compile tab, warn if static analysis warnings
pull/1/head
yann300 7 years ago committed by GitHub
commit ed37c6c4d1
  1. 31
      src/app.js
  2. 5
      src/app/panels/righthand-panel.js
  3. 6
      src/app/staticanalysis/staticAnalysisView.js
  4. 28
      src/app/tabs/compile-tab.js
  5. 4
      src/app/tabs/tabbed-menu.js
  6. 8
      src/app/ui/renderer.js

@ -324,6 +324,18 @@ function run () {
}
var renderer = new Renderer(rendererAPI)
// ----------------- StaticAnalysis -----------------
var staticAnalysisAPI = {
renderWarning: (label, warningContainer, type) => {
return renderer.error(label, warningContainer, type)
},
offsetToLineColumn: (location, file) => {
return offsetToLineColumnConverter.offsetToLineColumn(location, file, compiler.lastCompilationResult)
}
}
var staticanalysis = new StaticAnalysis(staticAnalysisAPI, compiler.event)
// ----------------- UniversalDApp -----------------
var transactionContextAPI = {
getAddress: (cb) => {
@ -415,13 +427,17 @@ function run () {
compiler: compiler.event,
app: self.event,
udapp: udapp.event,
editor: editor.event
editor: editor.event,
staticAnalysis: staticanalysis.event
}
self._components.righthandpanel = new RighthandPanel(rhpAPI, rhpEvents, {})
self._view.rightpanel.appendChild(self._components.righthandpanel.render())
self._components.righthandpanel.init()
self._components.righthandpanel.event.register('resize', delta => self._adjustLayout('right', delta))
var node = document.getElementById('staticanalysisView')
node.insertBefore(staticanalysis.render(), node.childNodes[0])
// ----------------- editor resize ---------------
function onResize () {
@ -478,19 +494,6 @@ function run () {
transactionDebugger.addProvider('web3', executionContext.web3())
transactionDebugger.switchProvider(executionContext.getProvider())
// ----------------- StaticAnalysis -----------------
var staticAnalysisAPI = {
renderWarning: (label, warningContainer, type) => {
return renderer.error(label, warningContainer, type)
},
offsetToLineColumn: (location, file) => {
return offsetToLineColumnConverter.offsetToLineColumn(location, file, compiler.lastCompilationResult)
}
}
var staticanalysis = new StaticAnalysis(staticAnalysisAPI, compiler.event)
var node = document.getElementById('staticanalysisView')
node.insertBefore(staticanalysis.render(), node.childNodes[0])
// ----------------- Tx listener -----------------
var transactionReceiptResolver = {

@ -86,6 +86,9 @@ function RighthandPanel (appAPI, events, opts) {
</div>
</div>
`
appAPI.switchTab = (tabClass) => {
this.event.trigger('switchTab', [tabClass])
}
compileTab(optionViews, appAPI, events, opts)
runTab(optionViews, appAPI, events, opts)
settingsTab(optionViews, appAPI, events, opts)
@ -101,7 +104,7 @@ function RighthandPanel (appAPI, events, opts) {
// ----------------- tabbed menu -----------------
var tabbedMenuAPI = {}
// load tabbed menu component
var tabEvents = {compiler: events.compiler, app: events.app}
var tabEvents = {compiler: events.compiler, app: events.app, rhp: self.event}
tabbedMenu(options, tabbedMenuAPI, tabEvents, {})
// ----------------- resizeable ui ---------------

@ -9,6 +9,8 @@ var remix = require('ethereum-remix')
var styleGuide = remix.ui.styleGuide
var styles = styleGuide()
var EventManager = require('ethereum-remix').lib.EventManager
var css = csjs`
.analysis {
display: flex;
@ -40,6 +42,7 @@ var css = csjs`
`
function staticAnalysisView (appAPI, compilerEvent) {
this.event = new EventManager()
this.view = null
this.appAPI = appAPI
this.runner = new StaticAnalysisRunner()
@ -99,6 +102,7 @@ staticAnalysisView.prototype.run = function () {
warningContainer.empty()
if (this.lastCompilationResult) {
var self = this
var warningCount = 0
this.runner.run(this.lastCompilationResult, selected, function (results) {
results.map(function (result, i) {
result.report.map(function (item, i) {
@ -113,6 +117,7 @@ staticAnalysisView.prototype.run = function () {
location = self.appAPI.offsetToLineColumn(location, file)
location = self.lastCompilationResult.sourceList[file] + ':' + (location.start.line + 1) + ':' + (location.start.column + 1) + ':'
}
warningCount++
self.appAPI.renderWarning(location + ' ' + item.warning + ((item.more) ? '<br><a href="' + item.more + '" target="blank">more</a>' : ''), warningContainer, {type: 'warning', useSpan: true, isHTML: true})
})
})
@ -122,6 +127,7 @@ staticAnalysisView.prototype.run = function () {
} else {
$('#righthand-panel #menu .staticanalysisView').css('color', styles.colors.red)
}
self.event.trigger('staticAnaysisWarning', [warningCount])
})
} else {
warningContainer.html('No compiled AST available')

@ -274,6 +274,12 @@ function compileTab (container, appAPI, appEvents, opts) {
function contractNames (container, appAPI, appEvents, opts) {
var contractsDetails = {}
appEvents.compiler.register('compilationStarted', () => {
var errorContainer = container.querySelector('.error')
errorContainer.innerHTML = ''
})
appEvents.compiler.register('compilationFinished', function (success, data, source) {
// reset the contractMetadata list (used by the publish action)
contractsDetails = {}
@ -287,17 +293,33 @@ function compileTab (container, appAPI, appEvents, opts) {
}
// display warning error if any
var errorContainer = container.querySelector('.error')
errorContainer.innerHTML = ''
var error = false
if (data['error']) {
error = true
appAPI.compilationMessage(data['error'], $(errorContainer))
}
if (data['errors']) {
if (data['errors'].length) error = true
data['errors'].forEach(function (err) {
appAPI.compilationMessage(err, $(errorContainer))
})
}
if (errorContainer.innerHTML === '') {
appAPI.compilationMessage('Compilation successful without warning', $(errorContainer), {type: 'success'})
if (!error) {
if (data.contracts) {
for (var contract in data.contracts) {
appAPI.compilationMessage(contract, $(errorContainer), {type: 'success'})
}
}
}
})
appEvents.staticAnalysis.register('staticAnaysisWarning', (count) => {
if (count) {
var errorContainer = container.querySelector('.error')
appAPI.compilationMessage(`Static Analysis raised ${count} warning(s) that requires your attention.`, $(errorContainer), {
type: 'warning',
click: () => appAPI.switchTab('staticanalysisView')
})
}
})

@ -12,6 +12,10 @@ function tabbedMenu (container, appAPI, events, opts) {
selectTab(container.querySelector('li.debugView'))
})
events.rhp.register('switchTab', tabName => {
selectTab(container.querySelector(`li.${tabName}`))
})
// initialize tabbed menu
selectTab(container.querySelector('.compileView'))

@ -42,8 +42,14 @@ Renderer.prototype.error = function (message, container, options) {
})
}
$error.click(function (ev) {
self.appAPI.errorClick(errFile, errLine, errCol)
options && options.click ? options.click(errFile, errLine, errCol) : self.appAPI.errorClick(errFile, errLine, errCol)
})
} else {
if (options.click) {
$error.click(function (ev) {
options.click(message)
})
}
}
$error.find('.close').click(function (ev) {
ev.preventDefault()

Loading…
Cancel
Save