Skip to content

Commit ae91ae8

Browse files
committed
feat(require-jsdoc): add exemptEmptyConstructors and set true as default; fixes #600
If `true` will prevent empty constructors from needing documentation. Also adds `checkConstructors`, `checkGetters`, and `checkSetters` options (default `true`) to allow the complete disabling of checks on these methods as per other require-* rules.
1 parent 8604bde commit ae91ae8

File tree

6 files changed

+377
-85
lines changed

6 files changed

+377
-85
lines changed

.README/rules/require-jsdoc.md

Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,76 @@ functions.
77

88
Accepts one optional options object with the following optional keys.
99

10-
- `publicOnly` - This option will insist that missing jsdoc blocks are
11-
only reported for function bodies / class declarations that are exported
12-
from the module. May be a boolean or object. If set to `true`, the defaults
13-
below will be used. If unset, jsdoc block reporting will not be limited to
14-
exports.
15-
16-
This object supports the following optional boolean keys (`false` unless
17-
otherwise noted):
18-
19-
- `ancestorsOnly` - Only check node ancestors to check if node is exported
20-
- `esm` - ESM exports are checked for JSDoc comments (Defaults to `true`)
21-
- `cjs` - CommonJS exports are checked for JSDoc comments (Defaults to `true`)
22-
- `window` - Window global exports are checked for JSDoc comments
23-
24-
- `require` - An object with the following optional boolean keys which all
25-
default to `false` except as noted, indicating the contexts where the rule
26-
will apply:
27-
28-
- `ArrowFunctionExpression`
29-
- `ClassDeclaration`
30-
- `ClassExpression`
31-
- `FunctionDeclaration` (defaults to `true`)
32-
- `FunctionExpression`
33-
- `MethodDefinition`
34-
35-
- `contexts` - Set this to an array of strings or objects representing the
36-
additional AST contexts where you wish the rule to be applied (e.g.,
37-
`Property` for properties). If specified as an object, it should have a
38-
`context` property and can have an `inlineCommentBlock` property which,
39-
if set to `true`, will add an inline `/** */` instead of the regular,
40-
multi-line, indented jsdoc block which will otherwise be added. Defaults
41-
to an empty array.
42-
43-
- `exemptEmptyFunctions` (default: false) - When `true`, the rule will not report
44-
missing jsdoc blocks above functions/methods with no parameters or return values
45-
(intended where variable names are sufficient for themselves as documentation).
10+
##### `publicOnly`
11+
12+
This option will insist that missing jsdoc blocks are only reported for
13+
function bodies / class declarations that are exported from the module.
14+
May be a boolean or object. If set to `true`, the defaults below will be
15+
used. If unset, jsdoc block reporting will not be limited to exports.
16+
17+
This object supports the following optional boolean keys (`false` unless
18+
otherwise noted):
19+
20+
- `ancestorsOnly` - Only check node ancestors to check if node is exported
21+
- `esm` - ESM exports are checked for JSDoc comments (Defaults to `true`)
22+
- `cjs` - CommonJS exports are checked for JSDoc comments (Defaults to `true`)
23+
- `window` - Window global exports are checked for JSDoc comments
24+
25+
##### `require`
26+
27+
An object with the following optional boolean keys which all default to
28+
`false` except as noted, indicating the contexts where the rule will apply:
29+
30+
- `ArrowFunctionExpression`
31+
- `ClassDeclaration`
32+
- `ClassExpression`
33+
- `FunctionDeclaration` (defaults to `true`)
34+
- `FunctionExpression`
35+
- `MethodDefinition`
36+
37+
##### `contexts`
38+
39+
Set this to an array of strings or objects representing the additional AST
40+
contexts where you wish the rule to be applied (e.g., `Property` for
41+
properties). If specified as an object, it should have a `context` property
42+
and can have an `inlineCommentBlock` property which, if set to `true`, will
43+
add an inline `/** */` instead of the regular, multi-line, indented jsdoc
44+
block which will otherwise be added. Defaults to an empty array.
45+
46+
##### `exemptEmptyConstructors`
47+
48+
Default: true
49+
50+
When `true`, the rule will not report missing jsdoc blocks above constructors
51+
with no parameters or return values (this is enabled by default as the class
52+
name or description should be seen as sufficient to convey intent).
53+
54+
##### `exemptEmptyFunctions`
55+
56+
Default: false.
57+
58+
When `true`, the rule will not report missing jsdoc blocks above
59+
functions/methods with no parameters or return values (intended where
60+
function/method names are sufficient for themselves as documentation).
61+
62+
##### `checkConstructors`
63+
64+
A value indicating whether `constructor`s should be checked. Defaults to `true`.
65+
When `true`, `exemptEmptyConstructors` may still avoid reporting when no
66+
parameters or return values are found.
67+
68+
##### `checkGetters`
69+
70+
A value indicating whether getters should be checked. Defaults to `false`.
71+
72+
##### `checkSetters`
73+
74+
A value indicating whether getters should be checked. Defaults to `false`.
4675

4776
|||
4877
|---|---|
4978
|Context|`ArrowFunctionExpression`, `ClassDeclaration`, `ClassExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
5079
|Tags|N/A|
51-
|Options|`publicOnly`, `require`, `contexts`, `exemptEmptyFunctions`|
80+
|Options|`publicOnly`, `require`, `contexts`, `exemptEmptyConstructors`, `exemptEmptyFunctions`|
5281

5382
<!-- assertions requireJsdoc -->

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"extends": "canonical",
33
"root": true,
44
"rules": {
5+
"array-element-newline": 0,
56
"filenames/match-regex": 0,
67
"prefer-named-capture-group": 0,
78
"unicorn/prevent-abbreviations": 0

README.md

Lines changed: 129 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8296,48 +8296,85 @@ functions.
82968296
82978297
Accepts one optional options object with the following optional keys.
82988298
8299-
- `publicOnly` - This option will insist that missing jsdoc blocks are
8300-
only reported for function bodies / class declarations that are exported
8301-
from the module. May be a boolean or object. If set to `true`, the defaults
8302-
below will be used. If unset, jsdoc block reporting will not be limited to
8303-
exports.
8304-
8305-
This object supports the following optional boolean keys (`false` unless
8306-
otherwise noted):
8307-
8308-
- `ancestorsOnly` - Only check node ancestors to check if node is exported
8309-
- `esm` - ESM exports are checked for JSDoc comments (Defaults to `true`)
8310-
- `cjs` - CommonJS exports are checked for JSDoc comments (Defaults to `true`)
8311-
- `window` - Window global exports are checked for JSDoc comments
8312-
8313-
- `require` - An object with the following optional boolean keys which all
8314-
default to `false` except as noted, indicating the contexts where the rule
8315-
will apply:
8316-
8317-
- `ArrowFunctionExpression`
8318-
- `ClassDeclaration`
8319-
- `ClassExpression`
8320-
- `FunctionDeclaration` (defaults to `true`)
8321-
- `FunctionExpression`
8322-
- `MethodDefinition`
8323-
8324-
- `contexts` - Set this to an array of strings or objects representing the
8325-
additional AST contexts where you wish the rule to be applied (e.g.,
8326-
`Property` for properties). If specified as an object, it should have a
8327-
`context` property and can have an `inlineCommentBlock` property which,
8328-
if set to `true`, will add an inline `/** */` instead of the regular,
8329-
multi-line, indented jsdoc block which will otherwise be added. Defaults
8330-
to an empty array.
8331-
8332-
- `exemptEmptyFunctions` (default: false) - When `true`, the rule will not report
8333-
missing jsdoc blocks above functions/methods with no parameters or return values
8334-
(intended where variable names are sufficient for themselves as documentation).
8299+
<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-19-publiconly"></a>
8300+
##### <code>publicOnly</code>
8301+
8302+
This option will insist that missing jsdoc blocks are only reported for
8303+
function bodies / class declarations that are exported from the module.
8304+
May be a boolean or object. If set to `true`, the defaults below will be
8305+
used. If unset, jsdoc block reporting will not be limited to exports.
8306+
8307+
This object supports the following optional boolean keys (`false` unless
8308+
otherwise noted):
8309+
8310+
- `ancestorsOnly` - Only check node ancestors to check if node is exported
8311+
- `esm` - ESM exports are checked for JSDoc comments (Defaults to `true`)
8312+
- `cjs` - CommonJS exports are checked for JSDoc comments (Defaults to `true`)
8313+
- `window` - Window global exports are checked for JSDoc comments
8314+
8315+
<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-19-require"></a>
8316+
##### <code>require</code>
8317+
8318+
An object with the following optional boolean keys which all default to
8319+
`false` except as noted, indicating the contexts where the rule will apply:
8320+
8321+
- `ArrowFunctionExpression`
8322+
- `ClassDeclaration`
8323+
- `ClassExpression`
8324+
- `FunctionDeclaration` (defaults to `true`)
8325+
- `FunctionExpression`
8326+
- `MethodDefinition`
8327+
8328+
<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-19-contexts-4"></a>
8329+
##### <code>contexts</code>
8330+
8331+
Set this to an array of strings or objects representing the additional AST
8332+
contexts where you wish the rule to be applied (e.g., `Property` for
8333+
properties). If specified as an object, it should have a `context` property
8334+
and can have an `inlineCommentBlock` property which, if set to `true`, will
8335+
add an inline `/** */` instead of the regular, multi-line, indented jsdoc
8336+
block which will otherwise be added. Defaults to an empty array.
8337+
8338+
<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-19-exemptemptyconstructors"></a>
8339+
##### <code>exemptEmptyConstructors</code>
8340+
8341+
Default: true
8342+
8343+
When `true`, the rule will not report missing jsdoc blocks above constructors
8344+
with no parameters or return values (this is enabled by default as the class
8345+
name or description should be seen as sufficient to convey intent).
8346+
8347+
<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-19-exemptemptyfunctions"></a>
8348+
##### <code>exemptEmptyFunctions</code>
8349+
8350+
Default: false.
8351+
8352+
When `true`, the rule will not report missing jsdoc blocks above
8353+
functions/methods with no parameters or return values (intended where
8354+
function/method names are sufficient for themselves as documentation).
8355+
8356+
<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-19-checkconstructors-1"></a>
8357+
##### <code>checkConstructors</code>
8358+
8359+
A value indicating whether `constructor`s should be checked. Defaults to `true`.
8360+
When `true`, `exemptEmptyConstructors` may still avoid reporting when no
8361+
parameters or return values are found.
8362+
8363+
<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-19-checkgetters-1"></a>
8364+
##### <code>checkGetters</code>
8365+
8366+
A value indicating whether getters should be checked. Defaults to `false`.
8367+
8368+
<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-19-checksetters-1"></a>
8369+
##### <code>checkSetters</code>
8370+
8371+
A value indicating whether getters should be checked. Defaults to `false`.
83358372
83368373
|||
83378374
|---|---|
83388375
|Context|`ArrowFunctionExpression`, `ClassDeclaration`, `ClassExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
83398376
|Tags|N/A|
8340-
|Options|`publicOnly`, `require`, `contexts`, `exemptEmptyFunctions`|
8377+
|Options|`publicOnly`, `require`, `contexts`, `exemptEmptyConstructors`, `exemptEmptyFunctions`|
83418378
83428379
The following patterns are considered problems:
83438380
@@ -8858,6 +8895,36 @@ class Animal {
88588895
export class User {}
88598896
// Options: [{"require":{"ClassDeclaration":true}}]
88608897
// Message: Missing JSDoc comment.
8898+
8899+
/**
8900+
*
8901+
*/
8902+
class Foo {
8903+
constructor() {}
8904+
}
8905+
// Options: [{"exemptEmptyConstructors":false,"require":{"MethodDefinition":true}}]
8906+
// Message: Missing JSDoc comment.
8907+
8908+
/**
8909+
*
8910+
*/
8911+
class Foo {
8912+
constructor(notEmpty) {}
8913+
}
8914+
// Options: [{"exemptEmptyConstructors":true,"require":{"MethodDefinition":true}}]
8915+
// Message: Missing JSDoc comment.
8916+
8917+
/**
8918+
*
8919+
*/
8920+
class Foo {
8921+
constructor() {
8922+
const notEmpty = true;
8923+
return notEmpty;
8924+
}
8925+
}
8926+
// Options: [{"exemptEmptyConstructors":true,"require":{"MethodDefinition":true}}]
8927+
// Message: Missing JSDoc comment.
88618928
````
88628929
88638930
The following patterns are not considered problems:
@@ -9521,6 +9588,22 @@ export class User {
95219588
export class User {
95229589
}
95239590
// Options: [{"require":{"ArrowFunctionExpression":false,"ClassDeclaration":true,"ClassExpression":true,"FunctionDeclaration":true,"FunctionExpression":false,"MethodDefinition":true}}]
9591+
9592+
/**
9593+
*
9594+
*/
9595+
class Foo {
9596+
constructor() {}
9597+
}
9598+
// Options: [{"exemptEmptyConstructors":true,"require":{"MethodDefinition":true}}]
9599+
9600+
/**
9601+
*
9602+
*/
9603+
class Foo {
9604+
constructor() {}
9605+
}
9606+
// Options: [{"checkConstructors":false,"require":{"MethodDefinition":true}}]
95249607
````
95259608
95269609
@@ -9532,7 +9615,7 @@ Requires that each `@param` tag has a `description` value.
95329615
<a name="eslint-plugin-jsdoc-rules-require-param-description-options-20"></a>
95339616
#### Options
95349617
9535-
<a name="eslint-plugin-jsdoc-rules-require-param-description-options-20-contexts-4"></a>
9618+
<a name="eslint-plugin-jsdoc-rules-require-param-description-options-20-contexts-5"></a>
95369619
##### <code>contexts</code>
95379620
95389621
Set this to an array of strings representing the AST context
@@ -9655,7 +9738,7 @@ Requires that all function parameters have names.
96559738
<a name="eslint-plugin-jsdoc-rules-require-param-name-options-21"></a>
96569739
#### Options
96579740

9658-
<a name="eslint-plugin-jsdoc-rules-require-param-name-options-21-contexts-5"></a>
9741+
<a name="eslint-plugin-jsdoc-rules-require-param-name-options-21-contexts-6"></a>
96599742
##### <code>contexts</code>
96609743

96619744
Set this to an array of strings representing the AST context
@@ -9773,7 +9856,7 @@ Requires that each `@param` tag has a `type` value.
97739856
<a name="eslint-plugin-jsdoc-rules-require-param-type-options-22"></a>
97749857
#### Options
97759858

9776-
<a name="eslint-plugin-jsdoc-rules-require-param-type-options-22-contexts-6"></a>
9859+
<a name="eslint-plugin-jsdoc-rules-require-param-type-options-22-contexts-7"></a>
97779860
##### <code>contexts</code>
97789861

97799862
Set this to an array of strings representing the AST context
@@ -10216,7 +10299,7 @@ You could set this regular expression to a more expansive list, or you
1021610299
could restrict it such that even types matching those strings would not
1021710300
need destructuring.
1021810301
10219-
<a name="eslint-plugin-jsdoc-rules-require-param-options-23-contexts-7"></a>
10302+
<a name="eslint-plugin-jsdoc-rules-require-param-options-23-contexts-8"></a>
1022010303
##### <code>contexts</code>
1022110304
1022210305
Set this to an array of strings representing the AST context
@@ -10228,17 +10311,17 @@ which are checked.
1022810311
See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors) section of our README for
1022910312
more on the expected format.
1023010313
10231-
<a name="eslint-plugin-jsdoc-rules-require-param-options-23-checkconstructors-1"></a>
10314+
<a name="eslint-plugin-jsdoc-rules-require-param-options-23-checkconstructors-2"></a>
1023210315
##### <code>checkConstructors</code>
1023310316
1023410317
A value indicating whether `constructor`s should be checked. Defaults to `true`.
1023510318

10236-
<a name="eslint-plugin-jsdoc-rules-require-param-options-23-checkgetters-1"></a>
10319+
<a name="eslint-plugin-jsdoc-rules-require-param-options-23-checkgetters-2"></a>
1023710320
##### <code>checkGetters</code>
1023810321

1023910322
A value indicating whether getters should be checked. Defaults to `false`.
1024010323

10241-
<a name="eslint-plugin-jsdoc-rules-require-param-options-23-checksetters-1"></a>
10324+
<a name="eslint-plugin-jsdoc-rules-require-param-options-23-checksetters-2"></a>
1024210325
##### <code>checkSetters</code>
1024310326

1024410327
A value indicating whether getters should be checked. Defaults to `false`.
@@ -12066,7 +12149,7 @@ or if it is `Promise<void>` or `Promise<undefined>`.
1206612149
<a name="eslint-plugin-jsdoc-rules-require-returns-description-options-24"></a>
1206712150
#### Options
1206812151

12069-
<a name="eslint-plugin-jsdoc-rules-require-returns-description-options-24-contexts-8"></a>
12152+
<a name="eslint-plugin-jsdoc-rules-require-returns-description-options-24-contexts-9"></a>
1207012153
##### <code>contexts</code>
1207112154

1207212155
Set this to an array of strings representing the AST context
@@ -12221,7 +12304,7 @@ Requires that `@returns` tag has `type` value.
1222112304
<a name="eslint-plugin-jsdoc-rules-require-returns-type-options-25"></a>
1222212305
#### Options
1222312306

12224-
<a name="eslint-plugin-jsdoc-rules-require-returns-type-options-25-contexts-9"></a>
12307+
<a name="eslint-plugin-jsdoc-rules-require-returns-type-options-25-contexts-10"></a>
1222512308
##### <code>contexts</code>
1222612309

1222712310
Set this to an array of strings representing the AST context

0 commit comments

Comments
 (0)