gajus / eslint-plugin-jsdoc

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

Fails to detect missing JSDoc for static class methods. #1203

Closed Pik-9 closed 9 months ago

Pik-9 commented 9 months ago

Expected behavior

ESLint should report a "Missing JSDoc comment" rule violation for the first function as well as for the static class function.

Actual behavior

It only reports the the first missing JSDoc, but not the undocumented static class function.

ESLint Config

Pretty much the standard configuration with the AirBnB style:

module.exports = {
  env: {
    browser: true,
    es2021: true,
    node: true,
  },
  extends: [
    'airbnb-base',
    'plugin:jsdoc/recommended-error',
  ],
  overrides: [
    {
      env: {
        node: true,
      },
      files: [
        '.eslintrc.{js,cjs}',
      ],
      parserOptions: {
        sourceType: 'script',
      },
    },
  ],
  parserOptions: {
    ecmaVersion: 'latest',
    sourceType: 'module',
  },
  plugins: [
    'jsdoc',
  ],
  rules: {
  },
};

ESLint sample

function undocumentedFunction() {
  // This undocumented function will be reported.
  return 42;
}

class MyClass {
  static undocumentedStaticClassFunction() {
    // This one won't.
    return 'What does this function do? No one knows.';
  }
}

export { undocumentedFunction, MyClass };

Environment

brettz9 commented 9 months ago

You need to enable MethodDefinition under the require or contexts option:

    rules: {
      'jsdoc/require-jsdoc': ['error', {
        require: {
          MethodDefinition: true,
        },
      }]
    }

Closing as that should resolve, but feel free to comment further as needed.