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

TypeError with jsdoc/require-jsdoc and certain configurations #613

Closed
joeyparrish opened this issue Jul 20, 2020 · 5 comments
Closed

TypeError with jsdoc/require-jsdoc and certain configurations #613

joeyparrish opened this issue Jul 20, 2020 · 5 comments

Comments

@joeyparrish
Copy link

Expected behavior

No TypeError

Actual behavior

Oops! Something went wrong! :(

ESLint: 7.4.0

TypeError: Cannot read property 'map' of undefined
Occurred while linting /path/to/secret/project/test.js:2
    at Object.getFunctionParameterNames (/path/to/secret/project/node_modules/eslint-plugin-jsdoc/dist/jsdocUtils.js:200:30)
    at checkJsDoc (/path/to/secret/project/node_modules/eslint-plugin-jsdoc/dist/rules/requireJsdoc.js:204:60)
    at listeners.(anonymous function).forEach.listener (/path/to/secret/project/node_modules/eslint/lib/linter/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/path/to/secret/project/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/path/to/secret/project/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/path/to/secret/project/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (/path/to/secret/project/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/path/to/secret/project/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:635:23)
    at nodeQueue.forEach.traversalInfo (/path/to/secret/project/node_modules/eslint/lib/linter/linter.js:949:32)

ESLint Config

module.exports = {
  extends: ['plugin:jsdoc/recommended'],
  parserOptions: {
    ecmaVersion: 2019,
  },
  rules: {
    'jsdoc/require-jsdoc': ['error', {
      contexts: ['MethodDefinition'],
      exemptEmptyConstructors: true,
    }],
  },
};

ESLint sample

class Base {
  constructor() {
  }
}

Environment

  • Node version: v10.21.0
  • ESLint version: v7.4.0
  • eslint-plugin-jsdoc version: 30.0.2
@joeyparrish
Copy link
Author

I found that I can work around it locally by changing:

return functionNode.params.map((param) => {

to:

return (functionNode.params || []).map((param) => {

But I'm not sure if params is supposed be non-null already, or where it comes from. (I don't really understand the codebase well at all.) So this hack might be completely inappropriate.

@joeyparrish
Copy link
Author

Ultimately, I found I was not configuring the plugin correctly for what I wanted to do. So it's possible the config that triggered this bug was not valid. My final config doesn't use contexts, and it doesn't crash on the same code.

@gajus
Copy link
Owner

gajus commented Jul 20, 2020

🎉 This issue has been resolved in version 30.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Jul 20, 2020
@brettz9
Copy link
Collaborator

brettz9 commented Jul 20, 2020

A lot of the mystery goes away if using the likes of https://astexplorer.net/ to follow the AST strucures we are parsing. But we can also no doubt improve our own internal docs.

@joeyparrish
Copy link
Author

Beautiful. Thanks for the quick fix!

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