Skip to content

Commit

Permalink
fix(require-returns-check, require-yields-check): avoid never b…
Browse files Browse the repository at this point in the history
…eing reported
  • Loading branch information
brettz9 committed Dec 18, 2021
1 parent 4433d7e commit 3a27c39
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 3 deletions.
27 changes: 27 additions & 0 deletions README.md
Expand Up @@ -16637,6 +16637,19 @@ function quux () {
return undefined;
}
/**
* @returns {never} Foo.
*/
function quux () {
}
/**
* @returns {never} Foo.
*/
function quux () {
return undefined;
}
/**
* @returns {void} Foo.
*/
Expand Down Expand Up @@ -19583,6 +19596,12 @@ function * quux () {
function * quux () {
}

/**
* @yields {never} Foo.
*/
function * quux () {
}

/**
* @yields {void} Foo.
*/
Expand Down Expand Up @@ -19789,6 +19808,14 @@ function * quux (foo) {
const a = yield 5;
}
// "jsdoc/require-yields-check": ["error"|"warn", {"next":true}]

/**
* @next {never}
*/
function * quux (foo) {

}
// "jsdoc/require-yields-check": ["error"|"warn", {"next":true}]
````


Expand Down
15 changes: 12 additions & 3 deletions src/rules/requireReturnsCheck.js
Expand Up @@ -66,10 +66,19 @@ export default iterateJsdoc(({
return;
}

const [tag] = tags;

// In case a return value is declared in JSDoc, we also expect one in the code.
if ((reportMissingReturnForUndefinedTypes || utils.hasDefinedTypeTag(tags[0])) && !utils.hasValueOrExecutorHasNonEmptyResolveValue(
exemptAsync,
) && (!exemptGenerators || !node.generator)) {
if (
tag.type.trim() !== 'never' &&
(
reportMissingReturnForUndefinedTypes ||
utils.hasDefinedTypeTag(tag)
) &&
!utils.hasValueOrExecutorHasNonEmptyResolveValue(
exemptAsync,
) && (!exemptGenerators || !node.generator)
) {
report(`JSDoc @${tagName} declaration present but return expression not available in function.`);
}
}, {
Expand Down
8 changes: 8 additions & 0 deletions src/rules/requireYieldsCheck.js
Expand Up @@ -71,6 +71,10 @@ export default iterateJsdoc(({
);
if (preferredYieldTagName) {
const shouldReportYields = () => {
if (yieldTag.type.trim() === 'never') {
return false;
}

if (checkGeneratorsOnly && !utils.isGenerator()) {
return true;
}
Expand All @@ -90,6 +94,10 @@ export default iterateJsdoc(({
);
if (preferredNextTagName) {
const shouldReportNext = () => {
if (nextTag.type.trim() === 'never') {
return false;
}

if (checkGeneratorsOnly && !utils.isGenerator()) {
return true;
}
Expand Down
19 changes: 19 additions & 0 deletions test/rules/assertions/requireReturnsCheck.js
Expand Up @@ -519,6 +519,25 @@ export default {
}
`,
},
{
code: `
/**
* @returns {never} Foo.
*/
function quux () {
}
`,
},
{
code: `
/**
* @returns {never} Foo.
*/
function quux () {
return undefined;
}
`,
},
{
code: `
/**
Expand Down
22 changes: 22 additions & 0 deletions test/rules/assertions/requireYieldsCheck.js
Expand Up @@ -440,6 +440,15 @@ export default {
}
`,
},
{
code: `
/**
* @yields {never} Foo.
*/
function * quux () {
}
`,
},
{
code: `
/**
Expand Down Expand Up @@ -719,5 +728,18 @@ export default {
next: true,
}],
},
{
code: `
/**
* @next {never}
*/
function * quux (foo) {
}
`,
options: [{
next: true,
}],
},
],
};

0 comments on commit 3a27c39

Please sign in to comment.