Skip to content

Enforcing single line JSDoc comments if it fits within a line length #1158

Closed
@jaydenseric

Description

@jaydenseric

It would be great to have a way of enforcing single line JSDoc comments, if the description is a single line, there are no non-inline JSDoc tags, and the last */ characters would fit within a (configurable?) line length of 80 characters, taking into account the current indentation of the comment.

These would be errors:

/**
 * Description.
 */
const foo = true;
/**
 * Description {@linkcode Foo}.
 */
const foo = true;

These would not be errors:

/**
 * Description.
 * @see https://example.example
 */
const foo = true;
/**
 * Multiline description:
 * 
 * - Bullet A.
 * - Bullet B.
 */
const foo = true;
/**
 * [A super long single line description](https://example.example/asdf/asdf/as).
 */
const foo = true;
const foo = {
  a: {
    a: {
      a: {
        a: {
          a: {
            a: {
              a: {
                a: {
                  a: {
                    a: {
                      a: {
                        a: {
                          a: {
                            a: {
                              a: {
                                a: {
                                  a: {
                                    a: {
                                      a: {
                                        /**
                                         * Some description that is this long.
                                         */
                                        a: {},
                                      },
                                    },
                                  },
                                },
                              },
                            },
                          },
                        },
                      },
                    },
                  },
                },
              },
            },
          },
        },
      },
    },
  },
};

Motivation

I regularly review PR's that have many multiline JSDoc comments containing only tiny single line descriptions. They are very verbose and vertically space inefficient; I would like an automated way to ensure such modules have more compact single line JSDoc comments resulting in a smaller module line count.

Current behavior

At first I hoped this would get the desired result:

{
  "jsdoc/multiline-blocks": [
    "error",
    {
      noMultilineBlocks: true,
      minimumLengthForMultiline: 80,
    },
  ],
}

But it seems that minimumLengthForMultiline just counts the length of the description, and doesn't account for the indentation of the comment, etc.

Desired behavior

I would like a new jsdoc/multiline-blocks config option, to enforce the behavior explained above.

Alternatives considered

N/A.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions