Skip to content

Commit

Permalink
Validate js (2600hz#1886)
Browse files Browse the repository at this point in the history
* validate-js: add validate-js script

* validate-js: fix an actual issue!
  • Loading branch information
fenollp authored and jamesaimonetti committed May 9, 2016
1 parent 41bd177 commit 124878c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ after_success:
- files="$(git diff --name-only master... -- application/ core/)" || true && echo $files
- make build-plt
- ./scripts/check-dialyzer.escript .kazoo.plt $files
- ./scripts/validate-js.sh $(find applications/ core/ -name '*.json')
- make sup_completion
- make build-ci-release
- # ERL_LIBS="$HOME/proper" ERLC_OPTS='-DPROPER' make compile-test
Expand Down
2 changes: 1 addition & 1 deletion applications/trunkstore/priv/couchdb/lookupipauth.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"language": "javascript",
"views": {
"LookUpIPAuth": {
"map": "function(doc) { if(doc.type != 'sys_info' ) return; if(doc.servers) { var srvs = Iterator(doc.servers); if(doc.servers) { var srvs = Iterator(doc.servers); for (var srv in srvs) { if (srv[1].auth) { var IPs = Iterator(srv[1].auth.AuthIP); for (var IP in IPs) { emit(IP[1], JSON.stringify({auth: srv[1].auth})); } } } } for (var srv in srvs) { if (srv[1].DIDs) { var DIDs = Iterator(srv[1].DIDs); for (var DID in DIDs) { emit(DID[0], JSON.stringify({auth: srv.auth, DID_Opts: DID[1]})); } } } }"
"map": "function(doc) { if(doc.type != 'sys_info' ) return; if(doc.servers) { var srvs = Iterator(doc.servers); if(doc.servers) { var srvs = Iterator(doc.servers); for (var srv in srvs) { if (srv[1].auth) { var IPs = Iterator(srv[1].auth.AuthIP); for (var IP in IPs) { emit(IP[1], JSON.stringify({auth: srv[1].auth})); } } } } for (var srv in srvs) { if (srv[1].DIDs) { var DIDs = Iterator(srv[1].DIDs); for (var DID in DIDs) { emit(DID[0], JSON.stringify({auth: srv.auth, DID_Opts: DID[1]})); } } } } }"
}
}
}
49 changes: 49 additions & 0 deletions scripts/validate-js.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python2

# print 'Usage: ' + sys.argv[0] + ' file.json+'

import sys
import json
from subprocess import call
import os

if len(sys.argv) < 2:
pass

def fmap(F, data):
if isinstance(data, dict):
for key, value in data.iteritems():
fmap(F, (key,value))
elif isinstance(data, tuple):
(key, value) = data
if isinstance(value, basestring):
if value.startswith('function'):
F(data)
else:
fmap(F, value)
elif isinstance(data, list):
for i, value in enumerate(data):
fmap(F, (i,value))
elif isinstance(data, int):
pass

def couchjs((field, js)):
TMP = '_'
with open(TMP, 'w') as wd:
wd.write(js + '\n')
try:
code = call(['couchjs', TMP])
if code != 0:
print 'Key:', field
print 'Code:', js
exit(1)
else:
print field, 'passed'
finally:
os.remove(TMP)

for fn in sys.argv[1:]:
print 'checking ' + fn
with open(fn) as rd:
data = json.load(rd)
fmap(couchjs, data)

0 comments on commit 124878c

Please sign in to comment.