gajus / eslint-plugin-jsdoc

JSDoc specific linting rules for ESLint.
Other
1.09k stars 157 forks source link

Spurious complaint `jsdoc/require-returns-check`. #1315

Closed danfuzz closed 2 weeks ago

danfuzz commented 2 weeks ago

Expected behavior

A for (;;) (forever) loop containing a conditional return statement gets recognized as such, vis-a-vis the rule require-returns-check.

Actual behavior

This warning is reported, even though a return is present:

JSDoc @returns declaration present but return expression not available in function  jsdoc/require-returns-check

The error goes away if for (;;) is changed to while (true).

But also, surprisingly, if the @returns declaration is omitted, then this warning is reported instead:

Missing JSDoc @returns declaration  jsdoc/require-returns

ESLint Config

import js from '@eslint/js';
import jsdocPlugin from 'eslint-plugin-jsdoc';
import globals from 'globals';

export default [
  js.configs.recommended,
  jsdocPlugin.configs['flat/recommended'],
  {
    languageOptions: {
      ecmaVersion: 2024,
      globals: globals.node
    },
    plugins: {
      'jsdoc': jsdocPlugin,
    },
    settings: {
      jsdoc: {
        mode: 'jsdoc'
      }
    }
  },
];

ESLint sample

In the following, the definition of x() causes a problem, but y() does not:

/**
 * @returns {boolean} The result.
 */
function x() {
  for (;;) {
    const result = Array.isArray([]);
    if (result) {
      return result;
    }
  }
}
x();

/**
 * @returns {boolean} The result.
 */
function y() {
  while (true) {
    const result = Array.isArray([]);
    if (result) {
      return result;
    }
  }
}
y();

Here is a complete example as a tarball. Unpack it and then run the demo script: bug-report.tar.gz

Environment

github-actions[bot] commented 2 weeks ago

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

The release is available on:

Your semantic-release bot :package::rocket:

danfuzz commented 2 weeks ago

Thanks so much for the quick fix!

brettz9 commented 2 weeks ago

Thank you for the report!