Skip to content

Feature Request: Require single line JSDoc for short comments #724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
danvk opened this issue May 10, 2021 · 4 comments
Closed

Feature Request: Require single line JSDoc for short comments #724

danvk opened this issue May 10, 2021 · 4 comments

Comments

@danvk
Copy link

danvk commented May 10, 2021

Motivation

There are two basic forms of JSDoc comment:

/** single line */

/**
 * multiline
 * jsdoc
 * comment
 */

For short comments, I consider the multiline form a waste of space. For example, instead of:

/**
 * Process the inputs and return an output.
 */
function f(x) { ... }

I'd like to enforce that this be written using single line form:

/** Process the inputs and return an output. */
function f(x) { ... }

Current behavior

I believe this would have to be a new rule.

Desired behavior

I'd like to be able to configure a maximum line length for JSDoc comments and have eslint-plugin-jsdoc enforce that JSDoc comments shorter than this use the single-line form, whereas JSDoc comments longer than this use the multiline form.

Configuration might be something like:

{
  'jsdoc/prefer-single-line': ['error', 'always', {
    maxLineLength: 95
  }]
}

Alternatives considered

None

@danvk danvk changed the title Require single line jsdoc for short comments Feature Request: Require single line jsdoc for short comments May 10, 2021
@danvk danvk changed the title Feature Request: Require single line jsdoc for short comments Feature Request: Require single line JSDoc for short comments May 10, 2021
@brettz9
Copy link
Collaborator

brettz9 commented May 10, 2021

Did you want this only when there were no tags or also for tags? (If the latter, I think we should at least allow tags like @example to avoid the need for single line.)

I suggest we combine this proposed rule into one which also allows optional support for the opposite--what is detailed at the end of #199 (comment) , namely forbidding single-line comments (except when accompanied by specific whitelisted tags like @lends).

@danvk
Copy link
Author

danvk commented May 10, 2021

@brettz9 that makes sense to me. I'm usually working in TypeScript, where there's less need for tags, but I can see why you'd want @example to be multiline.

Do you want me to comment on the other issue and close this out?

@brettz9
Copy link
Collaborator

brettz9 commented May 10, 2021

Sure, as you like. I'll go ahead and summarize your idea in that same comment, as I've turned it into a kind of wiki.

@danvk
Copy link
Author

danvk commented May 10, 2021

Great! Closing in favor of #199 (comment)

@danvk danvk closed this as completed May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants