Skip to content

Commit 4fb6db2

Browse files
committed
Remove filename from error output
1 parent 1b95d87 commit 4fb6db2

18 files changed

+28
-63
lines changed

rules/detect-buffer-noassert.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ module.exports = function(context) {
4747
"writeDoubleBE"
4848
];
4949

50-
51-
var getSource = function (token) {
52-
return token.loc.start.line+ ': ' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t');
53-
}
54-
5550
return {
5651
"MemberExpression": function (node) {
5752
var index;
@@ -63,7 +58,7 @@ module.exports = function(context) {
6358

6459
if (index && node.parent && node.parent.arguments && node.parent.arguments[index] && node.parent.arguments[index].value) {
6560
var token = context.getTokens(node)[0];
66-
return context.report(node, 'Found Buffer.' + node.property.name + ' with noAssert flag set true:\n\t' + getSource(token));
61+
return context.report(node, 'Found Buffer.' + node.property.name + ' with noAssert flag set true');
6762

6863
}
6964
}

rules/detect-child-process.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ module.exports = function(context) {
1313

1414
"use strict";
1515

16-
var getSource = function (token) {
17-
return token.loc.start.line+ ': ' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t');
18-
}
19-
2016
return {
2117
"CallExpression": function (node) {
2218
var token = context.getTokens(node)[0];
@@ -28,15 +24,15 @@ module.exports = function(context) {
2824
} else if (node.parent.type === 'AssignmentExpression' && node.parent.operator === '=') {
2925
names.push(node.parent.left.name);
3026
}
31-
return context.report(node, 'Found require("child_process")\n\t' + getSource(token));
27+
return context.report(node, 'Found require("child_process")');
3228
}
3329
}
3430
},
3531
"MemberExpression": function (node) {
3632
var token = context.getTokens(node)[0];
3733
if (node.property.name === 'exec' && names.indexOf(node.object.name) > -1) {
3834
if (node.parent && node.parent.arguments && node.parent.arguments[0].type !== 'Literal') {
39-
return context.report(node, 'Found child_process.exec() with non Literal first argument\n\t' + getSource(token));
35+
return context.report(node, 'Found child_process.exec() with non Literal first argument');
4036
}
4137
}
4238
}

rules/detect-new-buffer.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
module.exports = function (context) {
2-
3-
var getSource = function (node) {
4-
var token = context.getTokens(node)[0];
5-
return token.loc.start.line+ ': ' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t');
6-
}
7-
8-
92
// Detects instances of new Buffer(argument)
103
// where argument is any non literal value.
114
return {
@@ -14,7 +7,7 @@ module.exports = function (context) {
147
node.arguments[0] &&
158
node.arguments[0].type != 'Literal') {
169

17-
return context.report(node, "Found new Buffer\n\t" + getSource(node));
10+
return context.report(node, "Found new Buffer");
1811
}
1912

2013

rules/detect-non-literal-fs-filename.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ module.exports = function(context) {
1515

1616
"use strict";
1717

18-
var getSource = function (token) {
19-
return token.loc.start.line+ ': ' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t');
20-
}
21-
2218
return {
2319
"MemberExpression": function (node) {
2420
var result = [];
@@ -36,13 +32,13 @@ module.exports = function(context) {
3632

3733
if (result.length > 0) {
3834
var token = context.getTokens(node)[0];
39-
return context.report(node, 'Found fs.' + node.property.name + ' with non literal argument at index ' + result.join(',') + '\n\t' + getSource(token));
35+
return context.report(node, 'Found fs.' + node.property.name + ' with non literal argument at index ' + result.join(','));
4036
}
4137

4238

4339
/*
4440
if (node.parent && node.parent.arguments && node.parent.arguments[index].value) {
45-
return context.report(node, 'found Buffer.' + node.property.name + ' with noAssert flag set true:\n\t' + getSource(token));
41+
return context.report(node, 'found Buffer.' + node.property.name + ' with noAssert flag set true');
4642
4743
}
4844
*/

rules/detect-non-literal-regexp.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@ module.exports = function(context) {
1212

1313
"use strict";
1414

15-
var getSource = function(token) {
16-
return token.loc.start.line + ': ' + context.getSourceLines().slice(token.loc.start.line - 1, token.loc.end.line).join('\n\t');
17-
}
1815
return {
1916
"NewExpression": function(node) {
2017
if (node.callee.name === 'RegExp') {
2118
var args = node.arguments;
2219
if (args && args.length > 0 && args[0].type !== 'Literal') {
2320
var token = context.getTokens(node)[0];
24-
return context.report(node, 'Found non-literal argument to RegExp Constructor\n\t' + getSource(token));
21+
return context.report(node, 'Found non-literal argument to RegExp Constructor');
2522
}
2623
}
2724

rules/detect-non-literal-require.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,13 @@ module.exports = function(context) {
1111

1212
"use strict";
1313

14-
var getSource = function (token) {
15-
return token.loc.start.line+ ': ' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t');
16-
}
17-
1814
return {
1915
"CallExpression": function (node) {
2016
if (node.callee.name === 'require') {
2117
var args = node.arguments;
2218
if (args && args.length > 0 && args[0].type !== 'Literal') {
2319
var token = context.getTokens(node)[0];
24-
return context.report(node, 'Found non-literal argument in require\n\t' + getSource(token));
20+
return context.report(node, 'Found non-literal argument in require');
2521
}
2622
}
2723

rules/detect-object-injection.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ var isChanged = false;
5959
var token = context.getTokens(node)[0];
6060
if (node.property.type === 'Identifier') {
6161
if (node.parent.type === 'VariableDeclarator') {
62-
context.report(node, 'Variable Assigned to Object Injection Sink: ' + context.getFilename() + ': ' + token.loc.start.line+ '\n\t' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t') + '\n\n');
62+
context.report(node, 'Variable Assigned to Object Injection Sink');
6363

6464
} else if (node.parent.type === 'CallExpression') {
6565
// console.log(node.parent)
66-
context.report(node, 'Function Call Object Injection Sink: ' + context.getFilename() + ': ' + token.loc.start.line+ '\n\t' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t') + '\n\n');
66+
context.report(node, 'Function Call Object Injection Sink');
6767
} else {
68-
context.report(node, 'Generic Object Injection Sink: ' + context.getFilename() + ': ' + token.loc.start.line+ '\n\t' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t') + '\n\n');
68+
context.report(node, 'Generic Object Injection Sink');
6969

7070
}
7171

rules/detect-possible-timing-attacks.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ module.exports = function(context) {
3232

3333
"use strict";
3434

35-
var getSource = function (token) {
36-
return token.loc.start.line+ ': ' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t');
37-
}
38-
3935
return {
4036
"IfStatement": function(node) {
4137
if (node.test && node.test.type === 'BinaryExpression') {
@@ -46,14 +42,14 @@ module.exports = function(context) {
4642
if (node.test.left) {
4743
var left = containsKeyword(node.test.left);
4844
if (left) {
49-
return context.report(node, "Potential timing attack, left side: " + left + '\n\t' + getSource(token));
45+
return context.report(node, "Potential timing attack, left side: " + left);
5046
}
5147
}
5248

5349
if (node.test.right) {
5450
var right = containsKeyword(node.test.right);
5551
if (right) {
56-
return context.report(node, "Potential timing attack, right side: " + right + '\n\t' + getSource(token));
52+
return context.report(node, "Potential timing attack, right side: " + right);
5753
}
5854
}
5955
}

rules/detect-pseudoRandomBytes.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ module.exports = function(context) {
1111

1212
"use strict";
1313

14-
var getSource = function (token) {
15-
return token.loc.start.line+ ': ' + context.getSourceLines().slice(token.loc.start.line-1, token.loc.end.line).join('\n\t');
16-
}
17-
1814
return {
1915
"MemberExpression": function (node) {
2016
if (node.property.name === 'pseudoRandomBytes') {
2117
var token = context.getTokens(node)[0];
22-
return context.report(node, 'Found crypto.pseudoRandomBytes which does not produce cryptographically strong numbers:\n\t' + getSource(token));
18+
return context.report(node, 'Found crypto.pseudoRandomBytes which does not produce cryptographically strong numbers');
2319
}
2420
}
2521

test/detect-buffer-noassert.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ tester.run(ruleName, Rule, {
1414
invalid: [
1515
{
1616
code: invalid,
17-
errors: [{ message: `Found Buffer.readUInt8 with noAssert flag set true:\n\t1: ${invalid}` }]
17+
errors: [{ message: 'Found Buffer.readUInt8 with noAssert flag set true' }]
1818
}
1919
]
2020
});
@@ -24,7 +24,7 @@ tester.run(`${ruleName} (false)`, Rule, {
2424
invalid: [
2525
{
2626
code: invalid,
27-
errors: [{ message: `Found Buffer.readUInt8 with noAssert flag set true:\n\t1: ${invalid}` }]
27+
errors: [{ message: 'Found Buffer.readUInt8 with noAssert flag set true' }]
2828
}
2929
]
3030
});

0 commit comments

Comments
 (0)