gajus / eslint-plugin-jsdoc

JSDoc specific linting rules for ESLint.
Other
1.08k stars 155 forks source link

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

Open iliubinskii opened 3 years ago

iliubinskii commented 3 years ago

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!](https://app.bountysource.com/issues/99894844-jsdoc-require-jsdoc-false-positive-when-documentation-is-inherited-from-interface?utm_campaign=plugin&utm_content=tracker%2F23037809&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://app.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F23037809&utm_medium=issues&utm_source=github).
brettz9 commented 3 years ago

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.

DerZyklop commented 1 month ago

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).