gajus / eslint-plugin-jsdoc

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

require-jsdoc fails on classes with static block #1312

Closed patricklx closed 1 month ago

patricklx commented 1 month ago

Expected behavior

report missing jsdoc on classes that also have static blocks

Actual behavior

fails with a type error

TypeError: Cannot read properties of undefined (reading 'name')
Occurred while linting /.../test.js:1
Rule: "jsdoc/require-jsdoc"
    at getSymbol (.../node_modules/.pnpm/eslint-plugin-jsdoc@50.2.2_eslint@8.57.0_supports-color@9.4.0__supports-color@9.4.0/node_modules/eslint-plugin-jsdoc/dist/exportParser.cjs:194:125)

The code could probably be enhanced to handle unknown types so that new things that come up can be handled

ESLint Config

module.exports = {
  root: true,
  parser: '@babel/eslint-parser',
  parserOptions: {
    ecmaVersion: 'latest',
    sourceType: 'module',
    requireConfigFile: false,
    babelOptions: {
      root: __dirname,
    },
  },
  plugins: ['jsdoc'],
  extends: [
    'plugin:jsdoc/recommended',
  ],
  rules: {
    'jsdoc/require-description': 'warn',
    'jsdoc/require-jsdoc': ["error", {"publicOnly":true,"require":{"ClassDeclaration":true}}],
  },
}

ESLint sample

class Abc {
    static {
        this.x = '2'
    }
}

Environment

github-actions[bot] commented 1 month ago

:tada: This issue has been resolved in version 50.2.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

brettz9 commented 1 month ago

Thanks for the report. Fixed by #1313 .

With AST, there can be changes that break our assumptions, and it is not always easy to anticipate what these will be (or if it is, it can be cumbersome to handle every path). Feel free to report if these come up again, and we can hopefully give quick turnaround.