Skip to content

Commit 5543c29

Browse files
committed
feat(check-values): add new rule for checking special tag values (within version, since, license, author)
BREAKING CHANGE: Adds to `recommended`. 1. `@version` - Checks that there is a present and valid [semver](https://semver.org/) version value. 2. `@since` - As with `@version` 3. `@license` - Checks that there is a present and valid SPDX identifier or is present within an `allowedLicenses` option. 4. `@author` - Checks there is a value present, and if the option `allowedAuthors` is present, ensure that the author value is one of these array items.
1 parent f919d5a commit 5543c29

File tree

9 files changed

+606
-23
lines changed

9 files changed

+606
-23
lines changed

.README/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ only (e.g., to match `Array` if the type is `Array` vs. `Array.<string>`).
322322
{"gitdown": "include", "file": "./rules/check-syntax.md"}
323323
{"gitdown": "include", "file": "./rules/check-tag-names.md"}
324324
{"gitdown": "include", "file": "./rules/check-types.md"}
325+
{"gitdown": "include", "file": "./rules/check-values.md"}
325326
{"gitdown": "include", "file": "./rules/empty-tags.md"}
326327
{"gitdown": "include", "file": "./rules/implements-on-classes.md"}
327328
{"gitdown": "include", "file": "./rules/match-description.md"}

.README/rules/check-values.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
### `check-values`
2+
3+
This rule checks the values for a handful of tags:
4+
5+
1. `@version` - Checks that there is a present and valid
6+
[semver](https://semver.org/) version value.
7+
2. `@since` - As with `@version`
8+
3. `@license` - Checks that there is a present and valid SPDX identifier
9+
or is present within an `allowedLicenses` option.
10+
4. `@author` - Checks there is a value present, and if the option
11+
`allowedAuthors` is present, ensure that the author value is one
12+
of these array items.
13+
14+
#### Options
15+
16+
##### `allowedAuthors`
17+
18+
An array of allowable author values. If absent, only non-whitespace will
19+
be checked for.
20+
21+
##### `allowedLicenses`
22+
23+
An array of allowable license values or `true` to allow any license text.
24+
If present as an array, will be used in place of SPDX identifiers.
25+
26+
|||
27+
|---|---|
28+
|Context|everywhere|
29+
|Tags|`@version`, `@since`, `@license`, `@author`|
30+
|Options|`allowedAuthors`, `allowedLicenses`|
31+
|Settings|`tagNamePreference`|
32+
33+
<!-- assertions checkValues -->

README.md

Lines changed: 193 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ JSDoc linting rules for ESLint.
2727
* [`check-syntax`](#eslint-plugin-jsdoc-rules-check-syntax)
2828
* [`check-tag-names`](#eslint-plugin-jsdoc-rules-check-tag-names)
2929
* [`check-types`](#eslint-plugin-jsdoc-rules-check-types)
30+
* [`check-values`](#eslint-plugin-jsdoc-rules-check-values)
3031
* [`empty-tags`](#eslint-plugin-jsdoc-rules-empty-tags)
3132
* [`implements-on-classes`](#eslint-plugin-jsdoc-rules-implements-on-classes)
3233
* [`match-description`](#eslint-plugin-jsdoc-rules-match-description)
@@ -3126,6 +3127,177 @@ var subscribe = function(callback) {};
31263127
````
31273128

31283129

3130+
<a name="eslint-plugin-jsdoc-rules-check-values"></a>
3131+
### <code>check-values</code>
3132+
3133+
This rule checks the values for a handful of tags:
3134+
3135+
1. `@version` - Checks that there is a present and valid
3136+
[semver](https://semver.org/) version value.
3137+
2. `@since` - As with `@version`
3138+
3. `@license` - Checks that there is a present and valid SPDX identifier
3139+
or is present within an `allowedLicenses` option.
3140+
4. `@author` - Checks there is a value present, and if the option
3141+
`allowedAuthors` is present, ensure that the author value is one
3142+
of these array items.
3143+
3144+
<a name="eslint-plugin-jsdoc-rules-check-values-options-5"></a>
3145+
#### Options
3146+
3147+
<a name="eslint-plugin-jsdoc-rules-check-values-options-5-allowedauthors"></a>
3148+
##### <code>allowedAuthors</code>
3149+
3150+
An array of allowable author values. If absent, only non-whitespace will
3151+
be checked for.
3152+
3153+
<a name="eslint-plugin-jsdoc-rules-check-values-options-5-allowedlicenses"></a>
3154+
##### <code>allowedLicenses</code>
3155+
3156+
An array of allowable license values or `true` to allow any license text.
3157+
If present as an array, will be used in place of SPDX identifiers.
3158+
3159+
|||
3160+
|---|---|
3161+
|Context|everywhere|
3162+
|Tags|`@version`, `@since`, `@license`, `@author`|
3163+
|Options|`allowedAuthors`, `allowedLicenses`|
3164+
|Settings|`tagNamePreference`|
3165+
3166+
The following patterns are considered problems:
3167+
3168+
````js
3169+
/**
3170+
* @version
3171+
*/
3172+
function quux (foo) {
3173+
3174+
}
3175+
// Message: Missing JSDoc @version.
3176+
3177+
/**
3178+
* @version 3.1
3179+
*/
3180+
function quux (foo) {
3181+
3182+
}
3183+
// Message: Invalid JSDoc @version: "3.1".
3184+
3185+
/**
3186+
* @since
3187+
*/
3188+
function quux (foo) {
3189+
3190+
}
3191+
// Message: Missing JSDoc @since.
3192+
3193+
/**
3194+
* @since 3.1
3195+
*/
3196+
function quux (foo) {
3197+
3198+
}
3199+
// Message: Invalid JSDoc @since: "3.1".
3200+
3201+
/**
3202+
* @license
3203+
*/
3204+
function quux (foo) {
3205+
3206+
}
3207+
// Message: Missing JSDoc @license.
3208+
3209+
/**
3210+
* @license FOO
3211+
*/
3212+
function quux (foo) {
3213+
3214+
}
3215+
// Message: Invalid JSDoc @license: "FOO"; expected SPDX identifier: https://spdx.org/licenses/.
3216+
3217+
/**
3218+
* @license FOO
3219+
*/
3220+
function quux (foo) {
3221+
3222+
}
3223+
// Options: [{"allowedLicenses":["BAR","BAX"]}]
3224+
// Message: Invalid JSDoc @license: "FOO"; expected one of BAR, BAX.
3225+
3226+
/**
3227+
* @author
3228+
*/
3229+
function quux (foo) {
3230+
3231+
}
3232+
// Message: Missing JSDoc @author.
3233+
3234+
/**
3235+
* @author Brett Zamir
3236+
*/
3237+
function quux (foo) {
3238+
3239+
}
3240+
// Options: [{"allowedAuthors":["Gajus Kuizinas","golopot"]}]
3241+
// Message: Invalid JSDoc @author: "Brett Zamir"; expected one of Gajus Kuizinas, golopot.
3242+
````
3243+
3244+
The following patterns are not considered problems:
3245+
3246+
````js
3247+
/**
3248+
* @version 3.4.1
3249+
*/
3250+
function quux (foo) {
3251+
3252+
}
3253+
3254+
/**
3255+
* @since 3.4.1
3256+
*/
3257+
function quux (foo) {
3258+
3259+
}
3260+
3261+
/**
3262+
* @license MIT
3263+
*/
3264+
function quux (foo) {
3265+
3266+
}
3267+
3268+
/**
3269+
* @license FOO
3270+
*/
3271+
function quux (foo) {
3272+
3273+
}
3274+
// Options: [{"allowedLicenses":["FOO","BAR","BAX"]}]
3275+
3276+
/**
3277+
* @license FOO
3278+
*/
3279+
function quux (foo) {
3280+
3281+
}
3282+
// Options: [{"allowedLicenses":true}]
3283+
3284+
/**
3285+
* @author Gajus Kuizinas
3286+
*/
3287+
function quux (foo) {
3288+
3289+
}
3290+
3291+
/**
3292+
* @author Brett Zamir
3293+
*/
3294+
function quux (foo) {
3295+
3296+
}
3297+
// Options: [{"allowedAuthors":["Gajus Kuizinas","golopot","Brett Zamir"]}]
3298+
````
3299+
3300+
31293301
<a name="eslint-plugin-jsdoc-rules-empty-tags"></a>
31303302
### <code>empty-tags</code>
31313303

@@ -3152,10 +3324,10 @@ is set to "closure" (which allows types).
31523324
- `@public`
31533325
- `@static`
31543326

3155-
<a name="eslint-plugin-jsdoc-rules-empty-tags-options-5"></a>
3327+
<a name="eslint-plugin-jsdoc-rules-empty-tags-options-6"></a>
31563328
#### Options
31573329

3158-
<a name="eslint-plugin-jsdoc-rules-empty-tags-options-5-tags"></a>
3330+
<a name="eslint-plugin-jsdoc-rules-empty-tags-options-6-tags"></a>
31593331
##### <code>tags</code>
31603332

31613333
If you want additional tags to be checked for their descriptions, you may
@@ -3370,10 +3542,10 @@ by our supported Node versions):
33703542
Applies to the jsdoc block description and `@description` (or `@desc`)
33713543
by default but the `tags` option (see below) may be used to match other tags.
33723544

3373-
<a name="eslint-plugin-jsdoc-rules-match-description-options-6"></a>
3545+
<a name="eslint-plugin-jsdoc-rules-match-description-options-7"></a>
33743546
#### Options
33753547

3376-
<a name="eslint-plugin-jsdoc-rules-match-description-options-6-matchdescription"></a>
3548+
<a name="eslint-plugin-jsdoc-rules-match-description-options-7-matchdescription"></a>
33773549
##### <code>matchDescription</code>
33783550

33793551
You can supply your own expression to override the default, passing a
@@ -3388,7 +3560,7 @@ You can supply your own expression to override the default, passing a
33883560
As with the default, the supplied regular expression will be applied with the
33893561
Unicode (`"u"`) flag and is *not* case-insensitive.
33903562

3391-
<a name="eslint-plugin-jsdoc-rules-match-description-options-6-tags-1"></a>
3563+
<a name="eslint-plugin-jsdoc-rules-match-description-options-7-tags-1"></a>
33923564
##### <code>tags</code>
33933565

33943566
If you want different regular expressions to apply to tags, you may use
@@ -3425,7 +3597,7 @@ its "description" (e.g., for `@returns {someType} some description`, the
34253597
description is `some description` while for `@some-tag xyz`, the description
34263598
is `xyz`).
34273599

3428-
<a name="eslint-plugin-jsdoc-rules-match-description-options-6-maindescription"></a>
3600+
<a name="eslint-plugin-jsdoc-rules-match-description-options-7-maindescription"></a>
34293601
##### <code>mainDescription</code>
34303602

34313603
If you wish to override the main function description without changing the
@@ -3447,7 +3619,7 @@ There is no need to add `mainDescription: true`, as by default, the main
34473619
function (and only the main function) is linted, though you may disable checking
34483620
it by setting it to `false`.
34493621

3450-
<a name="eslint-plugin-jsdoc-rules-match-description-options-6-contexts"></a>
3622+
<a name="eslint-plugin-jsdoc-rules-match-description-options-7-contexts"></a>
34513623
##### <code>contexts</code>
34523624

34533625
Set this to an array of strings representing the AST context
@@ -4067,7 +4239,7 @@ function quux () {
40674239

40684240
Enforces a consistent padding of the block description.
40694241

4070-
<a name="eslint-plugin-jsdoc-rules-newline-after-description-options-7"></a>
4242+
<a name="eslint-plugin-jsdoc-rules-newline-after-description-options-8"></a>
40714243
#### Options
40724244

40734245
This rule allows one optional string argument. If it is `"always"` then a problem is raised when there is no newline after the description. If it is `"never"` then a problem is raised when there is a newline after the description. The default value is `"always"`.
@@ -4251,7 +4423,7 @@ The following types are always considered defined.
42514423
Note that preferred types indicated within `settings.jsdoc.preferredTypes` will
42524424
also be assumed to be defined.
42534425

4254-
<a name="eslint-plugin-jsdoc-rules-no-undefined-types-options-8"></a>
4426+
<a name="eslint-plugin-jsdoc-rules-no-undefined-types-options-9"></a>
42554427
#### Options
42564428

42574429
An option object may have the following key:
@@ -4633,10 +4805,10 @@ tag descriptions are written in complete sentences, i.e.,
46334805
* A colon or semi-colon followed by two line breaks is still part of the
46344806
containing paragraph (unlike normal dual line breaks).
46354807

4636-
<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-9"></a>
4808+
<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-10"></a>
46374809
#### Options
46384810

4639-
<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-9-tags-2"></a>
4811+
<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-10-tags-2"></a>
46404812
##### <code>tags</code>
46414813

46424814
If you want additional tags to be checked for their descriptions, you may
@@ -5108,7 +5280,7 @@ Requires that all functions have a description.
51085280
`"tag"`) must have a non-empty description that explains the purpose of the
51095281
method.
51105282

5111-
<a name="eslint-plugin-jsdoc-rules-require-description-options-10"></a>
5283+
<a name="eslint-plugin-jsdoc-rules-require-description-options-11"></a>
51125284
#### Options
51135285

51145286
An options object may have any of the following properties:
@@ -5393,25 +5565,25 @@ Requires that all functions have examples.
53935565
* All functions must have one or more `@example` tags.
53945566
* Every example tag must have a non-empty description that explains the method's usage.
53955567

5396-
<a name="eslint-plugin-jsdoc-rules-require-example-options-11"></a>
5568+
<a name="eslint-plugin-jsdoc-rules-require-example-options-12"></a>
53975569
#### Options
53985570

53995571
This rule has an object option.
54005572

5401-
<a name="eslint-plugin-jsdoc-rules-require-example-options-11-exemptedby"></a>
5573+
<a name="eslint-plugin-jsdoc-rules-require-example-options-12-exemptedby"></a>
54025574
##### <code>exemptedBy</code>
54035575

54045576
Array of tags (e.g., `['type']`) whose presence on the document
54055577
block avoids the need for an `@example`. Defaults to an empty array.
54065578

5407-
<a name="eslint-plugin-jsdoc-rules-require-example-options-11-avoidexampleonconstructors"></a>
5579+
<a name="eslint-plugin-jsdoc-rules-require-example-options-12-avoidexampleonconstructors"></a>
54085580
##### <code>avoidExampleOnConstructors</code>
54095581

54105582
Set to `true` to avoid the need for an example on a constructor (whether
54115583
indicated as such by a jsdoc tag or by being within an ES6 `class`).
54125584
Defaults to `false`.
54135585

5414-
<a name="eslint-plugin-jsdoc-rules-require-example-options-11-contexts-1"></a>
5586+
<a name="eslint-plugin-jsdoc-rules-require-example-options-12-contexts-1"></a>
54155587
##### <code>contexts</code>
54165588

54175589
Set this to an array of strings representing the AST context
@@ -5589,7 +5761,7 @@ function quux () {
55895761

55905762
Requires a hyphen before the `@param` description.
55915763

5592-
<a name="eslint-plugin-jsdoc-rules-require-hyphen-before-param-description-options-12"></a>
5764+
<a name="eslint-plugin-jsdoc-rules-require-hyphen-before-param-description-options-13"></a>
55935765
#### Options
55945766

55955767
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"`.
@@ -5695,7 +5867,7 @@ function quux () {
56955867
Checks for presence of jsdoc comments, on class declarations as well as
56965868
functions.
56975869

5698-
<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-13"></a>
5870+
<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-14"></a>
56995871
#### Options
57005872

57015873
Accepts one optional options object with the following optional keys.
@@ -6883,7 +7055,7 @@ function quux (foo) {
68837055

68847056
Requires that all function parameters are documented.
68857057

6886-
<a name="eslint-plugin-jsdoc-rules-require-param-options-14"></a>
7058+
<a name="eslint-plugin-jsdoc-rules-require-param-options-15"></a>
68877059
#### Options
68887060

68897061
An options object accepts one optional property:
@@ -7956,7 +8128,7 @@ Requires returns are documented.
79568128

79578129
Will also report if multiple `@returns` tags are present.
79588130

7959-
<a name="eslint-plugin-jsdoc-rules-require-returns-options-15"></a>
8131+
<a name="eslint-plugin-jsdoc-rules-require-returns-options-16"></a>
79608132
#### Options
79618133

79628134
- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the document
@@ -8421,7 +8593,7 @@ Also impacts behaviors on namepath (or event)-defining and pointing tags:
84218593
allow `#`, `.`, or `~` at the end (which is not allowed at the end of
84228594
normal paths).
84238595

8424-
<a name="eslint-plugin-jsdoc-rules-valid-types-options-16"></a>
8596+
<a name="eslint-plugin-jsdoc-rules-valid-types-options-17"></a>
84258597
#### Options
84268598

84278599
- `allowEmptyNamepaths` (default: true) - Set to `false` to disallow

0 commit comments

Comments
 (0)