Merge pull request #455 from soad003/master

Categories for static analysis modules
pull/1/head
chriseth 8 years ago committed by GitHub
commit a698dfe998
  1. 4
      src/app/staticanalysis/modules/categories.js
  2. 2
      src/app/staticanalysis/modules/gasCosts.js
  3. 2
      src/app/staticanalysis/modules/txOrigin.js
  4. 38
      src/app/staticanalysis/staticAnalysisView.js
  5. 13
      src/app/utils.js
  6. 1
      test/index.js
  7. 26
      test/util-test.js

@ -0,0 +1,4 @@
module.exports = {
SECURITY: {displayName: 'Security', id: 'SEC'},
GAS: {displayName: 'Gas & Economy', id: 'GAS'}
}

@ -1,5 +1,6 @@
var name = 'gas costs'
var desc = 'Warn if the gas requiremets of functions are too high.'
var categories = require('./categories')
function gasCosts () {
}
@ -46,5 +47,6 @@ gasCosts.prototype.report = function (compilationResults) {
module.exports = {
name: name,
description: desc,
category: categories.GAS,
Module: gasCosts
}

@ -1,5 +1,6 @@
var name = 'tx origin'
var desc = 'warn if tx.origin is used'
var categories = require('./categories')
function txOrigin () {
this.txOriginNodes = []
@ -29,5 +30,6 @@ txOrigin.prototype.report = function () {
module.exports = {
name: name,
description: desc,
category: categories.SECURITY,
Module: txOrigin
}

@ -2,6 +2,7 @@
var StaticAnalysisRunner = require('./staticAnalysisRunner.js')
var yo = require('yo-yo')
var $ = require('jquery')
var utils = require('../utils')
function staticAnalysisView (appAPI, compilerEvent) {
this.view = null
@ -26,7 +27,7 @@ staticAnalysisView.prototype.render = function () {
var self = this
var view = yo`<div>
<strong>Static Analysis</strong>
<label for="autorunstaticanalysis"><input id="autorunstaticanalysis" type="checkbox" checked="true">Auto run</label>
<label for="autorunstaticanalysis"><input id="autorunstaticanalysis" type="checkbox" style="vertical-align:bottom" checked="true">Auto run</label>
<div id="staticanalysismodules">
${this.modulesView}
</div>
@ -94,7 +95,38 @@ staticAnalysisView.prototype.run = function () {
module.exports = staticAnalysisView
function renderModules (modules) {
return modules.map(function (item, i) {
return yo`<label><input id="staticanalysismodule${i}" type="checkbox" name="staticanalysismodule" index=${i} checked="true">${item.name} (${item.description})</label>`
var groupedModules = utils.groupBy(preProcessModules(modules), 'categoryId')
return Object.keys(groupedModules).map((categoryId, i) => {
var category = groupedModules[categoryId]
var entriesDom = category.map((item, i) => {
return yo`<label>
<input id="staticanalysismodule_${categoryId}_${i}"
type="checkbox"
name="staticanalysismodule"
index=${item._index}
checked="true" style="vertical-align:bottom">${item.name} (${item.description})
</label>`
})
return yo`<div>
<label>
<b>${category[0].categoryDisplayName}</b> (
<input id="staticanalysismodule_${categoryId}"
type="checkbox"
checked="true"
style="vertical-align:bottom; margin-left:0"
onchange=${function () { $('[id^=' + this.id + ']').prop('checked', this.checked) }}/> all/none)
</label>
${entriesDom}
</div>`
})
}
function preProcessModules (arr) {
return arr.map((item, i) => {
item['_index'] = i
item.categoryDisplayName = item.category.displayName
item.categoryId = item.category.id
return item
})
}

@ -4,6 +4,17 @@ function errortype (message) {
return message.match(/^(.*:[0-9]*:[0-9]* )?Warning: /) ? 'warning' : 'error'
}
function groupBy (arr, key) {
return arr.reduce((sum, item) => {
const groupByVal = item[key]
var groupedItems = sum[groupByVal] || []
groupedItems.push(item)
sum[groupByVal] = groupedItems
return sum
}, {})
}
module.exports = {
errortype: errortype
errortype: errortype,
groupBy: groupBy
}

@ -3,3 +3,4 @@
require('./compiler-test')
require('./gist-handler-test')
require('./query-params-test')
require('./util-test')

@ -0,0 +1,26 @@
var test = require('tape')
var utils = require('../babelify-src/app/utils')
test('util.groupBy on valid input', function (t) {
t.plan(1)
var result = utils.groupBy([
{category: 'GAS', name: 'a'},
{category: 'SEC', name: 'b'},
{category: 'GAS', name: 'c'}
], 'category')
var expectedResult = {
'GAS': [
{category: 'GAS', name: 'a'},
{category: 'GAS', name: 'c'}
],
'SEC': [
{category: 'SEC', name: 'b'}
]
}
t.deepEqual(result, expectedResult)
})
Loading…
Cancel
Save