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

Commit ea1ebb9

Browse files
committed
disallowUnusedParams: notice AssignmentPattern nodes
Fixes #2254
1 parent e948d70 commit ea1ebb9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/rules/disallow-unused-params.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
var assert = require('assert');
3838

3939
function getUnusedNodes(node, variableMap, groupIfPossible) {
40+
if (node.type === 'AssignmentPattern') {
41+
return getUnusedNodes(node.left, variableMap, groupIfPossible);
42+
}
43+
4044
if (node.type === 'Identifier') {
4145
var variable = variableMap[node.name];
4246

@@ -94,6 +98,8 @@ function getUnusedNodes(node, variableMap, groupIfPossible) {
9498
}
9599
return unusedObjectNodes;
96100
}
101+
102+
return [];
97103
}
98104

99105
function isComma(token) {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ 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() {
20+
it('should not report even with eval expression (gh-1943)', function() {
2121
expect(checker.checkString('function foo(options) { return options; eval() };'))
2222
.to.have.no.errors();
2323
});
@@ -40,6 +40,11 @@ describe('rules/disallow-unused-params', function() {
4040
).getErrorList()[0].message).to.contain('Param `test` is not used');
4141
});
4242

43+
it('should report for AssignmentPattern (gh-2254)', function() {
44+
expect(checker.checkString('function foo(options = {}) {};')
45+
.getErrorList()[0].message).to.contain('Param `options` is not used');
46+
});
47+
4348
it('should report unused param in function expression', function() {
4449
expect(checker.checkString(
4550
'(function(test) { })'

0 commit comments

Comments
 (0)