Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #383 from ilyavolodin/no-undef
Fixing no-undef for eval use case (Fixes #376)
  • Loading branch information
nzakas committed Nov 14, 2013
2 parents 5217f8d + e00d7f0 commit 736d0ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/eslint.js
Expand Up @@ -283,7 +283,7 @@ module.exports = (function() {
controller = new estraverse.Controller();

// gather data that may be needed by the rules
currentScopes = escope.analyze(ast).scopes;
currentScopes = escope.analyze(ast, { ignoreEval: true }).scopes;

/* get all tokens from the ast and store them as a hashtable to
* improve traversal speed when wanting to find tokens for a given
Expand Down
18 changes: 17 additions & 1 deletion tests/lib/rules/no-undef.js
Expand Up @@ -426,6 +426,22 @@ vows.describe(RULE_ID).addBatch({
assert.equal(messages[0].message, "'Array' is read only.");
assert.include(messages[0].node.type, "Identifier");
}
}
},

//------------------------------------------------------------------------------
// Test eval and with
//------------------------------------------------------------------------------

"when evaluating function with eval": {
topic: "function evilEval(stuffToEval) { var ultimateAnswer; ultimateAnswer = 42; eval(stuffToEval); }",

"should not report a violation": function(topic) {

var config = { rules: {} };
config.rules[RULE_ID] = 1;

var messages = eslint.verify(topic, config);
assert.equal(messages.length, 0);
}
}
}).export(module);

0 comments on commit 736d0ee

Please sign in to comment.