gajus / eslint-plugin-jsdoc

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

`require-description-complete-sentence` throws TypeError if code block exists somewhere between beginning and end of JSDoc block #1193

Closed milofultz closed 6 months ago

milofultz commented 6 months ago

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

milofultz commented 6 months ago

I found this that seemed very related but not quite the same: https://github.com/gajus/eslint-plugin-jsdoc/issues/961

github-actions[bot] commented 6 months ago

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

The release is available on:

Your semantic-release bot :package::rocket:

milofultz commented 6 months ago

dang you're quick! thanks @brettz9