Skip to content

Commit fec8b67

Browse files
committed
Merge branch 'master' into add-more-type-checks-to-valid-types
* master: feat(require-description-complete-sentence): validate explicit `description` tags fix(check-types): remove template substitution variables, `badType`, `preferredType`, and `replacement` (gajus#310) feat: remove `preferredTypesDefined` option in favor of making it apply automatically feat(check-tag-names): auto-allow tags in `tagNamePreference` setting to be defined; add `definedTags` option to replace `additionalTagNames.customTags` setting feat(check-tag-names): allow rejecting normally valid tag names and/or providing custom error messages when suggesting tags to reject or replace (fixes gajus#108) Allow rejecting normally valid tag names and/or providing custom error messages when suggesting tags to reject or replace (gajus#302) docs: indicate option defaults (fixes part of gajus#256) and ensure optioins all listed in docs chore: update Babel devDeps. feat(no-undefined-types): handle GCC generic functions docs: generate docs Add an invalid test case for incorrect @template type fix: reverse jsdoctypeparser update until traversal issue with "external:..." can be fixed feat: bump jsdoctypeparser to 5.0.0 docs: generate docs Add support for generic functions in addition to classes
2 parents 4549593 + 3479aaf commit fec8b67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1142
-286
lines changed

.README/README.md

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,61 @@ Use `settings.jsdoc.tagNamePreference` to configure a preferred alias name for a
147147
}
148148
```
149149

150+
One may also use an object with a `message` and `replacement`.
151+
152+
The following will report the message `@extends is to be used over @augments as it is more evocative of classes than @augments` upon encountering `@augments`.
153+
154+
```json
155+
{
156+
"rules": {},
157+
"settings": {
158+
"jsdoc": {
159+
"tagNamePreference": {
160+
"augments": {
161+
"message": "@extends is to be used over @augments as it is more evocative of classes than @augments",
162+
"replacement": "extends"
163+
}
164+
}
165+
}
166+
}
167+
}
168+
```
169+
170+
If one wishes to reject a normally valid tag, e.g., `@todo`, one may set the tag to `false`:
171+
172+
```json
173+
{
174+
"rules": {},
175+
"settings": {
176+
"jsdoc": {
177+
"tagNamePreference": {
178+
"todo": false
179+
}
180+
}
181+
}
182+
}
183+
```
184+
185+
Or one may set the targeted tag to an object with a custom `message`, but without a `replacement` property:
186+
187+
```json
188+
{
189+
"rules": {},
190+
"settings": {
191+
"jsdoc": {
192+
"tagNamePreference": {
193+
"todo": {
194+
"message": "We expect immediate perfection, so don't leave to-dos in your code."
195+
}
196+
}
197+
}
198+
}
199+
}
200+
```
201+
202+
Note that the preferred tags indicated in the `settings.jsdoc.tagNamePreference`
203+
map will be assumed to be defined by `check-tag-names`.
204+
150205
The defaults in `eslint-plugin-jsdoc` (for tags which offer
151206
aliases) are as follows:
152207

@@ -183,24 +238,6 @@ This setting is utilized by the the rule for tag name checking
183238
- `require-returns-description`
184239
- `require-returns-type`
185240

186-
### Additional Tag Names
187-
188-
Use `settings.jsdoc.additionalTagNames` to configure additional, allowed JSDoc
189-
tags in the rule `check-tag-names`. The format of the configuration is as follows:
190-
191-
```json
192-
{
193-
"rules": {},
194-
"settings": {
195-
"jsdoc": {
196-
"additionalTagNames": {
197-
"customTags": ["define", "record"]
198-
}
199-
}
200-
}
201-
}
202-
```
203-
204241
### `@override`/`@augments`/`@extends`/`@implements` Without Accompanying `@param`/`@description`/`@example`/`@returns`
205242

206243
The following settings allows the element(s) they reference to be omitted
@@ -272,15 +309,12 @@ but restricted to `@param`. These settings are now deprecated.
272309
when encountering the discouraged type and, if a type is to be preferred
273310
in its place, the key `replacement` to indicate the type that should be
274311
used in its place (and which `fix` mode can replace) or `false` if
275-
forbidding the type. The message string will have the following
276-
substrings with special meaning replaced with their corresponding
277-
value (`{{tagName}}`, `{{tagValue}}`, `{{badType}}`, and
278-
`{{preferredType}}` (or `{{replacement}}`), noting that the latter is
279-
of no use when one is merely forbidding a type).
280-
281-
If `no-undefined-types` has the option key `preferredTypesDefined` set to
282-
`true`, the preferred types indicated in the `settings.jsdoc.preferredTypes`
283-
map will be assumed to be defined.
312+
forbidding the type. The message string will have the substrings with
313+
special meaning, `{{tagName}}` and `{{tagValue}}`, replaced with their
314+
corresponding value.
315+
316+
Note that the preferred types indicated as targets in `settings.jsdoc.preferredTypes`
317+
map will be assumed to be defined by `no-undefined-types`.
284318

285319
See the option of `check-types`, `unifyParentAndChildTypeChecks`, for
286320
how the keys of `preferredTypes` may have `<>` or `.<>` (or just `.`)

.README/rules/check-tag-names.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,26 @@ version
7575
yields
7676
```
7777

78+
Note that the tags indicated as replacements in `settings.jsdoc.tagNamePreference` will automatically be considered as valid.
79+
80+
#### Options
81+
82+
##### `definedTags`
83+
84+
Use an array of `definedTags` strings to configure additional, allowed JSDoc tags.
85+
The format is as follows:
86+
87+
```json
88+
{
89+
"definedTags": ["define", "record"]
90+
}
91+
```
92+
7893
|||
7994
|---|---|
8095
|Context|everywhere|
8196
|Tags|N/A|
82-
|Settings|`tagNamePreference`, `additionalTagNames`|
97+
|Options|`definedTags`|
98+
|Settings|`tagNamePreference`|
8399

84100
<!-- assertions checkTagNames -->

.README/rules/check-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ RegExp
2424
- An option object:
2525
- with the key `noDefaults` to insist that only the supplied option type
2626
map is to be used, and that the default preferences (such as "string"
27-
over "String") will not be enforced.
27+
over "String") will not be enforced. The option's default is `false`.
2828
- with the key `unifyParentAndChildTypeChecks` which will treat
2929
`settings.jsdoc.preferredTypes` keys such as `SomeType` as matching
3030
not only child types such as an unadorned `SomeType` but also

.README/rules/match-description.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ tag should be linted with the `matchDescription` value (or the default).
5050
}
5151
```
5252

53+
##### `mainDescription`
54+
5355
If you wish to override the main function description without changing the
5456
default `match-description`, you may use `mainDescription`:
5557

@@ -73,13 +75,13 @@ it by setting it to `false`.
7375

7476
Set this to an array of strings representing the AST context
7577
where you wish the rule to be applied (e.g., `ClassDeclaration` for ES6 classes).
76-
Overrides the defaults.
78+
Overrides the default contexts (see below).
7779

7880
|||
7981
|---|---|
8082
|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
8183
|Tags|N/A by default but see `tags` options|
8284
|Settings||
83-
|Options|`contexts`, `tags` (allows for 'param', 'arg', 'argument', 'returns', 'return'), `matchDescription`|
85+
|Options|`contexts`, `tags` (allows for 'param', 'arg', 'argument', 'returns', 'return'), `mainDescription`, `matchDescription`|
8486

8587
<!-- assertions matchDescription -->

.README/rules/newline-after-description.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
Enforces a consistent padding of the block description.
44

5-
This rule takes one argument. If it is `"always"` then a problem is raised when there is a newline after the description. If it is `"never"` then a problem is raised when there is no newline after the description. The default value is `"always"`.
5+
#### Options
6+
7+
This rule allows one optional string argument. If it is `"always"` then a problem is raised when there is a newline after the description. If it is `"never"` then a problem is raised when there is no newline after the description. The default value is `"always"`.
68

79
|||
810
|---|---|
911
|Context|everywhere|
12+
|Options|(a string matching `"always"|"never"`)|
1013
|Tags|N/A|
1114

1215
<!-- assertions newlineAfterDescription -->

.README/rules/no-undefined-types.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,24 @@ The following types are always considered defined.
2020
- `any`, `*`
2121
- `Array`, `Object`, `RegExp`, `Date`, `Function`
2222

23+
Note that preferred types indicated within `settings.jsdoc.preferredTypes` will
24+
also be assumed to be defined.
25+
2326
#### Options
2427

25-
An option object may have the following keys:
28+
An option object may have the following key:
2629

27-
- `preferredTypesDefined` - If this option is set to `true` and preferred
28-
types are indicated within `settings.jsdoc.preferredTypes`, any such
29-
types will be assumed to be defined as well.
3030
- `definedTypes` - This array can be populated to indicate other types which
31-
are automatically considered as defined (in addition to globals, etc.)
31+
are automatically considered as defined (in addition to globals, etc.).
32+
Defaults to an empty array.
3233

3334
|||
3435
|---|---|
3536
|Context|everywhere|
3637
|Tags|`class`, `constant`, `enum`, `implements`, `member`, `module`, `namespace`, `param`, `property`, `returns`, `throws`, `type`, `typedef`, `yields`|
3738
|Aliases|`constructor`, `const`, `var`, `arg`, `argument`, `prop`, `return`, `exception`, `yield`|
3839
|Closure-only|`package`, `private`, `protected`, `public`, `static`|
39-
|Options|`preferredTypesDefined`, `definedTypes`|
40+
|Options|`definedTypes`|
4041
|Settings|`preferredTypes`|
4142

4243
<!-- assertions noUndefinedTypes -->
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
### `require-description-complete-sentence`
22

3-
Requires that block description and tag description are written in complete sentences, i.e.,
3+
Requires that block description, explicit `@description`, and `@param`/`@returns`
4+
tag descriptions are written in complete sentences, i.e.,
45

56
* Description must start with an uppercase alphabetical character.
67
* Paragraphs must start with an uppercase alphabetical character.
78
* Sentences must end with a period.
8-
* Every line in a paragraph (except the first) which starts with an uppercase character must be preceded by a line ending with a period.
9+
* Every line in a paragraph (except the first) which starts with an uppercase
10+
character must be preceded by a line ending with a period.
911

1012
|||
1113
|---|---|
1214
|Context|everywhere|
13-
|Tags|`param`, `returns`|
14-
|Aliases|`arg`, `argument`, `return`|
15+
|Tags|`param`, `returns`, `description`|
16+
|Aliases|`arg`, `argument`, `return`, `desc`|
1517

1618
<!-- assertions requireDescriptionCompleteSentence -->

.README/rules/require-description.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ An options object may have any of the following properties:
1111

1212
- `contexts` - Set to an array of strings representing the AST context
1313
where you wish the rule to be applied (e.g., `ClassDeclaration` for ES6 classes).
14-
Overrides the defaults.
14+
Overrides the default contexts (see below).
1515
- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the document
16-
block avoids the need for a `@description`.
16+
block avoids the need for a `@description`. Defaults to an empty array.
1717

1818
|||
1919
|---|---|

.README/rules/require-example.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Requires that all functions have examples.
1010
Has an object option with one optional property:
1111

1212
- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the document
13-
block avoids the need for an `@example`.
13+
block avoids the need for an `@example`. Defaults to an empty array.
1414

1515
|||
1616
|---|---|

.README/rules/require-hyphen-before-param-description.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
Requires a hyphen before the `@param` description.
44

5-
This rule takes one argument. If it is `"always"` then a problem is raised when there is no hyphen before the description. If it is `"never"` then a problem is raised when there is a hyphen before the description. The default value is `"always"`.
5+
#### Options
6+
7+
This rule takes one optional string argument. If it is `"always"` then a problem is raised when there is no hyphen before the description. If it is `"never"` then a problem is raised when there is a hyphen before the description. The default value is `"always"`.
68

79
|||
810
|---|---|
911
|Context|everywhere|
1012
|Tags|`param`|
1113
|Aliases|`arg`, `argument`|
14+
|Options|(a string matching `"always"|"never"`)|
1215

1316
<!-- assertions requireHyphenBeforeParamDescription -->

.README/rules/require-jsdoc.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ functions.
55

66
#### Options
77

8-
Accepts one optional options object, with two optional keys, `publicOnly`
9-
for confining JSDoc comments to be checked to exported functions (with "exported"
10-
allowing for ESM exports, CJS exports, or browser window global export)
11-
in `require-jsdoc`, and `require` for limiting the contexts which are to
12-
be checked by the rule.
8+
Accepts one optional options object with the following optional keys.
139

14-
- `publicOnly` - Missing jsdoc blocks are only reported for function
15-
bodies / class declarations that are exported from the module.
16-
May be a boolean or object. If set to `true`, the defaults below will
17-
be used.
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.
1815

1916
This object supports the following optional boolean keys (`false` unless
2017
otherwise noted):
@@ -25,7 +22,8 @@ be checked by the rule.
2522
- `window` - Window global exports are checked for JSDoc comments
2623

2724
- `require` - An object with the following optional boolean keys which all
28-
default to `false` except as noted:
25+
default to `false` except as noted, indicating the contexts where the rule
26+
will apply:
2927

3028
- `ArrowFunctionExpression`
3129
- `ClassDeclaration`
@@ -35,13 +33,14 @@ be checked by the rule.
3533
- `MethodDefinition`
3634

3735
- `contexts` - Set this to an array of strings representing the additional
38-
AST context where you wish the rule to be applied (e.g., `Property` for properties).
36+
AST contexts where you wish the rule to be applied (e.g., `Property` for
37+
properties). Defaults to an empty array.
3938

4039
|||
4140
|---|---|
4241
|Context|`ArrowFunctionExpression`, `ClassDeclaration`, `ClassExpression`, `FunctionDeclaration`, `FunctionExpression`|
4342
|Tags|N/A|
44-
|Options|`publicOnly`|
43+
|Options|`publicOnly`, `require`, `contexts`|
4544
|Settings|`exemptEmptyFunctions`|
4645

4746
<!-- assertions requireJsdoc -->

.README/rules/require-param.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Requires that all function parameters are documented.
77
An options object accepts one optional property:
88

99
- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the document
10-
block avoids the need for a `@param`.
10+
block avoids the need for a `@param`. Defaults to an empty array.
1111

1212
|||
1313
|---|---|

.README/rules/require-returns.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Requires returns are documented.
55
#### Options
66

77
- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the document
8-
block avoids the need for a `@returns`.
9-
- `forceReturnsWithAsync` - By default `async` functions that do not explicitly return a value pass this rule. You can force all `async` functions to require return statements by setting `forceReturnsWithAsync` as true on the options object. This may be useful as an `async` function will always return a Promise, even if the Promise returns void.
8+
block avoids the need for a `@returns`. Defaults to an empty array.
9+
- `forceReturnsWithAsync` - By default `async` functions that do not explicitly return a value pass this rule. You can force all `async` functions to require return statements by setting `forceReturnsWithAsync` to `true` on the options object. This may be useful as an `async` function will always return a `Promise`, even if the `Promise` returns void. Defaults to `false`.
1010

1111
```js
1212
'jsdoc/require-jsdoc': ['error', {forceReturnsWithAsync: true}]

0 commit comments

Comments
 (0)