gajus / eslint-plugin-jsdoc

JSDoc specific linting rules for ESLint.
Other
1.1k stars 160 forks source link

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

Open ehoogeveen-medweb opened 3 months ago

ehoogeveen-medweb commented 3 months ago

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

JoshuaKGoldberg commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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

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

(assuming also https://github.com/gajus/eslint-plugin-jsdoc/issues/1296) looks reasonable to me.

JoshuaKGoldberg commented 5 days ago

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 commented 5 days ago

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

JoshuaKGoldberg commented 4 days ago

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

brettz9 commented 4 days ago

@JoshuaKGoldberg : SGTM!