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

Commit

Permalink
disallowUnusedParams: notice AssignmentPattern nodes
Browse files Browse the repository at this point in the history
Fixes #2254
  • Loading branch information
markelog committed Jun 4, 2016
1 parent e948d70 commit ea1ebb9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/rules/disallow-unused-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
var assert = require('assert');

function getUnusedNodes(node, variableMap, groupIfPossible) {
if (node.type === 'AssignmentPattern') {
return getUnusedNodes(node.left, variableMap, groupIfPossible);
}

if (node.type === 'Identifier') {
var variable = variableMap[node.name];

Expand Down Expand Up @@ -94,6 +98,8 @@ function getUnusedNodes(node, variableMap, groupIfPossible) {
}
return unusedObjectNodes;
}

return [];
}

function isComma(token) {
Expand Down
7 changes: 6 additions & 1 deletion test/specs/rules/disallow-unused-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('rules/disallow-unused-params', function() {
expect(checker.checkString('function a(b, c) { return c; };')).to.have.no.errors();
});

it('should report even with eval expression (gh-1943)', function() {
it('should not report even with eval expression (gh-1943)', function() {
expect(checker.checkString('function foo(options) { return options; eval() };'))
.to.have.no.errors();
});
Expand All @@ -40,6 +40,11 @@ describe('rules/disallow-unused-params', function() {
).getErrorList()[0].message).to.contain('Param `test` is not used');
});

it('should report for AssignmentPattern (gh-2254)', function() {
expect(checker.checkString('function foo(options = {}) {};')
.getErrorList()[0].message).to.contain('Param `options` is not used');
});

it('should report unused param in function expression', function() {
expect(checker.checkString(
'(function(test) { })'
Expand Down

0 comments on commit ea1ebb9

Please sign in to comment.