Skip to content

Commit e754b46

Browse files
AlexanderZeilmannAlexej Yaroshevich
authored andcommitted
checkParamNames: prevent failing on destructuring, and allow fake arguments
Fixes #90 Closes gh-92
1 parent 231b359 commit e754b46

File tree

2 files changed

+106
-1
lines changed

2 files changed

+106
-1
lines changed

lib/rules/validate-jsdoc/check-param-names.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,16 @@ function validateCheckParamNames(node, err) {
3636
* @param {number} i index
3737
*/
3838
function(tag, i) {
39-
// checking validity
39+
// There is no parameter name in destructuring assignments.
40+
if (node.params[i - skipped] && node.params[i - skipped].name === undefined) {
41+
// So if there is no tag name or the tag name does not contain '.', there is nothing to check.
42+
if (!tag.name || tag.name.value.indexOf('.') === -1) {
43+
lastRootParamTag = tag;
44+
return;
45+
}
46+
}
47+
48+
// Сhecking validity
4049
if (!tag.name) {
4150
return err('Missing param name', tag.loc);
4251
}

test/lib/rules/validate-jsdoc/check-param-names.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,4 +367,100 @@ describe('lib/rules/validate-jsdoc/check-param-names', function() {
367367

368368
});
369369

370+
describe('with destructurings', function() {
371+
var checker = global.checker({
372+
plugins: ['./lib/index'],
373+
esnext: true
374+
});
375+
checker.rules({checkParamNames: true});
376+
377+
checker.cases([
378+
/* jshint ignore:start */
379+
// jscs:disable
380+
{
381+
it: 'should not report missing parameter name for object destructurings',
382+
code: [
383+
'/**',
384+
' * @param {object}',
385+
' */',
386+
'function obj({param}) {',
387+
'}'
388+
].join('\n')
389+
}, {
390+
it: 'should not report missing parameter name for object destructurings',
391+
code: [
392+
'/**',
393+
' * @param {object}',
394+
' */',
395+
'function obj({param: newName}) {',
396+
'}'
397+
].join('\n')
398+
}, {
399+
it: 'should not fail if a fake parameter name is provided',
400+
code: [
401+
'/**',
402+
' * @param {object} fakeName - description',
403+
' */',
404+
'function obj({param}) {',
405+
'}'
406+
].join('\n')
407+
}, {
408+
it: 'should not fail if a fake parameter name and property description is provided',
409+
code: [
410+
'/**',
411+
' * @param {object} fakeName - description',
412+
' * @param {object} fakeName.param - description',
413+
' */',
414+
'function obj({param}) {',
415+
'}'
416+
].join('\n')
417+
}, {
418+
it: 'should report different fake parameter name',
419+
code: [
420+
'/**',
421+
' * @param {object} fakeName - description',
422+
' * @param {object} notFakeName.param - description',
423+
' */',
424+
'function obj({param}) {',
425+
'}'
426+
].join('\n'),
427+
errors: [
428+
{
429+
column: 19,
430+
filename: 'input',
431+
line: 3,
432+
message: 'Expected `fakeName` but got `notFakeName`',
433+
rule: 'jsDoc',
434+
fixed: undefined
435+
}
436+
]
437+
}, {
438+
it: 'should not report an error when used next to parameters with properties',
439+
code: [
440+
'/**',
441+
' * @param {object} obj1',
442+
' * @param {string} obj1.property',
443+
' * @param {object}',
444+
' * @param {object} obj2',
445+
' * @param {string} obj2.property',
446+
' */',
447+
'function obj(obj1, {param}, obj2) {',
448+
'}'
449+
].join('\n')
450+
}, {
451+
it: 'should not report missing parameter name for array destructurings',
452+
code: [
453+
'/**',
454+
' * @param {array}',
455+
' */',
456+
'function arr([param]) {',
457+
'}'
458+
].join('\n')
459+
}
460+
// jscs:enable
461+
/* jshint ignore:end */
462+
]);
463+
464+
});
465+
370466
});

0 commit comments

Comments
 (0)