Skip to content

Commit 20b6ae0

Browse files
l1bbcsgbrettz9
authored andcommitted
feat(require-returns-check): Allow @return to be omitted with @record tag in Closure mode
1 parent f97627d commit 20b6ae0

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9853,6 +9853,18 @@ class Foo {
98539853
}
98549854
}
98559855

9856+
/**
9857+
* @record
9858+
*/
9859+
class Foo {
9860+
/**
9861+
* @returns {string}
9862+
*/
9863+
bar () {
9864+
}
9865+
}
9866+
// Settings: {"jsdoc":{"mode":"closure"}}
9867+
98569868
/**
98579869
* @returns {undefined} Foo.
98589870
*/

src/rules/requireReturnsCheck.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import iterateJsdoc from '../iterateJsdoc';
22

3-
const canSkip = (utils) => {
4-
return utils.hasATag([
3+
const canSkip = (utils, settings) => {
4+
const voidingTags = [
55
// An abstract function is by definition incomplete
66
// so it is perfectly fine if a return is documented but
77
// not present within the function.
@@ -15,14 +15,25 @@ const canSkip = (utils) => {
1515
'class',
1616
'constructor',
1717
'interface',
18-
]) || utils.isConstructor() || utils.classHasTag('interface');
18+
];
19+
20+
if (settings.mode === 'closure') {
21+
// Structural Interface in GCC terms, equivalent to @interface tag as far as this rule is concerned
22+
voidingTags.push('record');
23+
}
24+
25+
return utils.hasATag(voidingTags) ||
26+
utils.isConstructor() ||
27+
utils.classHasTag('interface') ||
28+
settings.mode === 'closure' && utils.classHasTag('record');
1929
};
2030

2131
export default iterateJsdoc(({
2232
report,
33+
settings,
2334
utils,
2435
}) => {
25-
if (canSkip(utils)) {
36+
if (canSkip(utils, settings)) {
2637
return;
2738
}
2839

test/rules/assertions/requireReturnsCheck.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,25 @@ export default {
298298
}
299299
`,
300300
},
301+
{
302+
code: `
303+
/**
304+
* @record
305+
*/
306+
class Foo {
307+
/**
308+
* @returns {string}
309+
*/
310+
bar () {
311+
}
312+
}
313+
`,
314+
settings: {
315+
jsdoc: {
316+
mode: 'closure',
317+
},
318+
},
319+
},
301320
{
302321
code: `
303322
/**

0 commit comments

Comments
 (0)