Skip to content

Commit eb92080

Browse files
committed
feat(check-values): add checking of kind
Also, updates jsdoccomment and devDeps.
1 parent a5ad499 commit eb92080

File tree

5 files changed

+113
-5
lines changed

5 files changed

+113
-5
lines changed

.README/rules/check-values.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ This rule checks the values for a handful of tags:
1313
5. `@variation` - If `numericOnlyVariation` is set, will checks that there
1414
is a value present, and that it is an integer (otherwise, jsdoc allows any
1515
value).
16+
6. `@kind` - Insists that it be one of the allowed values: 'class',
17+
'constant', 'event', 'external', 'file', 'function', 'member', 'mixin',
18+
'module', 'namespace', 'typedef',
1619

1720
#### Options
1821

@@ -47,7 +50,7 @@ Whether to enable validation that `@variation` must be a number. Defaults to
4750
|||
4851
|---|---|
4952
|Context|everywhere|
50-
|Tags|`@version`, `@since`, `@license`, `@author`, `@variation`|
53+
|Tags|`@version`, `@since`, `@kind`, `@license`, `@author`, `@variation`|
5154
|Recommended|true|
5255
|Options|`allowedAuthors`, `allowedLicenses`, `licensePattern`|
5356
|Settings|`tagNamePreference`|

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5818,6 +5818,9 @@ This rule checks the values for a handful of tags:
58185818
5. `@variation` - If `numericOnlyVariation` is set, will checks that there
58195819
is a value present, and that it is an integer (otherwise, jsdoc allows any
58205820
value).
5821+
6. `@kind` - Insists that it be one of the allowed values: 'class',
5822+
'constant', 'event', 'external', 'file', 'function', 'member', 'mixin',
5823+
'module', 'namespace', 'typedef',
58215824

58225825
<a name="eslint-plugin-jsdoc-rules-check-values-options-8"></a>
58235826
#### Options
@@ -5857,7 +5860,7 @@ Whether to enable validation that `@variation` must be a number. Defaults to
58575860
|||
58585861
|---|---|
58595862
|Context|everywhere|
5860-
|Tags|`@version`, `@since`, `@license`, `@author`, `@variation`|
5863+
|Tags|`@version`, `@since`, `@kind`, `@license`, `@author`, `@variation`|
58615864
|Recommended|true|
58625865
|Options|`allowedAuthors`, `allowedLicenses`, `licensePattern`|
58635866
|Settings|`tagNamePreference`|
@@ -5881,6 +5884,22 @@ function quux (foo) {
58815884
}
58825885
// Message: Invalid JSDoc @version: "3.1".
58835886

5887+
/**
5888+
* @kind
5889+
*/
5890+
function quux (foo) {
5891+
5892+
}
5893+
// Message: Missing JSDoc @kind value.
5894+
5895+
/**
5896+
* @kind -3
5897+
*/
5898+
function quux (foo) {
5899+
5900+
}
5901+
// Message: Invalid JSDoc @kind: "-3"; must be one of: class, constant, event, external, file, function, member, mixin, module, namespace, typedef.
5902+
58845903
/**
58855904
* @variation -3
58865905
*/
@@ -6108,6 +6127,13 @@ function quux (foo) {
61086127
* @license MIT
61096128
*/
61106129
'use strict';
6130+
6131+
/**
6132+
* @kind function
6133+
*/
6134+
function quux (foo) {
6135+
6136+
}
61116137
````
61126138
61136139

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"url": "http://gajus.com"
66
},
77
"dependencies": {
8-
"@es-joy/jsdoccomment": "~0.18.0",
8+
"@es-joy/jsdoccomment": "~0.19.0",
99
"comment-parser": "1.3.0",
1010
"debug": "^4.3.3",
1111
"escape-string-regexp": "^4.0.0",
@@ -17,15 +17,15 @@
1717
"description": "JSDoc linting rules for ESLint.",
1818
"devDependencies": {
1919
"@babel/cli": "^7.17.0",
20-
"@babel/core": "^7.17.0",
20+
"@babel/core": "^7.17.2",
2121
"@babel/eslint-parser": "^7.17.0",
2222
"@babel/node": "^7.16.8",
2323
"@babel/plugin-syntax-class-properties": "^7.12.13",
2424
"@babel/plugin-transform-flow-strip-types": "^7.16.7",
2525
"@babel/preset-env": "^7.16.11",
2626
"@babel/register": "^7.17.0",
2727
"@hkdobrev/run-if-changed": "^0.3.1",
28-
"@typescript-eslint/parser": "^5.10.2",
28+
"@typescript-eslint/parser": "^5.11.0",
2929
"babel-plugin-add-module-exports": "^1.0.4",
3030
"babel-plugin-istanbul": "^6.1.1",
3131
"camelcase": "^6.3.0",

src/rules/checkValues.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ import semver from 'semver';
22
import spdxExpressionParse from 'spdx-expression-parse';
33
import iterateJsdoc from '../iterateJsdoc';
44

5+
const allowedKinds = new Set([
6+
'class',
7+
'constant',
8+
'event',
9+
'external',
10+
'file',
11+
'function',
12+
'member',
13+
'mixin',
14+
'module',
15+
'namespace',
16+
'typedef',
17+
]);
18+
519
export default iterateJsdoc(({
620
utils,
721
report,
@@ -31,6 +45,27 @@ export default iterateJsdoc(({
3145
);
3246
}
3347
});
48+
49+
utils.forEachPreferredTag('kind', (jsdocParameter, targetTagName) => {
50+
const kind = utils.getTagDescription(jsdocParameter).trim();
51+
if (!kind) {
52+
report(
53+
`Missing JSDoc @${targetTagName} value.`,
54+
null,
55+
jsdocParameter,
56+
);
57+
} else if (!allowedKinds.has(kind)) {
58+
report(
59+
`Invalid JSDoc @${targetTagName}: "${utils.getTagDescription(jsdocParameter)}"; ` +
60+
`must be one of: ${[
61+
...allowedKinds,
62+
].join(', ')}.`,
63+
null,
64+
jsdocParameter,
65+
);
66+
}
67+
});
68+
3469
if (numericOnlyVariation) {
3570
utils.forEachPreferredTag('variation', (jsdocParameter, targetTagName) => {
3671
const variation = utils.getTagDescription(jsdocParameter).trim();

test/rules/assertions/checkValues.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,40 @@ export default {
3232
},
3333
],
3434
},
35+
{
36+
code: `
37+
/**
38+
* @kind
39+
*/
40+
function quux (foo) {
41+
42+
}
43+
`,
44+
errors: [
45+
{
46+
line: 3,
47+
message: 'Missing JSDoc @kind value.',
48+
},
49+
],
50+
},
51+
{
52+
code: `
53+
/**
54+
* @kind -3
55+
*/
56+
function quux (foo) {
57+
58+
}
59+
`,
60+
errors: [
61+
{
62+
line: 3,
63+
message: 'Invalid JSDoc @kind: "-3"; must be one of: class, ' +
64+
'constant, event, external, file, function, member, mixin, ' +
65+
'module, namespace, typedef.',
66+
},
67+
],
68+
},
3569
{
3670
code: `
3771
/**
@@ -458,5 +492,15 @@ export default {
458492
'use strict';
459493
`,
460494
},
495+
{
496+
code: `
497+
/**
498+
* @kind function
499+
*/
500+
function quux (foo) {
501+
502+
}
503+
`,
504+
},
461505
],
462506
};

0 commit comments

Comments
 (0)