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

[require-jsdoc] Require JSDoc only either for the getter or the setter #515

Closed
manuth opened this issue Apr 13, 2020 · 3 comments · Fixed by #694, xiaohai2271/blog-frontEnd#92, MatthewCallis/super-pads#38 or getnova/components#81 · May be fixed by sivrad/skb-collection-ts#1

Comments

@manuth
Copy link
Contributor

manuth commented Apr 13, 2020

People might want to add a comment for a getter/setter pair only once rather than writing two comments:

class TestClass {
    constructor() {
        this.id = 1;
    }

    /**
     * Gets or sets the ID.
     */
    get ID() {
        return this.id;
    }

    set ID(value) {
        this.id = value;
    }
}

instead of this:

class TestClass {
    constructor() {
        this.id = 1;
    }

    /**
     * Gets or sets the ID.
     */
    get ID() {
        return this.id;
    }

    /**
     * @inheritdoc
     */
    set ID(value) {
        this.id = value;
    }
}
@brettz9
Copy link
Collaborator

brettz9 commented May 19, 2020

If you always put your get and set in that order, you could use the sibling selector, e.g., in this example excluding docs on a getter or setter followed by a setter or getter respectively (or on a constructor):

{
          contexts: [
            'MethodDefinition:not([kind="constructor"],[kind="get"],[kind="set"])',
            'MethodDefinition[kind="get"]:not(MethodDefinition[kind="set"] + MethodDefinition[kind="get"])',
            'MethodDefinition[kind="set"]:not(MethodDefinition[kind="get"] + MethodDefinition[kind="set"])',
          ]

However, this does not take into account method name, so for example, while this would as desired, only require docs on the first block:

          get ID() {
              return this.id;
          }

          set ID(value) {
              this.id = value;
          }

...so too would this:

          get something() {
              return this.id;
          }

          set ID(value) {
              this.id = value;
          }

@ocket8888
Copy link

I think having only a get is much more common than only a set, so at a minimum I think even just having an option like "checkSetters": "no-getter" to only check sets when there's no get by the same name would be a great improvement.

brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Feb 15, 2021
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Feb 16, 2021
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Feb 16, 2021
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Feb 16, 2021
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Feb 16, 2021
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Feb 16, 2021
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Feb 16, 2021
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Feb 16, 2021
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Feb 16, 2021
brettz9 added a commit to brettz9/eslint-plugin-jsdoc that referenced this issue Feb 21, 2021
@gajus
Copy link
Owner

gajus commented Feb 21, 2021

🎉 This issue has been resolved in version 32.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

This was referenced Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment