jscs-dev / jscs-jsdoc

JsDoc validation rules for jscs
MIT License
99 stars 35 forks source link

destructuring parameters fail checkParamNames #90

Closed AlexanderZeilmann closed 9 years ago

AlexanderZeilmann commented 9 years ago

These days I'm often using the following pattern to pass variables to functions

var f = function ({prop1, prop2}) {
  return prop1 + prop2;
};

This leads to the problem, that the destructuring object doesn't have a name, which is required by checkParamNames.

Giving the parameter no name, leads to the Missing param name error

/**
 * [f description]
 *
 * @param  {Object}
---^
 * @return {String} Some string
 */

Giving it a random name leads to the Expected undefined but got object error.

/**
 * [f description]
 *
 * @param  {Object} object
--------------------^
 * @return {String} Some string
 */

Trying to hack it with undefined gives a Parameters undefined and undefined are out of order error.

/**
 * [f description]
 *
 * @param  {Object} undefined
--------------------^
 * @return {String} Some string
 */

My .jscsrc:

  "jsDoc": {
    "checkParamNames": true,
    "checkRedundantParams": true,
    "requireParamTypes": true,
    "checkReturnTypes": true,
    "checkRedundantReturns": true,
    "requireReturnTypes": true,
    "checkTypes": true,
    "checkRedundantAccess": true,
    "leadingUnderscoreAccess": "private",
    "enforceExistence": true,
    "checkAnnotations": true,
    "requireReturnTypes": true,
    "checkRedundantAccess": true,
    "requireHyphenBeforeDescription": true
  },

Is there a way I can get this to work properly? If there is nothing implemented right now, I would suggest automatically disabling the checkParamNames rule for destructuring parameters. Thoughts?

qfox commented 9 years ago

Yeah, I'm not sure about ES6 support for now. ;-( Thanks for the report, at the first look I agreed with you.

But probably there is a way to check them as a usual case. Do you really need to describe {Object} as separate @param?

I would suggest to use:

/**
 * @param {Object} anyName
 * @param {String} anyName.prop1
 * @param {Number} anyName.prop2
 */

But for now it's easier to disable these validations and when ES6 will be jsdocable — just integrate them back.

Would you like to tackle this?

AlexanderZeilmann commented 9 years ago

Hmm, yeah perhaps it is a little bit to early to do stuff like this. Especially since JSDoc currently requires the name of the parameter. I opened a bug regarding this topic over at the jsdoc repo: https://github.com/jsdoc3/jsdoc/issues/987

Anyway, I created a pull request over at #92.