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

no-undefined-types: Cannot read property 'value' of null when function nested inside arrow function #561

Closed
nikolay-borzov opened this issue Jun 4, 2020 · 2 comments

Comments

@nikolay-borzov
Copy link

nikolay-borzov commented Jun 4, 2020

Expected behavior

No error when parsing JSDoc comment for function declared inside an arrow function

Actual behavior

TypeError: Cannot read property 'value' of null
Occurred while linting documents.js:6
    at parseComment (node_modules\eslint-plugin-jsdoc\dist\iterateJsdoc.js:46:64)
    at node_modules\eslint-plugin-jsdoc\dist\rules\noUndefinedTypes.js:97:50
    at arrayMap (node_modules\eslint-plugin-jsdoc\node_modules\lodash\lodash.js:639:23)
    at map (node_modules\eslint-plugin-jsdoc\node_modules\lodash\lodash.js:9554:14)
    at Function.flatMap (node_modules\eslint-plugin-jsdoc\node_modules\lodash\lodash.js:9257:26)
    at node_modules\eslint-plugin-jsdoc\node_modules\lodash\lodash.js:4368:28
    at arrayReduce (node_modules\eslint-plugin-jsdoc\node_modules\lodash\lodash.js:683:21)
    at baseWrapperValue (node_modules\eslint-plugin-jsdoc\node_modules\lodash\lodash.js:4367:14)
    at LodashWrapper.wrapperValue (node_modules\eslint-plugin-jsdoc\node_modules\lodash\lodash.js:9050:14)
    at _default.iterateAllJsdocs (node_modules\eslint-plugin-jsdoc\dist\rules\noUndefinedTypes.js:101:6)

Block in eslint-plugin-jsdoc\dist\rules\noUndefinedTypes.js throwing the error:

let templateTags = (0, _lodash.default)(ancestorNodes).flatMap(ancestorNode => {
    const commentNode = (0, _getJSDocComment.getJSDocComment)(sourceCode, ancestorNode, settings);
    const jsdoc = (0, _iterateJsdoc.parseComment)(commentNode, '');
    return _jsdocUtils.default.filterTags(jsdoc.tags, tag => {
      return 'template' === tag.tag;
    });
  }).value();

25.4.1 doesn't throw an error in that case

ESLint Config

{
  "env": {
    "browser": true,
    "es6": true
  },
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 2018,
    "sourceType": "module",
    "ecmaFeatures": {
      "impliedStrict ": true,
      "jsx": true,
      "experimentalDecorators": true,
      "generators": false,
      "objectLiteralDuplicateProperties": false
    }
  },
  "plugins": [
    "jsdoc"
  ],
  "rules": {
    "jsdoc/no-undefined-types": [
      "warn"
    ],
    "jsdoc/valid-types": [
      "warn"
    ]
  },
  "settings": {
    "jsdoc": {
      "mode ": "typescript",
      "preferredTypes": {
        "jQuery": "JQuery"
      }
    },
  }
}
All rules
{
  "env": {
    "browser": true,
    "es6": true
  },
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 2018,
    "sourceType": "module",
    "ecmaFeatures": {
      "impliedStrict ": true,
      "jsx": true,
      "experimentalDecorators": true,
      "generators": false,
      "objectLiteralDuplicateProperties": false
    }
  },
  "plugins": [
    "jsdoc"
  ],
  "rules": {
    "jsdoc/require-description-complete-sentence": [
      "warn"
    ],
    "jsdoc/require-hyphen-before-param-description": [
      "error",
      "never",
      {
        "tags": {
          "property": "never"
        }
      }
    ],
    "jsdoc/require-jsdoc": [
      "off"
    ],
    "jsdoc/require-param-description": [
      "off"
    ],
    "jsdoc/require-property-description": [
      "off"
    ],
    "jsdoc/require-returns-description": [
      "off"
    ],
    "jsdoc/check-access": [
      "warn"
    ],
    "jsdoc/check-alignment": [
      "warn"
    ],
    "jsdoc/check-examples": [
      "off"
    ],
    "jsdoc/check-indentation": [
      "off"
    ],
    "jsdoc/check-param-names": [
      "warn"
    ],
    "jsdoc/check-property-names": [
      "warn"
    ],
    "jsdoc/check-syntax": [
      "off"
    ],
    "jsdoc/check-tag-names": [
      "warn"
    ],
    "jsdoc/check-types": [
      "warn"
    ],
    "jsdoc/check-values": [
      "warn"
    ],
    "jsdoc/empty-tags": [
      "warn"
    ],
    "jsdoc/implements-on-classes": [
      "warn"
    ],
    "jsdoc/match-description": [
      "off"
    ],
    "jsdoc/newline-after-description": [
      "warn"
    ],
    "jsdoc/no-bad-blocks": [
      "off"
    ],
    "jsdoc/no-defaults": [
      "off"
    ],
    "jsdoc/no-types": [
      "off"
    ],
    "jsdoc/no-undefined-types": [
      "warn"
    ],
    "jsdoc/require-description": [
      "off"
    ],
    "jsdoc/require-example": [
      "off"
    ],
    "jsdoc/require-file-overview": [
      "off"
    ],
    "jsdoc/require-param": [
      "warn"
    ],
    "jsdoc/require-param-name": [
      "warn"
    ],
    "jsdoc/require-param-type": [
      "warn"
    ],
    "jsdoc/require-property": [
      "warn"
    ],
    "jsdoc/require-property-name": [
      "warn"
    ],
    "jsdoc/require-property-type": [
      "warn"
    ],
    "jsdoc/require-returns": [
      "warn"
    ],
    "jsdoc/require-returns-check": [
      "warn"
    ],
    "jsdoc/require-returns-type": [
      "warn"
    ],
    "jsdoc/valid-types": [
      "warn"
    ]
  },
  "settings": {
    "jsdoc": {
      "mode ": "typescript",
      "tagNamePreference": {
        "description": false
      },
      "preferredTypes": {
        "jQuery": "JQuery"
      }
    },
  }
}

ESLint sample

const init = () => {
  /**
   * Makes request
   * @returns {Promise}
   */
  function request() {
    return Promise.resolve('success');
  }
};

Environment

  • Node version: v13.7.0
  • ESLint version v6.8.0
  • eslint-plugin-jsdoc version: 27.0.2
@nikolay-borzov
Copy link
Author

Thanks!

@gajus
Copy link
Owner

gajus commented Jun 4, 2020

🎉 This issue has been resolved in version 27.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gajus gajus added the released label Jun 4, 2020
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

2 participants