Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit f890515

Browse files
committed
Fix: disallowUnusedParams: ignore eval exressions
Fixes #1943
1 parent 5eb44a7 commit f890515

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

lib/js-file.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ JsFile.prototype = {
823823
if (!this._scope) {
824824
this._scope = escope.analyze(this._tree, {
825825
ecmaVersion: 6,
826+
ignoreEval: true,
826827
sourceType: 'module'
827828
});
828829
}

test/specs/js-file.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,16 @@ describe('js-file', function() {
12151215
expect(file.getScope()).to.be.a('object');
12161216
expect(file._scope).to.be.not.a('null');
12171217
});
1218+
1219+
it('should ignore eval', function(done) {
1220+
var sources = ['function f(options) { return options; eval(); }'];
1221+
var file = createJsFile(sources.join('\n'));
1222+
1223+
file.iterateNodesByType(['FunctionDeclaration', 'FunctionExpression'], function(node) {
1224+
expect(file.getScope().acquire(node).variables[1].references.length).to.equal(1);
1225+
done();
1226+
});
1227+
});
12181228
});
12191229

12201230
describe('removeToken', function() {

test/specs/rules/disallow-unused-params.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ describe('rules/disallow-unused-params', function() {
1717
expect(checker.checkString('function a(b, c) { return c; };')).to.have.no.errors();
1818
});
1919

20+
it('should report even with eval expression (gh-1943)', function() {
21+
expect(checker.checkString('function foo(options) { return options; eval() };'))
22+
.to.have.no.errors();
23+
});
24+
2025
it('should not report on param that used in child scope', function() {
2126
expect(checker.checkString(
2227
'function a(b) { return function () { return b; }; }'

0 commit comments

Comments
 (0)