docblockr icon indicating copy to clipboard operation
docblockr copied to clipboard

JavaScript destructuring

Open DdZ-Fred opened this issue 8 years ago • 6 comments

Hi everyone!

I thought recognizing destructuring in function params could be a good enhancement! This is the actual result when it is used:

/**
 * [handleRecaptchaErrors description]
 * @param  {[type]} res        [description]
 * @param  {[type]} {          status        [description]
 * @param  {[type]} statusText [description]
 * @param  {[type]} config     }             [description]
 * @return {[type]}            [description]
 */
export function handleRecaptchaErrors(res, { status, statusText, config }) {
  // Code here
}

Getting something similar to this could be convenient:

/**
 * Handles the errors that can occur when requesting the reCatpcha API
 * @param  {Object} res                      [HTTP response of the /contactMe resource]
 * @param  {Object} recaptchaRequestResponse [Axios response received requesting the reCaptcha API]
 *         @property  {Number}  status       [Status code]
 *         @property  {String}  statusText   [Status message]
 *         @property  {Object}  config       [Original axios request config]
 */
 export function handleRecaptchaErrors(res, { status, statusText, config }) {
  // Code here
}

That being said, I'm really not comfortable with RegExp (...I should start learning) so not sure I can implement this myself

DdZ-Fred avatar May 22 '16 14:05 DdZ-Fred

Hey there!

Same goes when you use ES6 Spread Operator as function parameter:

/**
 * [example description]
 * @param  {[type]} prop     [description]
 * @param  {[type]} ...props [description]
 * @return {[type]}          [description]
 */
function example (prop, ...props) {
  // Code here
}

I do not have a good idea how to handle Spread Operator parameters. Maybe just defining their type to be Array :thought_balloon:

dirchev avatar Aug 01 '16 13:08 dirchev

@dirchev could you please open a new issue for adding support for the spread operator.

MoritzKn avatar Sep 09 '16 22:09 MoritzKn

This should be addressed with some prio cause it's causing exceptions (See #219 and #197).

MoritzKn avatar Sep 09 '16 22:09 MoritzKn

I do not have a good idea how to handle Spread Operator parameters. Maybe just defining their type to be Array

The coder may want to make it Array<{type}> so maybe that should be the placeholder.

sompylasar avatar Sep 10 '16 07:09 sompylasar

+1 on this issue

noahehall avatar Dec 20 '16 07:12 noahehall

With docblockr 0.13.7 and atom 1.31.2, the package correctly handles

function foo(x, {a, b}) { /* etc */ }
// results in 
/**
 * [foo description]
 * @param  {[type]} x [description]
 * @param  {[type]} a [description]
 * @param  {[type]} b [description]
 * @return {[type]}   [description]
 */

but

function bar(x, {a, b} = {a: 1, b: "2"}) {/* etc */}
// results in
/**
 * [foo description]
 * @param  {[type]} x [description]
 * @param  {[type]} a [description]
 * @param  {[type]} b [description]
 * @param  {[type]} b [description]
 * @return {[type]}   [description]
 */

No errors or docblockr-related warnings are written to the console.

SKalt avatar Oct 16 '18 14:10 SKalt