Skip to content
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

Option for lines-before-block to ignore single-line jsdoc comments #1295

Open
ehoogeveen-medweb opened this issue Aug 7, 2024 · 7 comments

Comments

@ehoogeveen-medweb
Copy link

Motivation

When documenting parameters, simple single-line descriptions can be enough. For example:

/** The parameters for a request */
export type RequestParams = {
	/** The year to retrieve. */
	year: `${number}`;
	/** The month to retrieve. */
	month: `${number}`;
}

In this case, I don't think newlines before the jsdoc comments add any value.

Current behavior

The rule warns even with ignoreSameLine: true, as the jsdoc is on a separate line.

Desired behavior

Don't warn if the jsdoc fits on a single line.

Alternatives considered

  • Don't warn if the jsdoc fits on a single line and only contains a description. That would be enough for the example above, but another use case is providing type information for a variable on the next line in javascript, and I don't think requiring a preceding newline helps much there either.
@JoshuaKGoldberg
Copy link
Contributor

IMO this option would be best enabled by default. This succinct / one-line style is pretty common in projects, and it's surprising for many to see the linter report against it.

@thernstig
Copy link

thernstig commented Aug 13, 2024

Although, if it was a /** @type {string[]} */ e.g. for a top-level variable I would expect it to have a line break before. Tricky.

@ehoogeveen-medweb
Copy link
Author

I'm not sure I would want to enforce it:

function foo() {
  /** @type { string[] | undefined } */
  let myStringArray;
  /** @type { number[] | undefined } */
  let myNumberArray;
  // ...
}

(assuming also #1296) looks reasonable to me.

@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Nov 25, 2024

Checking in, sorry for the ping @gajus. I just want to confirm - would you be open to a PR that makes checking single-line JSDoc comments an opt-in option?

(same question for #1296)

@gajus
Copy link
Owner

gajus commented Nov 25, 2024

I am not person to ask. @brettz9 has been maintaining this repo the past several years.

@JoshuaKGoldberg
Copy link
Contributor

Ah sorry! Same question on these two issues for @brettz9 then 🙂

@brettz9
Copy link
Collaborator

brettz9 commented Nov 25, 2024

@JoshuaKGoldberg : SGTM!

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

5 participants