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

Commit

Permalink
[Fix] disallowUnusedVariables included function expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevils committed Apr 14, 2016
1 parent 6c6cda4 commit 80b4015
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rules/disallow-unused-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ module.exports.prototype = {
var grandparentElement = node.parentElement.parentElement;

return grandparentElement.type !== 'ExportNamedDeclaration';
} else {
} else if (
node.parentElement.type === 'VariableDeclarator' ||
node.parentElement.type === 'ObjectProperty' ||
node.parentElement.isPattern
) {
return parentCheck(node.parentElement);
}
} else {
Expand Down
10 changes: 10 additions & 0 deletions test/specs/rules/disallow-unused-variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ describe('rules/disallow-unused-variables', function() {
.to.have.no.errors();
});

it('should not report unused for function expressions', function() {
expect(checker.checkString('var z = function x() { }; z++;'))
.to.have.no.errors();
});

it('should not report unused for function params', function() {
expect(checker.checkString('var z = function x(f) { }; z++;'))
.to.have.no.errors();
});

it('should not report unused variable defined with let within a function declaration', function() {
expect(checker.checkString('function x() { let y=1; return y; }'))
.to.have.no.errors();
Expand Down

0 comments on commit 80b4015

Please sign in to comment.