forked from gajus/eslint-plugin-jsdoc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
requireReturnsCheck.js
executable file
·53 lines (45 loc) · 1.28 KB
/
requireReturnsCheck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import iterateJsdoc from '../iterateJsdoc';
const canSkip = (utils) => {
return utils.hasATag([
// An abstract function is by definition incomplete
// so it is perfectly fine if a return is documented but
// not present within the function.
// A subclass may inherit the doc and implement the
// missing return.
'abstract',
'virtual',
// A constructor function returns `this` by default, so may be `@returns`
// tag indicating this but no explicit return
'class',
'constructor',
'interface'
]) || utils.isConstructor() || utils.classHasTag('interface');
};
export default iterateJsdoc(({
report,
utils
}) => {
if (canSkip(utils)) {
return;
}
const tagName = utils.getPreferredTagName({tagName: 'returns'});
if (!tagName) {
return;
}
const tags = utils.getTags(tagName);
if (tags.length === 0) {
return;
}
if (tags.length > 1) {
report(`Found more than one @${tagName} declaration.`);
return;
}
// In case a return value is declared in JSDoc, we also expect one in the code.
if (utils.hasDefinedTypeReturnTag(tags[0]) && !utils.hasReturnValue()) {
report(`JSDoc @${tagName} declaration present but return expression not available in function.`);
}
}, {
meta: {
type: 'suggestion'
}
});