documentation icon indicating copy to clipboard operation
documentation copied to clipboard

Support standard class constructor JSDoc

Open jaydenseric opened this issue 7 years ago • 3 comments

The way that documentation.js forces us to document classes is incorrect:

/**
 * A foo.
 * @param {*} value Value.
 */
class Foo {
  constructor(value) {
    this.value = value
  }
}

Here is the standard way:

/**
 * A foo.
 */
class Foo {
  /**
   * Constructs a new foo.
   * @param {*} value Value.
   */
  constructor(value) {
    this.value = value
  }
}

Attempting to use the standard approach will result in documentation not appearing, or the constructor docs take over the class description.

Not only is the documentation.js way unintuitive and a common gotcha, but it causes problems using JSDoc linters that expect a standard approach. This ESLint config will report an error that the constructor is missing JSDoc:

{
  "rules": {
      "require-jsdoc": ["error", {
        "require": {
          "ClassDeclaration": true,
          "MethodDefinition": true
        }
      }]
    }
}

There is no way to configure the ESLint require-jsdoc to ignore constructor. You can't use normal eslint ignore rule directive comments (// eslint-disable-next-line require-jsdoc) as a workaround due to https://github.com/documentationjs/documentation/issues/1090. You're just stuck 😔

As part of a fix:

Related:

  • https://github.com/documentationjs/documentation/issues/109

jaydenseric avatar Jun 12 '18 06:06 jaydenseric

I was wondering why my constructor wasn't being outputted in all the documentation. This explains it.

I really hope this can get fixed.

balupton avatar Jul 11 '18 23:07 balupton

@balupton Same here, I was oblivious as to why the documentation wasn't showing anything from the constructor's doclet when it was valid.

Berkmann18 avatar Nov 13 '18 10:11 Berkmann18

Please peruse the current maintenance status. I eagerly review and merge PRs, so the way to get this done is by doing it.

tmcw avatar Nov 13 '18 15:11 tmcw