Skip to content

Commit b88ad6b

Browse files
committed
checkRedundantParams: fixed error with dotted params
Fixes #79
1 parent fa260db commit b88ad6b

File tree

2 files changed

+73
-3
lines changed

2 files changed

+73
-3
lines changed

lib/rules/validate-jsdoc/check-redundant-params.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ function validateCheckParamNames(node, err) {
1414
return;
1515
}
1616

17+
var skipped = 0;
18+
1719
node.jsdoc.iterateByType(['param', 'arg', 'argument'],
1820
/**
1921
* tag checker
@@ -23,15 +25,23 @@ function validateCheckParamNames(node, err) {
2325
function(tag, i) {
2426
// skip if there is dot in param name (object's inner param)
2527
if (tag.name && tag.name.value.indexOf('.') !== -1) {
28+
skipped++;
2629
return;
2730
}
2831

29-
var param = node.params[i];
3032
var _optional = tag.optional || (tag.type && (tag.type.optional || tag.type.variable));
33+
if (_optional) {
34+
skipped++;
35+
return;
36+
}
37+
38+
var param = node.params[i - skipped];
3139

3240
// checking redundant
33-
if (!_optional && !param) {
34-
return err('redundant param statement');
41+
if (!param) {
42+
return err('Found redundant ' +
43+
(tag.name ? 'param "' + tag.name.value + '"' : 'unnamed param') +
44+
' statement', tag.loc);
3545
}
3646
});
3747
}

test/lib/rules/validate-jsdoc/check-redundant-params.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,66 @@ describe('lib/rules/validate-jsdoc/check-redundant-params', function () {
115115
*/
116116
function setTimeout(callback, delay) {}
117117
}
118+
}, {
119+
// issue #79
120+
it: 'should not report different names',
121+
code: function() {
122+
/**
123+
* Example function
124+
* @param {Object} options - some options
125+
* @param {number} options.id - some id
126+
* @param {Array} rest - rest arguments
127+
*/
128+
function hello(options, rest) {
129+
return (options.filename) ? true : false;
130+
}
131+
},
132+
errors: []
133+
}, {
134+
// issue #79
135+
it: 'should report with right location',
136+
code: function() {
137+
/**
138+
* @param {Object} options - some options
139+
* @param {Array} rest - rest arguments
140+
*/
141+
function hello(options) {
142+
}
143+
},
144+
errors: [{
145+
column: 3, line: 3, filename: 'input', rule: 'jsDoc',
146+
message: 'Found redundant param "rest" statement'
147+
}]
148+
}, {
149+
it: 'should not report optional params',
150+
code: function() {
151+
/**
152+
* Example function
153+
* @param {Object} options - some options
154+
* @param {number} options.id - some id
155+
* @param {Go} [optional] - optional param
156+
* @param {Go=} optional2 - another optional param
157+
* @param {Array} rest - rest arguments
158+
*/
159+
function hello(options, rest) {
160+
}
161+
},
162+
errors: []
163+
}, {
164+
it: 'should not report declared optional params',
165+
code: function() {
166+
/**
167+
* Example function
168+
* @param {Object} options - some options
169+
* @param {number} options.id - some id
170+
* @param {Go} [optional] - optional param
171+
* @param {Go=} optional2 - another optional param
172+
* @param {Array} rest - rest arguments
173+
*/
174+
function hello(options, optional, optional2, rest) {
175+
}
176+
},
177+
errors: []
118178
}
119179
/* jshint ignore:end */
120180
]);

0 commit comments

Comments
 (0)