Skip to content

Commit

Permalink
checkParamNames: prevent failing on destructuring, and allow fake arg…
Browse files Browse the repository at this point in the history
…uments

Fixes #90
Closes gh-92
  • Loading branch information
AlexanderZeilmann authored and Alexej Yaroshevich committed May 3, 2015
1 parent 231b359 commit e754b46
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/rules/validate-jsdoc/check-param-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ function validateCheckParamNames(node, err) {
* @param {number} i index
*/
function(tag, i) {
// checking validity
// There is no parameter name in destructuring assignments.
if (node.params[i - skipped] && node.params[i - skipped].name === undefined) {
// So if there is no tag name or the tag name does not contain '.', there is nothing to check.
if (!tag.name || tag.name.value.indexOf('.') === -1) {
lastRootParamTag = tag;
return;
}
}

// Сhecking validity
if (!tag.name) {
return err('Missing param name', tag.loc);
}
Expand Down
96 changes: 96 additions & 0 deletions test/lib/rules/validate-jsdoc/check-param-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,100 @@ describe('lib/rules/validate-jsdoc/check-param-names', function() {

});

describe('with destructurings', function() {
var checker = global.checker({
plugins: ['./lib/index'],
esnext: true
});
checker.rules({checkParamNames: true});

checker.cases([
/* jshint ignore:start */
// jscs:disable
{
it: 'should not report missing parameter name for object destructurings',
code: [
'/**',
' * @param {object}',
' */',
'function obj({param}) {',
'}'
].join('\n')
}, {
it: 'should not report missing parameter name for object destructurings',
code: [
'/**',
' * @param {object}',
' */',
'function obj({param: newName}) {',
'}'
].join('\n')
}, {
it: 'should not fail if a fake parameter name is provided',
code: [
'/**',
' * @param {object} fakeName - description',
' */',
'function obj({param}) {',
'}'
].join('\n')
}, {
it: 'should not fail if a fake parameter name and property description is provided',
code: [
'/**',
' * @param {object} fakeName - description',
' * @param {object} fakeName.param - description',
' */',
'function obj({param}) {',
'}'
].join('\n')
}, {
it: 'should report different fake parameter name',
code: [
'/**',
' * @param {object} fakeName - description',
' * @param {object} notFakeName.param - description',
' */',
'function obj({param}) {',
'}'
].join('\n'),
errors: [
{
column: 19,
filename: 'input',
line: 3,
message: 'Expected `fakeName` but got `notFakeName`',
rule: 'jsDoc',
fixed: undefined
}
]
}, {
it: 'should not report an error when used next to parameters with properties',
code: [
'/**',
' * @param {object} obj1',
' * @param {string} obj1.property',
' * @param {object}',
' * @param {object} obj2',
' * @param {string} obj2.property',
' */',
'function obj(obj1, {param}, obj2) {',
'}'
].join('\n')
}, {
it: 'should not report missing parameter name for array destructurings',
code: [
'/**',
' * @param {array}',
' */',
'function arr([param]) {',
'}'
].join('\n')
}
// jscs:enable
/* jshint ignore:end */
]);

});

});

0 comments on commit e754b46

Please sign in to comment.