diff --git a/README.md b/README.md index 4ab8aaa0e..7e4d27a95 100644 --- a/README.md +++ b/README.md @@ -17875,7 +17875,7 @@ function quux () { } /** - * @returns {SomeType} Foo. + * @returns {*} Foo. */ const quux = () => foo; @@ -18276,14 +18276,14 @@ function quux (path) { }; /** - * @returns {SomeType} Foo. + * @returns {*} Foo. */ const quux = () => new Promise((resolve) => { resolve(3); }); /** - * @returns {SomeType} Foo. + * @returns {*} Foo. */ const quux = function () { return new Promise((resolve) => { @@ -18420,16 +18420,6 @@ export function f(): string { interface I {} } - -/** - * @param {boolean} bar A fun variable. - * @returns {*} Anything at all! - */ -function foo( bar ) { - if ( bar ) { - return functionWithUnknownReturnType(); - } -} ```` diff --git a/src/iterateJsdoc.js b/src/iterateJsdoc.js index 7b3ebcdce..dcca87fc8 100644 --- a/src/iterateJsdoc.js +++ b/src/iterateJsdoc.js @@ -724,8 +724,8 @@ const getUtils = ( return jsdocUtils.getTagStructureForMode(mde, settings.structuredTags); }; - utils.mayBeUndefinedTypeTag = (tag) => { - return jsdocUtils.mayBeUndefinedTypeTag(tag, settings.mode); + utils.hasDefinedTypeTag = (tag) => { + return jsdocUtils.hasDefinedTypeTag(tag, settings.mode); }; utils.hasValueOrExecutorHasNonEmptyResolveValue = (anyPromiseAsReturn, allBranches) => { diff --git a/src/jsdocUtils.js b/src/jsdocUtils.js index b14bea9a0..9aa0ce5ac 100644 --- a/src/jsdocUtils.js +++ b/src/jsdocUtils.js @@ -464,29 +464,26 @@ const hasATag = (jsdoc, targetTagNames) => { }; /** - * Checks if the JSDoc comment declares an undefined type. + * Checks if the JSDoc comment declares a defined type. * * @param {JsDocTag} tag * the tag which should be checked. * @param {"jsdoc"|"closure"|"typescript"} mode * @returns {boolean} - * true in case a defined type is undeclared; otherwise false. + * true in case a defined type is declared; otherwise false. */ -const mayBeUndefinedTypeTag = (tag, mode) => { +const hasDefinedTypeTag = (tag, mode) => { // The function should not continue in the event the type is not defined... if (typeof tag === 'undefined' || tag === null) { - return true; + return false; } // .. same applies if it declares an `{undefined}` or `{void}` type const tagType = tag.type.trim(); // Exit early if matching - if ( - tagType === 'undefined' || tagType === 'void' || - tagType === '*' || tagType === 'any' - ) { - return true; + if (tagType === 'undefined' || tagType === 'void') { + return false; } let parsedTypes; @@ -509,11 +506,11 @@ const mayBeUndefinedTypeTag = (tag, mode) => { return elem.type === 'JsdocTypeUndefined' || elem.type === 'JsdocTypeName' && elem.value === 'void'; })) { - return true; + return false; } // In any other case, a type is present - return false; + return true; }; /** @@ -1242,6 +1239,7 @@ export default { getTagsByType, getTagStructureForMode, hasATag, + hasDefinedTypeTag, hasParams, hasReturnValue, hasTag, @@ -1253,7 +1251,6 @@ export default { isNamepathDefiningTag, isSetter, isValidTag, - mayBeUndefinedTypeTag, overrideTagStructure, parseClosureTemplateTag, pathDoesNotBeginWith, diff --git a/src/rules/requireReturnsCheck.js b/src/rules/requireReturnsCheck.js index 8179cfc15..abc7c6c19 100755 --- a/src/rules/requireReturnsCheck.js +++ b/src/rules/requireReturnsCheck.js @@ -92,7 +92,7 @@ export default iterateJsdoc(({ !returnNever && ( reportMissingReturnForUndefinedTypes || - !utils.mayBeUndefinedTypeTag(tag) + utils.hasDefinedTypeTag(tag) ) && !utils.hasValueOrExecutorHasNonEmptyResolveValue( exemptAsync, diff --git a/src/rules/requireYieldsCheck.js b/src/rules/requireYieldsCheck.js index f3837b216..9cc7154d1 100644 --- a/src/rules/requireYieldsCheck.js +++ b/src/rules/requireYieldsCheck.js @@ -90,7 +90,7 @@ export default iterateJsdoc(({ return true; } - return !utils.mayBeUndefinedTypeTag(yieldTag) && !utils.hasYieldValue(); + return utils.hasDefinedTypeTag(yieldTag) && !utils.hasYieldValue(); }; // In case a yield value is declared in JSDoc, we also expect one in the code. @@ -120,7 +120,7 @@ export default iterateJsdoc(({ return true; } - return !utils.mayBeUndefinedTypeTag(nextTag) && !utils.hasYieldReturnValue(); + return utils.hasDefinedTypeTag(nextTag) && !utils.hasYieldReturnValue(); }; if (shouldReportNext()) { diff --git a/test/jsdocUtils.js b/test/jsdocUtils.js index 5d5f6722a..86c6fbd11 100644 --- a/test/jsdocUtils.js +++ b/test/jsdocUtils.js @@ -68,10 +68,10 @@ describe('jsdocUtils', () => { }); }); }); - describe('mayBeUndefinedTypeTag()', () => { + describe('hasDefinedTypeTag()', () => { context('Missing tag', () => { it('should return `false` with a missing tag', () => { - expect(jsdocUtils.mayBeUndefinedTypeTag(null)).to.equal(true); + expect(jsdocUtils.hasDefinedTypeTag(null)).to.equal(false); }); }); }); diff --git a/test/rules/assertions/requireReturnsCheck.js b/test/rules/assertions/requireReturnsCheck.js index ccb2c7418..fb0135406 100755 --- a/test/rules/assertions/requireReturnsCheck.js +++ b/test/rules/assertions/requireReturnsCheck.js @@ -701,7 +701,7 @@ export default { { code: ` /** - * @returns {SomeType} Foo. + * @returns {*} Foo. */ const quux = () => foo; `, @@ -1306,7 +1306,7 @@ export default { { code: ` /** - * @returns {SomeType} Foo. + * @returns {*} Foo. */ const quux = () => new Promise((resolve) => { resolve(3); @@ -1316,7 +1316,7 @@ export default { { code: ` /** - * @returns {SomeType} Foo. + * @returns {*} Foo. */ const quux = function () { return new Promise((resolve) => { @@ -1505,18 +1505,5 @@ export default { `, parser: require.resolve('@typescript-eslint/parser'), }, - { - code: ` - /** - * @param {boolean} bar A fun variable. - * @returns {*} Anything at all! - */ - function foo( bar ) { - if ( bar ) { - return functionWithUnknownReturnType(); - } - } - `, - }, ], };