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-description-complete-sentence throws TypeError if code block exists somewhere between beginning and end of JSDoc block #1193

Closed
milofultz opened this issue Jan 26, 2024 · 3 comments · Fixed by #1194

Comments

@milofultz
Copy link

Expected behavior

When given a code block that is not at the beginning or the end of the JSDoc block, the rule require-description-complete-sentence should run and provide feedback.

Actual behavior

The rule is throwing a TypeError when given a code block that is not at the beginning or end of a JSDoc code block.

Oops! Something went wrong! :(

ESLint: 8.56.0

TypeError: Expected a string
Occurred while linting /Users/user/test/test.js:10
Rule: "jsdoc/require-description-complete-sentence"
    at module.exports (/Users/user/test/node_modules/escape-string-regexp/index.js:5:9)
    at Object.fix (/Users/user/test/node_modules/eslint-plugin-jsdoc/dist/rules/requireDescriptionCompleteSentence.cjs:112:75)
    at normalizeFixes (/Users/user/test/node_modules/eslint/lib/linter/report-translator.js:194:28)
    at /Users/user/test/node_modules/eslint/lib/linter/report-translator.js:365:49
    at Object.report (/Users/user/test/node_modules/eslint/lib/linter/linter.js:1047:41)
    at report (/Users/user/test/node_modules/eslint-plugin-jsdoc/dist/iterateJsdoc.cjs:1642:13)
    at report (/Users/user/test/node_modules/eslint-plugin-jsdoc/dist/rules/requireDescriptionCompleteSentence.cjs:157:7)
    at /Users/user/test/node_modules/eslint-plugin-jsdoc/dist/rules/requireDescriptionCompleteSentence.cjs:171:7
    at Array.some (<anonymous>)
    at validateDescription (/Users/user/test/node_modules/eslint-plugin-jsdoc/dist/rules/requireDescriptionCompleteSentence.cjs:106:21)

ESLint Config

module.exports = {
  env: {
    browser: true,
    es2021: true,
  },
  plugins: ["jsdoc"],
  overrides: [
    {
      env: {
        node: true,
      },
      files: [".eslintrc.{js,cjs}"],
      parserOptions: {
        sourceType: "script",
      },
    },
  ],
  parserOptions: {
    ecmaVersion: "latest",
    sourceType: "module",
  },
  rules: {
    "jsdoc/require-description-complete-sentence": "error",
  },
};

ESLint sample

/**
 * A single line for testing.
 *
 * ```js
 * const aCodeExample = true;
 * ```
 *
 * @param parameter
 */
const code = (parameter) => 123;

Interestingly, if you rearrange these three elements, it works.

/**
 * ```js
 * const aCodeExample = true;
 * ```
 *
 * A single line for testing.
 *
 * @param parameter
 */
const code = (parameter) => 123;

// or

/**
 * A single line for testing.
 *
 * @param parameter
 *
 * ```js
 * const aCodeExample = true;
 * ```
 */
const code = (parameter) => 123;

Environment

  • Node version: v21.6.1
  • ESLint version: v8.56.0
  • eslint-plugin-jsdoc version: ^48.0.3
@milofultz
Copy link
Author

I found this that seemed very related but not quite the same: #961

Copy link

🎉 This issue has been resolved in version 48.0.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@milofultz
Copy link
Author

dang you're quick! thanks @brettz9

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