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

Don't require Docs for short methods in require-jsdoc #870

Closed
nrauschcom opened this issue Apr 11, 2022 · 3 comments · Fixed by #871
Closed

Don't require Docs for short methods in require-jsdoc #870

nrauschcom opened this issue Apr 11, 2022 · 3 comments · Fixed by #871

Comments

@nrauschcom
Copy link

nrauschcom commented Apr 11, 2022

Motivation

Using the require-jsdoc rule, we currently have no way of excluding "trivial" methods, so we have to write many comments that just paraphrase the method name. In Java-Checkstyle, we have the option of excluding methods with less than n rows, where n can be specified with the parameter minLineCount (https://checkstyle.sourceforge.io/apidocs/com/puppycrawl/tools/checkstyle/checks/javadoc/MissingJavadocMethodCheck.html).

We already have similar options for get/set accessors and we can exclude specific things like constructors using the context property, but especially for projects using method getters/setters instead of JavaScript accessors, I think such a parameter would improve the usability of the rule. My projects are not using accessors because I believe it is an antipattern (https://www.reddit.com/r/typescript/comments/87t1h7/are_getters_and_setters_an_antipattern/) but I would really like to enforce comments for more complex methods.

Current behavior

Currently, we would have to write parapharasing comments to our getters/setters in a project:

/**
 * Returns the ID of this object.
**/
getId(): number {
  return this.id;
}

/**
 * Sets the ID of this object.
 * @param newId the new ID of this object
**/
setId(newId: number): void {
  this.id = id;
}

Desired behavior

I would like to set a property like "minLineCount": 2 in my .eslintrc.json to suppress warings for one-liner methods. This would result in the code above not needing comments, and we would not have to write the same thing in three rows:

getId(): number {
  return this.id;
}

setId(newId: number): void {
  this.id = id;
}

Alternatives considered

Currently we have the option of disabling the rule for get and set accessors, so we could consider implementing a "detection" mechanism for plain getter and setter methods (e.g. should be simple using a regular expression). However, since people are already using minLineCount in a Java/CheckStyle context, I think that one would be the easier-to-implement and more convenient option.

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Apr 11, 2022
@brettz9
Copy link
Collaborator

brettz9 commented Apr 11, 2022

I submitted #871 to handle this. I allowed for both a global minLineCount and a context-specific one (since one might want different lengths for variables, functions, etc.). Note that we count the whole length of the node, e.g, 3 lines for your methods (a method technically could be just a () { /* one line */ }).

@nrauschcom
Copy link
Author

@brettz9 you rock! thanks for implementing this so fast.
In my case, implementing methods in a single line is not allowed anyway, so this solution perfectly fits my use-case.
Hope the other maintainers find this useful as well.

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Apr 11, 2022
brettz9 added a commit that referenced this issue Apr 12, 2022
@gajus
Copy link
Owner

gajus commented Apr 12, 2022

🎉 This issue has been resolved in version 39.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Apr 12, 2022
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this issue Apr 13, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) | devDependencies | minor | [`39.1.0` -> `39.2.1`](https://renovatebot.com/diffs/npm/eslint-plugin-jsdoc/39.1.0/39.2.1) |

---

### Release Notes

<details>
<summary>gajus/eslint-plugin-jsdoc</summary>

### [`v39.2.1`](https://github.com/gajus/eslint-plugin-jsdoc/releases/v39.2.1)

[Compare Source](gajus/eslint-plugin-jsdoc@v39.2.0...v39.2.1)

##### Bug Fixes

-   regression with checking TS MethodDefinition params ([041de5f](gajus/eslint-plugin-jsdoc@041de5f))

### [`v39.2.0`](https://github.com/gajus/eslint-plugin-jsdoc/releases/v39.2.0)

[Compare Source](gajus/eslint-plugin-jsdoc@v39.1.1...v39.2.0)

##### Features

-   **`require-jsdoc`:** add `minLineCount` option to avoid reporting short functions/contexts; fixes [#&#8203;870](gajus/eslint-plugin-jsdoc#870) ([199aa4a](gajus/eslint-plugin-jsdoc@199aa4a))
-   support inline `minLineCount` ([288363e](gajus/eslint-plugin-jsdoc@288363e))

### [`v39.1.1`](https://github.com/gajus/eslint-plugin-jsdoc/releases/v39.1.1)

[Compare Source](gajus/eslint-plugin-jsdoc@v39.1.0...v39.1.1)

##### Bug Fixes

-   **`require-jsdoc`:** detect ClassDeclaration as referenced public export and ClassExpression methods; fixes [#&#8203;648](gajus/eslint-plugin-jsdoc#648) ([520c7be](gajus/eslint-plugin-jsdoc@520c7be))

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1300
Reviewed-by: crapStone <crapstone@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants