Skip to content
This repository was archived by the owner on Dec 4, 2021. It is now read-only.

Commit 1f15f7e

Browse files
Caleb HooverCaleb Hoover
Caleb Hoover
authored and
Caleb Hoover
committed
added stuff, fixed stuff
1 parent 2c90617 commit 1f15f7e

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

bin/check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var yargs = require('yargs')
55
.describe('v', 'Verbose flag. Will print statements.')
66
.describe('r', 'Recrusive flag. Will recursively check required files.')
77
.describe('o', 'Output flag. Will output ast into ASTOutput.js.')
8+
.describe('j', 'Will output <json class=""></json>')
89
.showHelpOnFail(false);
910

1011
var check = require('../check.js'),

check.js

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,21 @@ var sources = require('./danger.json').sources;
1616
var flags = module.exports.flags = {verbose: false, recursive: false};
1717
var lookupTable = {};
1818

19+
var cs = {
20+
'CE': colors.green,
21+
'SINK': colors.red,
22+
'SOURCE': colors.red,
23+
'SOURCES': colors.yellow,
24+
'RETURN': colors.red
25+
};
26+
1927
function log(type, node, name, value) {
2028
var p = pos(node);
2129
if (flags.recursive)
2230
p = this.file + ':' + p;
2331

24-
console.log(colors.blue(type), colors.grey(p), name, value ? value : '');
32+
console.log(cs[type]?cs[type]('[' + type + ']'):colors.blue('[' + type + ']'),
33+
colors.grey(p), name, value ? value : '');
2534
}
2635

2736

@@ -113,15 +122,15 @@ Scope.prototype.track = function(variable) {
113122
if (resolved && typeof resolved == 'string') {
114123
if (this.isSource(resolved.name || resolved) || this.isSource(value.name || value)) {
115124
this.sources.push(name);
116-
this.log('[SOURCE]'.red, variable, name, value);
125+
this.log('SOURCE', variable, name, value);
117126
}
118127
}
119128
}
120129

121130
this.vars[name] = value;
122131

123132
if (flags.verbose && value)
124-
this.log('[VAR]', variable, name, value?value.raw || value:'');
133+
this.log('VAR', variable, name, value?value.raw || value:'');
125134

126135
};
127136

@@ -182,14 +191,14 @@ Scope.prototype.resolveStatement = function(node) {
182191
var ceName = scope.resolve(ce.name);
183192

184193
if (flags.verbose)
185-
this.log('[CES]', node, ceName, ce.raw);
194+
this.log('CES', node, ceName, ce.raw);
186195

187196
if (this.isSink(ceName) && ce.arguments) {
188197
ce.arguments.some(function (arg) {
189198
var resolved = scope.resolve(arg);
190199

191200
if (scope.isSource(arg.name || arg) || scope.isSource(resolved.name || resolved)) {
192-
scope.log('[SINK]'.red, node, ceName, ce.arguments?ce.arguments:'');
201+
scope.log('SINK', node, ceName, ce.arguments?ce.arguments:'');
193202
return true;
194203
}
195204
return false;
@@ -206,7 +215,7 @@ Scope.prototype.resolveStatement = function(node) {
206215
var names = assign.names;
207216
var value = this.resolveExpression(assign.value, function() {
208217
scope.sources.push(names);
209-
scope.log('[SOURCE]'.red, node, names);
218+
scope.log('SOURCE'.red, node, names);
210219
});
211220

212221
names.forEach(function(name) {
@@ -223,7 +232,7 @@ Scope.prototype.resolveStatement = function(node) {
223232
});
224233

225234
if (flags.verbose && value)
226-
this.log('[ASSIGN]', node, names.length==1?names[0]:names, util.inspect(value.raw || value, {depth: 1}));
235+
this.log('ASSIGN', node, names.length==1?names[0]:names, util.inspect(value.raw || value, {depth: 1}));
227236
break;
228237
case 'FunctionDeclaration':
229238
var func = scope.resolveFunctionExpression(node);
@@ -232,7 +241,7 @@ Scope.prototype.resolveStatement = function(node) {
232241
traverse(func.body, func.scope);
233242

234243
if (flags.verbose)
235-
this.log('[FUNC]', node, func.name);
244+
this.log('FUNC', node, func.name);
236245
break;
237246
case 'IfStatement':
238247
this.resolveExpression(node.test);
@@ -254,10 +263,10 @@ Scope.prototype.resolveStatement = function(node) {
254263
break;
255264
case 'SwitchStatement':
256265
if (flags.verbose)
257-
this.log('[SWITCH]', node);
266+
this.log('SWITCH', node);
258267
node.cases.forEach(function (i) {
259268
if (flags.verbose)
260-
scope.log('[CASE]', node);
269+
scope.log('CASE', node);
261270
i.consequent.forEach(function (statement) {
262271
scope.resolveStatement(statement.expression || statement);
263272
});
@@ -295,7 +304,7 @@ Scope.prototype.resolveExpression = function(right, isSourceCB) {
295304
case 'ArrayExpression':
296305
var array = scope.resolveArrayExpression(right);
297306
if (flags.verbose)
298-
this.log('[ARRAY]', right, array);
307+
this.log('ARRAY', right, array);
299308
return array;
300309
case 'BinaryExpression':
301310
climb(right).forEach(function (i) {
@@ -320,7 +329,7 @@ Scope.prototype.resolveExpression = function(right, isSourceCB) {
320329
var ceName = scope.resolve(ce.name);
321330

322331
if (flags.verbose)
323-
this.log('[CE]', right, ceName, ce.raw);
332+
this.log('CE', right, ceName, ce.raw);
324333

325334
if (ceName && typeof ceName == 'string') {
326335
if (scope.isSource(ceName)) {
@@ -333,7 +342,7 @@ Scope.prototype.resolveExpression = function(right, isSourceCB) {
333342
var resolved = scope.resolve(arg);
334343

335344
if (scope.isSource(arg.name || arg) || scope.isSource(resolved.name || resolved)) {
336-
scope.log('[SINK]'.red, right, ceName, ce.arguments?ce.arguments:'');
345+
scope.log('SINK', right, ceName, ce.arguments?ce.arguments:'');
337346
return true;
338347
}
339348
return false;
@@ -424,7 +433,7 @@ Scope.prototype.resolveForStatement = function(node) {
424433
}
425434
test = this.resolveExpression(node.test);
426435
if (flags.verbose)
427-
this.log('[TEST]', node, test);
436+
this.log('TEST', node, test);
428437

429438
traverse(node.body, this);
430439
return fs;
@@ -434,7 +443,7 @@ Scope.prototype.resolveWhileStatement = function(node) {
434443
var ws = {};
435444
test = this.resolveExpression(node.test);
436445
if (flags.verbose)
437-
this.log('[TEST]', node);
446+
this.log('TEST', node);
438447

439448
traverse(node.body, this);
440449
return ws;
@@ -484,7 +493,7 @@ Scope.prototype.resolveFunctionExpression = function(node) {
484493
if (scope.isSource(resolved.name || resolved) || scope.isSource(arg.name || arg)) {
485494
if (fe.name)
486495
scope.sources.push(fe.name);
487-
scope.log('[RETURN]'.red, node, fe.name, arg, resolved);
496+
scope.log('RETURN', node, fe.name, arg, resolved);
488497
}
489498
}
490499
});
@@ -572,7 +581,7 @@ traverse = module.exports.traverse = function(ast, scope) {
572581
}
573582
if (flags.verbose) {
574583
console.log('Creating new scope'.yellow);
575-
console.log('[SOURCES]'.red, scope.sources);
584+
scope.log('SOURCES', scope.sources);
576585
}
577586

578587

0 commit comments

Comments
 (0)