gajus / eslint-plugin-jsdoc

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

require-yields crashes eslint when named exports do not have a declaration #1231

Closed wjhsf closed 1 month ago

wjhsf commented 1 month ago

When parsing a NamedExportDeclaration, the require-yields rule expects an ExportNamedDeclaration node to have a declaration defined, but that is not necessarily the case.

https://github.com/gajus/eslint-plugin-jsdoc/blob/244116e52fc3cedd1d16dd91d8ab218e40f6cfc6/src/iterateJsdoc.js#L1351-L1356

Expected behavior

ESLint does not crash.

Actual behavior

ESLint crashes.

$ npx eslint index.js

Oops! Something went wrong! :(

ESLint: 8.57.0

TypeError: Cannot read properties of null (reading 'generator')
Occurred while linting /Users/wharney/Projects/tmp/index.js:2
Rule: "jsdoc/require-yields"
    at utils.isGenerator (file:///Users/wharney/Projects/tmp/node_modules/eslint-plugin-jsdoc/src/iterateJsdoc.js:1356:9)
    at shouldReportYields (file:///Users/wharney/Projects/tmp/node_modules/eslint-plugin-jsdoc/src/rules/requireYields.js:107:41)
    at iterateJsdoc.contextDefaults (file:///Users/wharney/Projects/tmp/node_modules/eslint-plugin-jsdoc/src/rules/requireYields.js:110:9)
    at iterate (file:///Users/wharney/Projects/tmp/node_modules/eslint-plugin-jsdoc/src/iterateJsdoc.js:2049:3)
    at checkJsdoc (file:///Users/wharney/Projects/tmp/node_modules/eslint-plugin-jsdoc/src/iterateJsdoc.js:2498:9)
    at ruleErrorHandler (/Users/wharney/Projects/tmp/node_modules/eslint/lib/linter/linter.js:1076:28)
    at /Users/wharney/Projects/tmp/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/wharney/Projects/tmp/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/Users/wharney/Projects/tmp/node_modules/eslint/lib/linter/node-event-generator.js:297:26)

ESLint Config

import jsdoc from "eslint-plugin-jsdoc";
export default {
  plugins: { jsdoc },
  rules: {
    "jsdoc/require-yields": [
      "error",
      {
        contexts: ["ExportNamedDeclaration"],
      },
    ],
  },
};

ESLint sample

const foo = "foo";
/** this will crash */
export { foo }

/** this will crash */
export { bar } from "bar";

/** this works as expected */
export const okay = "has declaration!"

Environment

github-actions[bot] commented 1 month ago

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

The release is available on:

Your semantic-release bot :package::rocket: