jsdoc icon indicating copy to clipboard operation
jsdoc copied to clipboard

JSDoc doesn't generete doc for ES6 functions like export const myFunction = ( ) => ........

Open amtBurgos opened this issue 8 years ago • 17 comments

Input code

When you declare an arrow function with an export like:

/**
 * Description.
 * @param {object} userInfo description
 */
export const setUserInfo = userInfo => ({ userInfo });

The generated documentation takes it like a constant while removing the export the documentation is generated fine.

JSDoc configuration

Default configuration

JSDoc debug output

No output

Expected behavior

should

Current behavior

expected

Your environment

Software Version
JSDoc 3.5.5
Node.js 8.9.4
npm 5.7.1
Operating system Windows 10

amtBurgos avatar Mar 23 '18 14:03 amtBurgos

I encounter the same kind of issue when you declare a class in the export section. ie:

export default class Embedded {
...
}

The best solution to address this, is to declare and export separately :

/**
 * Description.
 * @param {object} userInfo description
 */
const setUserInfo = userInfo => ({ userInfo });

export default setUserInfo;

and I got a documentation's result close to what you wanted: capture d ecran 2018-05-29 a 15 31 45

tetedacier avatar May 29 '18 13:05 tetedacier

I was with the same problem and I didn't find a solution. I have a utils file with multiple exported functions and the 'export default' solution didn't be good in my case. I resolved that putting @method above the @params. Like this:

/**
 * @method
 * @param {String} str
 * @return {String}
*/

I don't if it's the best solution but I hope to help people with the same issue.

yvessacurae avatar Feb 28 '19 14:02 yvessacurae

There is problem with the (arrow or regular) function expression exported (without tag @function, @func or @method).

Input code

/**
 * Foo
 */
export const foo = function () { };

/**
 * Bar
 */
export const bar = () => { };

/**
 * Baz
 * @function
 */
export const baz = function () { };

/**
 * Quz
 */
export function quz() { }

/**
 * Quux
 */
const quux = function () { };

JSDoc

Members

(static, constant) bar Bar

(static, constant) foo Foo

Methods

(static) baz() Baz

(static) quz() Quz

(inner) quux() Quux

regseb avatar Dec 22 '19 14:12 regseb

What is the correct way to document ES6 code with JSDoc as of 2020?

tonix-tuft avatar Apr 19 '20 11:04 tonix-tuft

You need to add @module tag at the start of the document like so

/** @module user */ assuming user is a module name

More info on the docs

ommyjay avatar Apr 29 '20 05:04 ommyjay

document = JS file?

tonix-tuft avatar Apr 29 '20 06:04 tonix-tuft

Yes the JS file

ommyjay avatar Apr 29 '20 07:04 ommyjay

Facing same issue with JSDoc 3.6.4.

Adding /** @module moduleName */ at the top of the file doesn't solve the issue. Only viable solution so far is using @function, which is a bit annoying.

I wonder if we are doing something wrong or if this is an actual bug.

runoncedev avatar May 09 '20 05:05 runoncedev

/**
 * Baz
 * @function
 */
export const baz = function () { };

This works!! Awesome

DocCaliban avatar Dec 24 '20 01:12 DocCaliban

Is adding the @function decorator still the best solution for this? Thoughts, all?

kylekirkby avatar Mar 23 '21 14:03 kylekirkby

Is adding the @function decorator still the best solution for this? Thoughts, all?

This is what I use, in fact, I setup a snippet in VSCODE to auto comment my functions to save me the time of having to remember to add it. Now it's just part of my workflow.

DocCaliban avatar Apr 12 '21 22:04 DocCaliban

Do you guys know why this problem happens?

ghost avatar Jun 23 '21 13:06 ghost

The same problem happens when exporting simple constants like numbers or strings with the @default decorator.

I use this pattern alot: I have a constants.js file which can export lots of constant variables.

/** 
 * a maximum value
 * @constant
 * @type {Number}
 * @default
 */
export const MAX_VALUE = 20;

The @default decorator should add the constant value to the documentation, but it doesn't. If I remove the export, it works.

There is some issue with the ES6 exports here. And in this case, there seems to be no decorator to use as a workaround.

lukastillmann avatar Sep 20 '21 08:09 lukastillmann

Hello, Kinda late, but I figured out a workaround (I guess), but it makes the code looks messy. I named the parameter object, added default values, and then I wrote the description of each parameter inside the deconstructed parameter like this:

export default => ({
     param = {
          /**
          write what you like here
          @see {@link whatever}
          */
          paramName,
          /**
          another description
          */
          anotherParamName
         })
        {
 // your code
}

RiadhAdrani avatar Oct 26 '21 18:10 RiadhAdrani

Just run into this as well while using

export default class Foo {
	// stuff
}

while this worked fine:

class Foo {
	// stuff
}

export default Foo;

LeaVerou avatar Jun 22 '22 14:06 LeaVerou

Has there been any update on this? I'm trying to write a codebase in valid, standard ES2015 (standardized in 2015 I believe) and have typing support, but there doesn't seem to be any tooling that supports it!

Exporting default doesn't work, because one then can't import specific symbols using the import syntax.

Higgs1 avatar Feb 22 '23 15:02 Higgs1

Weirdly it works only if I add @methodOf {modulename} AND @function to each exported function:

/** @module tasks/methods */

/**
 * Creates a new task document
 * @methodOf {tasks/methods}
 * @function
 * @param text {string}
 * @return {string} inserted document _id
 */
export const insertTask = function ({ text }) {
  // ...
}

otherwise it won't get listed with params and return type etc.

jankapunkt avatar Jun 01 '23 06:06 jankapunkt