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
Expected behavior
A
for (;;)(forever) loop containing a conditionalreturnstatement gets recognized as such, vis-a-vis the rulerequire-returns-check.Actual behavior
This warning is reported, even though a
returnis present:The error goes away if
for (;;)is changed towhile (true).But also, surprisingly, if the
@returnsdeclaration 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
demoscript:bug-report.tar.gz
Environment
eslint-plugin-jsdocversion: 50.2.3