Skip to content

Commit 3a27c39

Browse files
committedDec 18, 2021
fix(require-returns-check, require-yields-check): avoid never being reported
1 parent 4433d7e commit 3a27c39

File tree

5 files changed

+88
-3
lines changed

5 files changed

+88
-3
lines changed
 

‎README.md

+27
Original file line numberDiff line numberDiff line change
@@ -16637,6 +16637,19 @@ function quux () {
1663716637
return undefined;
1663816638
}
1663916639
16640+
/**
16641+
* @returns {never} Foo.
16642+
*/
16643+
function quux () {
16644+
}
16645+
16646+
/**
16647+
* @returns {never} Foo.
16648+
*/
16649+
function quux () {
16650+
return undefined;
16651+
}
16652+
1664016653
/**
1664116654
* @returns {void} Foo.
1664216655
*/
@@ -19583,6 +19596,12 @@ function * quux () {
1958319596
function * quux () {
1958419597
}
1958519598

19599+
/**
19600+
* @yields {never} Foo.
19601+
*/
19602+
function * quux () {
19603+
}
19604+
1958619605
/**
1958719606
* @yields {void} Foo.
1958819607
*/
@@ -19789,6 +19808,14 @@ function * quux (foo) {
1978919808
const a = yield 5;
1979019809
}
1979119810
// "jsdoc/require-yields-check": ["error"|"warn", {"next":true}]
19811+
19812+
/**
19813+
* @next {never}
19814+
*/
19815+
function * quux (foo) {
19816+
19817+
}
19818+
// "jsdoc/require-yields-check": ["error"|"warn", {"next":true}]
1979219819
````
1979319820

1979419821

‎src/rules/requireReturnsCheck.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,19 @@ export default iterateJsdoc(({
6666
return;
6767
}
6868

69+
const [tag] = tags;
70+
6971
// In case a return value is declared in JSDoc, we also expect one in the code.
70-
if ((reportMissingReturnForUndefinedTypes || utils.hasDefinedTypeTag(tags[0])) && !utils.hasValueOrExecutorHasNonEmptyResolveValue(
71-
exemptAsync,
72-
) && (!exemptGenerators || !node.generator)) {
72+
if (
73+
tag.type.trim() !== 'never' &&
74+
(
75+
reportMissingReturnForUndefinedTypes ||
76+
utils.hasDefinedTypeTag(tag)
77+
) &&
78+
!utils.hasValueOrExecutorHasNonEmptyResolveValue(
79+
exemptAsync,
80+
) && (!exemptGenerators || !node.generator)
81+
) {
7382
report(`JSDoc @${tagName} declaration present but return expression not available in function.`);
7483
}
7584
}, {

‎src/rules/requireYieldsCheck.js

+8
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ export default iterateJsdoc(({
7171
);
7272
if (preferredYieldTagName) {
7373
const shouldReportYields = () => {
74+
if (yieldTag.type.trim() === 'never') {
75+
return false;
76+
}
77+
7478
if (checkGeneratorsOnly && !utils.isGenerator()) {
7579
return true;
7680
}
@@ -90,6 +94,10 @@ export default iterateJsdoc(({
9094
);
9195
if (preferredNextTagName) {
9296
const shouldReportNext = () => {
97+
if (nextTag.type.trim() === 'never') {
98+
return false;
99+
}
100+
93101
if (checkGeneratorsOnly && !utils.isGenerator()) {
94102
return true;
95103
}

‎test/rules/assertions/requireReturnsCheck.js

+19
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,25 @@ export default {
519519
}
520520
`,
521521
},
522+
{
523+
code: `
524+
/**
525+
* @returns {never} Foo.
526+
*/
527+
function quux () {
528+
}
529+
`,
530+
},
531+
{
532+
code: `
533+
/**
534+
* @returns {never} Foo.
535+
*/
536+
function quux () {
537+
return undefined;
538+
}
539+
`,
540+
},
522541
{
523542
code: `
524543
/**

‎test/rules/assertions/requireYieldsCheck.js

+22
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,15 @@ export default {
440440
}
441441
`,
442442
},
443+
{
444+
code: `
445+
/**
446+
* @yields {never} Foo.
447+
*/
448+
function * quux () {
449+
}
450+
`,
451+
},
443452
{
444453
code: `
445454
/**
@@ -719,5 +728,18 @@ export default {
719728
next: true,
720729
}],
721730
},
731+
{
732+
code: `
733+
/**
734+
* @next {never}
735+
*/
736+
function * quux (foo) {
737+
738+
}
739+
`,
740+
options: [{
741+
next: true,
742+
}],
743+
},
722744
],
723745
};

0 commit comments

Comments
 (0)
Please sign in to comment.