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

jsdoc/require-jsdoc: False positive when documentation is inherited from interface #768

Open
iliubinskii opened this issue Jul 14, 2021 · 2 comments

Comments

@iliubinskii
Copy link

iliubinskii commented Jul 14, 2021

Expected behavior

Method without documentation should pass when there is a documentation for it in an interface located in "implements" section.

I have checked that this situation is correctly handled by typedoc (https://www.npmjs.com/package/typedoc) and vscode editor.
Both extract documentation from interface.

See that vscode undestands this situation:
Sample

Actual behavior

The rule shows error in the situation described above.

ESLint Config

const contexts = [
  ":not(BlockStatement) > FunctionDeclaration",
  "MethodDefinition",
  "TSMethodSignature",
  "TSPropertySignature > TSTypeAnnotation > TSFunctionType"
];

module.exports = {
  rules: {
    "jsdoc/require-jsdoc": [
      "warn",
      {
        checkConstructors: true,
        checkGetters: true,
        checkSetters: true,
        contexts,
        require: {
          ArrowFunctionExpression: false,
          ClassDeclaration: false,
          ClassExpression: false,
          FunctionDeclaration: false,
          FunctionExpression: false,
          MethodDefinition: false
        }
      }
    ]
  }
};

ESLint sample

export interface A {
  /**
   * Documentation.
   */
  f(): void;
}

export class B implements A {
  public f(): void {
    //
  }
}

new B().f();

Environment

    "node": ">=14.0.0",
    "eslint": "^7.30.0",
    "eslint-plugin-jsdoc": "^35.4.3",

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@brettz9
Copy link
Collaborator

brettz9 commented Jul 20, 2021

ESLint is not aware of the whole program, so if we were to support this, it would probably only check the current file. However, this is not something I'm really inclined to spend time on. PR would be fine.

spalladino added a commit to AztecProtocol/aztec-packages that referenced this issue Aug 1, 2023
Our current eslint setup was enforcing all `public` methods in _classes_
to have a jsdoc, but not interfaces. As a result, most of our interfaces
(where we want to have docs the most) were undocumented, and the classes
that implement them carried the documentation instead.

This PR changes the eslint config so we enforce all interface methods to
have documentation. All classes that implement them automatically
inherit their docs (in vscode intellisense and in typedoc), so we don't
need to repeat the docs there and can clean those up. Unfortunately,
`require-jsdoc` cannot detect this automatically (see
gajus/eslint-plugin-jsdoc#768), so we tweak
the config so that jsdoc is not required for methods of classes that
implement an interface (not perfect, but good enough). This new esquery
filter required bumping the version of tslint.

Another issue with our config is that methods that are public by default
(ie without an accessibility modifier) do not have jsdoc enforced. I
tried enabling that but got 148 missing docs - so I'll leave that out
for now, and is commented in the eslintrc file.
@DerZyklop
Copy link

My workaround is usually to add a @see like

export class B implements A {
  /** @see A.f */
  public f(): void {

It works well with require-jsdoc and on hover over the f in B.f(…) you get the correct docs in the editor.


The only downside is that it does not play well with require-param, because require-param does not know the content of A.f (and probably never will).

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

3 participants