Skip to content

Commit 9df41d7

Browse files
committed
feat(check-tag-names): auto-allow tags in tagNamePreference setting to be defined; add definedTags option to replace additionalTagNames.customTags setting
BREAKING CHANGE: Switch `additionalTagNames.customTags` setting to `definedTags` option (only used by one rule)
1 parent a367c48 commit 9df41d7

File tree

8 files changed

+179
-93
lines changed

8 files changed

+179
-93
lines changed

.README/README.md

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ Or one may set the targeted tag to an object with a custom `message`, but withou
199199
}
200200
```
201201

202+
Note that the preferred tags indicated in the `settings.jsdoc.tagNamePreference`
203+
map will be assumed to be defined by `check-tag-names`.
202204

203205
The defaults in `eslint-plugin-jsdoc` (for tags which offer
204206
aliases) are as follows:
@@ -236,24 +238,6 @@ This setting is utilized by the the rule for tag name checking
236238
- `require-returns-description`
237239
- `require-returns-type`
238240

239-
### Additional Tag Names
240-
241-
Use `settings.jsdoc.additionalTagNames` to configure additional, allowed JSDoc
242-
tags in the rule `check-tag-names`. The format of the configuration is as follows:
243-
244-
```json
245-
{
246-
"rules": {},
247-
"settings": {
248-
"jsdoc": {
249-
"additionalTagNames": {
250-
"customTags": ["define", "record"]
251-
}
252-
}
253-
}
254-
}
255-
```
256-
257241
### `@override`/`@augments`/`@extends`/`@implements` Without Accompanying `@param`/`@description`/`@example`/`@returns`
258242

259243
The following settings allows the element(s) they reference to be omitted

.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.md

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ JSDoc linting rules for ESLint.
1616
* [Allow `@private` to disable rules for that comment block](#eslint-plugin-jsdoc-settings-allow-private-to-disable-rules-for-that-comment-block)
1717
* [Exempting empty functions from `require-jsdoc`](#eslint-plugin-jsdoc-settings-exempting-empty-functions-from-require-jsdoc)
1818
* [Alias Preference](#eslint-plugin-jsdoc-settings-alias-preference)
19-
* [Additional Tag Names](#eslint-plugin-jsdoc-settings-additional-tag-names)
2019
* [`@override`/`@augments`/`@extends`/`@implements` Without Accompanying `@param`/`@description`/`@example`/`@returns`](#eslint-plugin-jsdoc-settings-override-augments-extends-implements-without-accompanying-param-description-example-returns)
2120
* [Settings to Configure `check-types` and `no-undefined-types`](#eslint-plugin-jsdoc-settings-settings-to-configure-check-types-and-no-undefined-types)
2221
* [Settings to Configure `valid-types`](#eslint-plugin-jsdoc-settings-settings-to-configure-valid-types)
@@ -249,6 +248,8 @@ Or one may set the targeted tag to an object with a custom `message`, but withou
249248
}
250249
```
251250

251+
Note that the preferred tags indicated in the `settings.jsdoc.tagNamePreference`
252+
map will be assumed to be defined by `check-tag-names`.
252253

253254
The defaults in `eslint-plugin-jsdoc` (for tags which offer
254255
aliases) are as follows:
@@ -286,25 +287,6 @@ This setting is utilized by the the rule for tag name checking
286287
- `require-returns-description`
287288
- `require-returns-type`
288289

289-
<a name="eslint-plugin-jsdoc-settings-additional-tag-names"></a>
290-
### Additional Tag Names
291-
292-
Use `settings.jsdoc.additionalTagNames` to configure additional, allowed JSDoc
293-
tags in the rule `check-tag-names`. The format of the configuration is as follows:
294-
295-
```json
296-
{
297-
"rules": {},
298-
"settings": {
299-
"jsdoc": {
300-
"additionalTagNames": {
301-
"customTags": ["define", "record"]
302-
}
303-
}
304-
}
305-
}
306-
```
307-
308290
<a name="eslint-plugin-jsdoc-settings-override-augments-extends-implements-without-accompanying-param-description-example-returns"></a>
309291
### <code>@override</code>/<code>@augments</code>/<code>@extends</code>/<code>@implements</code> Without Accompanying <code>@param</code>/<code>@description</code>/<code>@example</code>/<code>@returns</code>
310292

@@ -1249,11 +1231,29 @@ version
12491231
yields
12501232
```
12511233

1234+
Note that the tags indicated as replacements in `settings.jsdoc.tagNamePreference` will automatically be considered as valid.
1235+
1236+
<a name="eslint-plugin-jsdoc-rules-check-tag-names-options"></a>
1237+
#### Options
1238+
1239+
<a name="eslint-plugin-jsdoc-rules-check-tag-names-options-definedtags"></a>
1240+
##### <code>definedTags</code>
1241+
1242+
Use an array of `definedTags` strings to configure additional, allowed JSDoc tags.
1243+
The format is as follows:
1244+
1245+
```json
1246+
{
1247+
"definedTags": ["define", "record"]
1248+
}
1249+
```
1250+
12521251
|||
12531252
|---|---|
12541253
|Context|everywhere|
12551254
|Tags|N/A|
1256-
|Settings|`tagNamePreference`, `additionalTagNames`|
1255+
|Options|`definedTags`|
1256+
|Settings|`tagNamePreference`|
12571257

12581258
The following patterns are considered problems:
12591259

@@ -1327,7 +1327,7 @@ function quux (foo) {
13271327
function quux (foo) {
13281328

13291329
}
1330-
// Settings: {"jsdoc":{"additionalTagNames":{"customTags":["bar"]}}}
1330+
// Options: [{"definedTags":["bar"]}]
13311331
// Message: Invalid JSDoc tag name "baz".
13321332

13331333
/**
@@ -1337,7 +1337,7 @@ function quux (foo) {
13371337
function quux (foo) {
13381338

13391339
}
1340-
// Settings: {"jsdoc":{"additionalTagNames":{"customTags":["bar"]}}}
1340+
// Options: [{"definedTags":["bar"]}]
13411341
// Message: Invalid JSDoc tag name "baz".
13421342

13431343
/**
@@ -1375,6 +1375,15 @@ function quux () {
13751375
}
13761376
// Settings: {"jsdoc":{"tagNamePreference":{"todo":{"message":"Please use x-todo instead of todo","replacement":"x-todo"}}}}
13771377
// Message: Please use x-todo instead of todo
1378+
1379+
/**
1380+
* @todo
1381+
*/
1382+
function quux () {
1383+
1384+
}
1385+
// Settings: {"jsdoc":{"tagNamePreference":{"todo":55}}}
1386+
// Message: Invalid `settings.jsdoc.tagNamePreference`. Values must be falsy, a string, or an object.
13781387
````
13791388

13801389
The following patterns are not considered problems:
@@ -1408,15 +1417,23 @@ function quux (foo) {
14081417
function quux (foo) {
14091418

14101419
}
1411-
// Settings: {"jsdoc":{"additionalTagNames":{"customTags":["bar"]}}}
1420+
// Options: [{"definedTags":["bar"]}]
1421+
1422+
/**
1423+
* @baz @bar foo
1424+
*/
1425+
function quux (foo) {
1426+
1427+
}
1428+
// Options: [{"definedTags":["baz","bar"]}]
14121429

14131430
/**
14141431
* @baz @bar foo
14151432
*/
14161433
function quux (foo) {
14171434

14181435
}
1419-
// Settings: {"jsdoc":{"additionalTagNames":{"customTags":["baz","bar"]}}}
1436+
// Settings: {"jsdoc":{"tagNamePreference":{"param":"baz","returns":{"message":"Prefer `bar`","replacement":"bar"},"todo":false}}}
14201437

14211438
/**
14221439
* @abstract
@@ -1521,7 +1538,7 @@ Date
15211538
RegExp
15221539
```
15231540

1524-
<a name="eslint-plugin-jsdoc-rules-check-types-options"></a>
1541+
<a name="eslint-plugin-jsdoc-rules-check-types-options-1"></a>
15251542
#### Options
15261543

15271544
`check-types` allows one option:
@@ -2402,10 +2419,10 @@ by our supported Node versions):
24022419

24032420
``^([A-Z]|[`\\d_])[\\s\\S]*[.?!`]$``
24042421

2405-
<a name="eslint-plugin-jsdoc-rules-match-description-options-1"></a>
2422+
<a name="eslint-plugin-jsdoc-rules-match-description-options-2"></a>
24062423
#### Options
24072424

2408-
<a name="eslint-plugin-jsdoc-rules-match-description-options-1-matchdescription"></a>
2425+
<a name="eslint-plugin-jsdoc-rules-match-description-options-2-matchdescription"></a>
24092426
##### <code>matchDescription</code>
24102427

24112428
You can supply your own expression to override the default, passing a
@@ -2420,7 +2437,7 @@ You can supply your own expression to override the default, passing a
24202437
As with the default, the supplied regular expression will be applied with the
24212438
Unicode (`"u"`) flag and is *not* case-insensitive.
24222439

2423-
<a name="eslint-plugin-jsdoc-rules-match-description-options-1-tags"></a>
2440+
<a name="eslint-plugin-jsdoc-rules-match-description-options-2-tags"></a>
24242441
##### <code>tags</code>
24252442

24262443
If you want different regular expressions to apply to tags, you may use
@@ -2447,7 +2464,7 @@ tag should be linted with the `matchDescription` value (or the default).
24472464
}
24482465
```
24492466

2450-
<a name="eslint-plugin-jsdoc-rules-match-description-options-1-maindescription"></a>
2467+
<a name="eslint-plugin-jsdoc-rules-match-description-options-2-maindescription"></a>
24512468
##### <code>mainDescription</code>
24522469

24532470
If you wish to override the main function description without changing the
@@ -2469,7 +2486,7 @@ There is no need to add `mainDescription: true`, as by default, the main
24692486
function (and only the main function) is linted, though you may disable checking
24702487
it by setting it to `false`.
24712488

2472-
<a name="eslint-plugin-jsdoc-rules-match-description-options-1-contexts"></a>
2489+
<a name="eslint-plugin-jsdoc-rules-match-description-options-2-contexts"></a>
24732490
##### <code>contexts</code>
24742491

24752492
Set this to an array of strings representing the AST context
@@ -2915,7 +2932,7 @@ const q = {
29152932

29162933
Enforces a consistent padding of the block description.
29172934

2918-
<a name="eslint-plugin-jsdoc-rules-newline-after-description-options-2"></a>
2935+
<a name="eslint-plugin-jsdoc-rules-newline-after-description-options-3"></a>
29192936
#### Options
29202937

29212938
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"`.
@@ -3075,7 +3092,7 @@ The following types are always considered defined.
30753092
- `any`, `*`
30763093
- `Array`, `Object`, `RegExp`, `Date`, `Function`
30773094

3078-
<a name="eslint-plugin-jsdoc-rules-no-undefined-types-options-3"></a>
3095+
<a name="eslint-plugin-jsdoc-rules-no-undefined-types-options-4"></a>
30793096
#### Options
30803097

30813098
An option object may have the following keys:
@@ -3671,7 +3688,7 @@ Requires that all functions have a description.
36713688
* All functions must have a `@description` tag.
36723689
* Every description tag must have a non-empty description that explains the purpose of the method.
36733690

3674-
<a name="eslint-plugin-jsdoc-rules-require-description-options-4"></a>
3691+
<a name="eslint-plugin-jsdoc-rules-require-description-options-5"></a>
36753692
#### Options
36763693

36773694
An options object may have any of the following properties:
@@ -3865,7 +3882,7 @@ Requires that all functions have examples.
38653882
* All functions must have one or more `@example` tags.
38663883
* Every example tag must have a non-empty description that explains the method's usage.
38673884

3868-
<a name="eslint-plugin-jsdoc-rules-require-example-options-5"></a>
3885+
<a name="eslint-plugin-jsdoc-rules-require-example-options-6"></a>
38693886
#### Options
38703887

38713888
Has an object option with one optional property:
@@ -3996,7 +4013,7 @@ function quux () {
39964013

39974014
Requires a hyphen before the `@param` description.
39984015

3999-
<a name="eslint-plugin-jsdoc-rules-require-hyphen-before-param-description-options-6"></a>
4016+
<a name="eslint-plugin-jsdoc-rules-require-hyphen-before-param-description-options-7"></a>
40004017
#### Options
40014018

40024019
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"`.
@@ -4102,7 +4119,7 @@ function quux () {
41024119
Checks for presence of jsdoc comments, on class declarations as well as
41034120
functions.
41044121

4105-
<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-7"></a>
4122+
<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-8"></a>
41064123
#### Options
41074124

41084125
Accepts one optional options object with the following optional keys.
@@ -5138,7 +5155,7 @@ function quux (foo) {
51385155

51395156
Requires that all function parameters are documented.
51405157

5141-
<a name="eslint-plugin-jsdoc-rules-require-param-options-8"></a>
5158+
<a name="eslint-plugin-jsdoc-rules-require-param-options-9"></a>
51425159
#### Options
51435160

51445161
An options object accepts one optional property:
@@ -6065,7 +6082,7 @@ function quux () {
60656082

60666083
Requires returns are documented.
60676084

6068-
<a name="eslint-plugin-jsdoc-rules-require-returns-options-9"></a>
6085+
<a name="eslint-plugin-jsdoc-rules-require-returns-options-10"></a>
60696086
#### Options
60706087

60716088
- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the document

src/iterateJsdoc.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const getUtils = (
2828
jsdocNode,
2929
{
3030
tagNamePreference,
31-
additionalTagNames,
3231
allowEmptyNamepaths,
3332
overrideReplacesDocs,
3433
implementsReplacesDocs,
@@ -89,8 +88,8 @@ const getUtils = (
8988
return isObject && !allowObjectReturn ? ret.replacement : ret;
9089
};
9190

92-
utils.isValidTag = (name) => {
93-
return jsdocUtils.isValidTag(name, additionalTagNames);
91+
utils.isValidTag = (name, definedTags) => {
92+
return jsdocUtils.isValidTag(name, definedTags);
9493
};
9594

9695
utils.hasATag = (name) => {
@@ -261,9 +260,6 @@ const getSettings = (context) => {
261260
settings.implementsReplacesDocs = _.get(context, 'settings.jsdoc.implementsReplacesDocs');
262261
settings.augmentsExtendsReplacesDocs = _.get(context, 'settings.jsdoc.augmentsExtendsReplacesDocs');
263262

264-
// `check-tag-names` only
265-
settings.additionalTagNames = _.get(context, 'settings.jsdoc.additionalTagNames') || {};
266-
267263
// `check-examples` only
268264
settings.exampleCodeRegex = _.get(context, 'settings.jsdoc.exampleCodeRegex') || null;
269265
settings.rejectExampleCodeRegex = _.get(context, 'settings.jsdoc.rejectExampleCodeRegex') || null;

src/jsdocUtils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ const getPreferredTagName = (name : string, tagPreference : Object = {}) : strin
7979
return name;
8080
};
8181

82-
const isValidTag = (name : string, additionalTagNames : Object) : boolean => {
82+
const isValidTag = (name : string, definedTags : Array) : boolean => {
8383
const validTagNames = _.keys(tagNames).concat(_.flatten(_.values(tagNames)));
84-
const additionalTags = additionalTagNames.customTags || [];
84+
const additionalTags = definedTags;
8585
const allTags = validTagNames.concat(additionalTags);
8686

8787
return allTags.includes(name);

0 commit comments

Comments
 (0)