Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
a698dfe9
Commit
a698dfe9
authored
Mar 13, 2017
by
chriseth
Committed by
GitHub
Mar 13, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #455 from soad003/master
Categories for static analysis modules
parents
a6ece05c
bed67f2b
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
82 additions
and
4 deletions
+82
-4
categories.js
src/app/staticanalysis/modules/categories.js
+4
-0
gasCosts.js
src/app/staticanalysis/modules/gasCosts.js
+2
-0
txOrigin.js
src/app/staticanalysis/modules/txOrigin.js
+2
-0
staticAnalysisView.js
src/app/staticanalysis/staticAnalysisView.js
+35
-3
utils.js
src/app/utils.js
+12
-1
index.js
test/index.js
+1
-0
util-test.js
test/util-test.js
+26
-0
No files found.
src/app/staticanalysis/modules/categories.js
0 → 100644
View file @
a698dfe9
module
.
exports
=
{
SECURITY
:
{
displayName
:
'Security'
,
id
:
'SEC'
},
GAS
:
{
displayName
:
'Gas & Economy'
,
id
:
'GAS'
}
}
src/app/staticanalysis/modules/gasCosts.js
View file @
a698dfe9
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
}
src/app/staticanalysis/modules/txOrigin.js
View file @
a698dfe9
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
}
src/app/staticanalysis/staticAnalysisView.js
View file @
a698dfe9
...
...
@@ -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
})
}
src/app/utils.js
View file @
a698dfe9
...
...
@@ -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
}
test/index.js
View file @
a698dfe9
...
...
@@ -3,3 +3,4 @@
require
(
'./compiler-test'
)
require
(
'./gist-handler-test'
)
require
(
'./query-params-test'
)
require
(
'./util-test'
)
test/util-test.js
0 → 100644
View file @
a698dfe9
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
)
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment