File tree Expand file tree Collapse file tree 5 files changed +72
-16
lines changed Expand file tree Collapse file tree 5 files changed +72
-16
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,10 @@ const curryUtils = (
60
60
return node . parent && node . parent . kind === 'constructor' ;
61
61
} ;
62
62
63
+ utils . isSetter = ( ) => {
64
+ return functionNode . parent . kind === 'set' ;
65
+ } ;
66
+
63
67
utils . getJsdocParameterNamesDeep = ( ) => {
64
68
return jsdocUtils . getJsdocParameterNamesDeep ( jsdoc , utils . getPreferredTagName ( 'param' ) ) ;
65
69
} ;
Original file line number Diff line number Diff line change @@ -30,12 +30,20 @@ const canSkip = (utils) => {
30
30
'class' ,
31
31
'constructor' ,
32
32
33
+ // This seems to imply a class as well
34
+ 'interface' ,
35
+
33
36
// While we may, in a future rule, err in the case of (regular) functions
34
37
// using @implements (see https://github.com/gajus/eslint-plugin-jsdoc/issues/201 ),
35
38
// this should not error for those using the tag to indicate implementation of
36
39
// a particular function signature
37
40
'implements'
38
- ] ) || utils . isConstructor ( ) ;
41
+ ] ) ||
42
+ utils . isConstructor ( ) ||
43
+
44
+ // Though ESLint avoided getters: https://github.com/eslint/eslint/blob/master/lib/rules/valid-jsdoc.js#L435
45
+ // ... getters seem that they should, unlike setters, always return:
46
+ utils . isSetter ( ) ;
39
47
} ;
40
48
41
49
export default iterateJsdoc ( ( {
Original file line number Diff line number Diff line change 1
1
import iterateJsdoc from '../iterateJsdoc' ;
2
2
3
- const canSkip = ( utils , node ) => {
3
+ const canSkip = ( utils ) => {
4
4
return utils . hasATag ( [
5
5
// An abstract function is by definition incomplete
6
- // so it is perfectly fine if the return is missing.
6
+ // so it is perfectly fine if a return is documented but
7
+ // not present within the function.
7
8
// A subclass may inherit the doc and implement the
8
9
// missing return.
9
10
'abstract' ,
10
11
'virtual' ,
11
12
12
- // A constructor function returns `this` by default
13
- 'constructor'
14
- ] ) ||
15
-
16
- utils . isConstructor ( ) ||
17
-
18
- // Implicit return like `() => foo` is ok
19
- utils . isArrowExpression ( ) ||
20
-
21
- // Async function always returns a `Promise`
22
- node . async ;
13
+ // A constructor function returns `this` by default, so may be `@returns`
14
+ // tag indicating this but no explicit return
15
+ 'class' ,
16
+ 'constructor' ,
17
+ 'interface'
18
+ ] ) || utils . isConstructor ( ) ;
23
19
} ;
24
20
25
21
export default iterateJsdoc ( ( {
26
22
report,
27
- node,
28
23
utils
29
24
} ) => {
30
- if ( canSkip ( utils , node ) ) {
25
+ if ( canSkip ( utils ) ) {
31
26
return ;
32
27
}
33
28
Original file line number Diff line number Diff line change @@ -155,6 +155,24 @@ export default {
155
155
forceRequireReturn : true
156
156
}
157
157
}
158
+ } ,
159
+ {
160
+ code : `
161
+ const language = {
162
+ /**
163
+ * @param {string} name
164
+ */
165
+ get name() {
166
+ return this._name;
167
+ }
168
+ }
169
+ ` ,
170
+ errors : [
171
+ {
172
+ line : 3 ,
173
+ message : 'Missing JSDoc @returns declaration.'
174
+ }
175
+ ]
158
176
}
159
177
] ,
160
178
valid : [
@@ -378,6 +396,18 @@ export default {
378
396
forceRequireReturn : true
379
397
}
380
398
}
399
+ } ,
400
+ {
401
+ code : `
402
+ const language = {
403
+ /**
404
+ * @param {string} name
405
+ */
406
+ set name(name) {
407
+ this._name = name;
408
+ }
409
+ }
410
+ `
381
411
}
382
412
]
383
413
} ;
Original file line number Diff line number Diff line change @@ -70,6 +70,25 @@ export default {
70
70
message : 'Found more than one @returns declaration.'
71
71
}
72
72
]
73
+ } ,
74
+ {
75
+ code : `
76
+ const language = {
77
+ /**
78
+ * @param {string} name
79
+ * @returns {string}
80
+ */
81
+ get name() {
82
+ this._name = name;
83
+ }
84
+ }
85
+ ` ,
86
+ errors : [
87
+ {
88
+ line : 3 ,
89
+ message : 'JSDoc @returns declaration present but return expression not available in function.'
90
+ }
91
+ ]
73
92
}
74
93
] ,
75
94
valid : [
You can’t perform that action at this time.
0 commit comments