Skip to content

Commit 9c18f16

Browse files
lingoLuke Hudson
andauthored
fix: Avoid TypeError when exec stub is used with no arguments (#97)
This extends the fix in 7f97815 In some situations, such as code using a sinon stub, a TypeError is thrown as the AST node has no 'arguments' property. Closes 69 Refs 69 Co-authored-by: Luke Hudson <[email protected]>
1 parent 08ba476 commit 9c18f16

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

rules/detect-child-process.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = {
4141
},
4242
MemberExpression: function (node) {
4343
if (node.property.name === 'exec' && names.indexOf(node.object.name) > -1) {
44-
if (node.parent && node.parent.arguments.length && node.parent.arguments[0].type !== 'Literal') {
44+
if (node.parent && node.parent.arguments && node.parent.arguments.length && node.parent.arguments[0].type !== 'Literal') {
4545
return context.report({ node: node, message: 'Found child_process.exec() with non Literal first argument' });
4646
}
4747
}

test/detect-child-process.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@ tester.run(ruleName, rule, {
2121
code: "var child = require('child_process'); child.exec()",
2222
errors: [{ message: 'Found require("child_process")' }],
2323
},
24+
{
25+
code: "var child = sinon.stub(require('child_process')); child.exec.returns({});",
26+
errors: [{ message: 'Found require("child_process")' }],
27+
},
2428
],
2529
});

0 commit comments

Comments
 (0)