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

Commit 80b4015

Browse files
committed
[Fix] disallowUnusedVariables included function expressions
1 parent 6c6cda4 commit 80b4015

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/rules/disallow-unused-variables.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ module.exports.prototype = {
6767
var grandparentElement = node.parentElement.parentElement;
6868

6969
return grandparentElement.type !== 'ExportNamedDeclaration';
70-
} else {
70+
} else if (
71+
node.parentElement.type === 'VariableDeclarator' ||
72+
node.parentElement.type === 'ObjectProperty' ||
73+
node.parentElement.isPattern
74+
) {
7175
return parentCheck(node.parentElement);
7276
}
7377
} else {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ describe('rules/disallow-unused-variables', function() {
3030
.to.have.no.errors();
3131
});
3232

33+
it('should not report unused for function expressions', function() {
34+
expect(checker.checkString('var z = function x() { }; z++;'))
35+
.to.have.no.errors();
36+
});
37+
38+
it('should not report unused for function params', function() {
39+
expect(checker.checkString('var z = function x(f) { }; z++;'))
40+
.to.have.no.errors();
41+
});
42+
3343
it('should not report unused variable defined with let within a function declaration', function() {
3444
expect(checker.checkString('function x() { let y=1; return y; }'))
3545
.to.have.no.errors();

0 commit comments

Comments
 (0)