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

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

Closed
danfuzz opened this issue Sep 18, 2024 · 3 comments · Fixed by #1316 · May be fixed by WontonSam/markdownlint#38
Closed

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

danfuzz opened this issue Sep 18, 2024 · 3 comments · Fixed by #1316 · May be fixed by WontonSam/markdownlint#38

Comments

@danfuzz
Copy link

danfuzz commented Sep 18, 2024

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

  • Node version: v22.1.0
  • ESLint version 9.10.0
  • eslint-plugin-jsdoc version: 50.2.3
Copy link

🎉 This issue has been resolved in version 50.2.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@danfuzz
Copy link
Author

danfuzz commented Sep 19, 2024

Thanks so much for the quick fix!

@brettz9
Copy link
Collaborator

brettz9 commented Sep 19, 2024

Thank you for the report!

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