Closed danfuzz closed 2 weeks ago
A for (;;) (forever) loop containing a conditional return statement gets recognized as such, vis-a-vis the rule require-returns-check.
for (;;)
return
require-returns-check
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).
while (true)
But also, surprisingly, if the @returns declaration is omitted, then this warning is reported instead:
@returns
Missing JSDoc @returns declaration jsdoc/require-returns
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' } } }, ];
In the following, the definition of x() causes a problem, but y() does not:
x()
y()
/** * @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
demo
eslint-plugin-jsdoc
:tada: This issue has been resolved in version 50.2.4 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Thanks so much for the quick fix!
Thank you for the report!
Expected behavior
A
for (;;)
(forever) loop containing a conditionalreturn
statement gets recognized as such, vis-a-vis the rulerequire-returns-check
.Actual behavior
This warning is reported, even though a
return
is present:The error goes away if
for (;;)
is changed towhile (true)
.But also, surprisingly, if the
@returns
declaration is omitted, then this warning is reported instead:ESLint Config
ESLint sample
In the following, the definition of
x()
causes a problem, buty()
does not:Here is a complete example as a tarball. Unpack it and then run the
demo
script: bug-report.tar.gzEnvironment
eslint-plugin-jsdoc
version: 50.2.3