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

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

Closed
wjhsf opened this issue May 23, 2024 · 1 comment · Fixed by #1232
Closed

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

wjhsf opened this issue May 23, 2024 · 1 comment · Fixed by #1232

Comments

@wjhsf
Copy link
Contributor

wjhsf commented May 23, 2024

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

(
/**
* @type {import('estree').ExportNamedDeclaration|
* import('estree').ExportDefaultDeclaration}
*/ (node).declaration
).generator,

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:https:///Users/wharney/Projects/tmp/node_modules/eslint-plugin-jsdoc/src/iterateJsdoc.js:1356:9)
    at shouldReportYields (file:https:///Users/wharney/Projects/tmp/node_modules/eslint-plugin-jsdoc/src/rules/requireYields.js:107:41)
    at iterateJsdoc.contextDefaults (file:https:///Users/wharney/Projects/tmp/node_modules/eslint-plugin-jsdoc/src/rules/requireYields.js:110:9)
    at iterate (file:https:///Users/wharney/Projects/tmp/node_modules/eslint-plugin-jsdoc/src/iterateJsdoc.js:2049:3)
    at checkJsdoc (file:https:///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

  • Node version: 22.1.0
  • ESLint version 8.57.0
  • eslint-plugin-jsdoc version: 48.2.5
Copy link

🎉 This issue has been resolved in version 48.2.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant