diff --git a/lib/rules/validate-jsdoc/check-param-names.js b/lib/rules/validate-jsdoc/check-param-names.js index 9916030..b951043 100644 --- a/lib/rules/validate-jsdoc/check-param-names.js +++ b/lib/rules/validate-jsdoc/check-param-names.js @@ -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); } diff --git a/test/lib/rules/validate-jsdoc/check-param-names.js b/test/lib/rules/validate-jsdoc/check-param-names.js index 2e33416..9db1921 100644 --- a/test/lib/rules/validate-jsdoc/check-param-names.js +++ b/test/lib/rules/validate-jsdoc/check-param-names.js @@ -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 */ + ]); + + }); + });