Skip to content

Commit 9b63f40

Browse files
brettz9chiawendt
authored andcommitted
feat(match-description): allow description and desc tags to be matched for validation
1 parent 7953354 commit 9b63f40

File tree

4 files changed

+155
-4
lines changed

4 files changed

+155
-4
lines changed

.README/rules/match-description.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,6 @@ Overrides the default contexts (see below).
8282
|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
8383
|Tags|N/A by default but see `tags` options|
8484
|Settings||
85-
|Options|`contexts`, `tags` (allows for 'param', 'arg', 'argument', 'returns', 'return'), `mainDescription`, `matchDescription`|
85+
|Options|`contexts`, `tags` (allows for 'param', 'arg', 'argument', 'returns', 'return', 'description', 'desc'), `mainDescription`, `matchDescription`|
8686

8787
<!-- assertions matchDescription -->

README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,7 @@ Overrides the default contexts (see below).
24952495
|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
24962496
|Tags|N/A by default but see `tags` options|
24972497
|Settings||
2498-
|Options|`contexts`, `tags` (allows for 'param', 'arg', 'argument', 'returns', 'return'), `mainDescription`, `matchDescription`|
2498+
|Options|`contexts`, `tags` (allows for 'param', 'arg', 'argument', 'returns', 'return', 'description', 'desc'), `mainDescription`, `matchDescription`|
24992499

25002500
The following patterns are considered problems:
25012501

@@ -2571,6 +2571,17 @@ function quux (foo) {
25712571
// Options: [{"tags":{"param":true}}]
25722572
// Message: JSDoc description does not satisfy the regex pattern.
25732573

2574+
/**
2575+
* Foo.
2576+
*
2577+
* @description foo foo.
2578+
*/
2579+
function quux (foo) {
2580+
2581+
}
2582+
// Options: [{"tags":{"description":true}}]
2583+
// Message: JSDoc description does not satisfy the regex pattern.
2584+
25742585
/**
25752586
* Foo
25762587
*
@@ -2695,6 +2706,16 @@ function quux () {
26952706
// Options: [{"tags":{"param":"[А-Я][А-я]+\\."}}]
26962707
// Message: JSDoc description does not satisfy the regex pattern.
26972708

2709+
/**
2710+
* @description notRet
2711+
* @returns Тест.
2712+
*/
2713+
function quux () {
2714+
2715+
}
2716+
// Options: [{"tags":{"description":"[А-Я][А-я]+\\."}}]
2717+
// Message: JSDoc description does not satisfy the regex pattern.
2718+
26982719
/**
26992720
* foo.
27002721
*/
@@ -2784,6 +2805,15 @@ function quux () {
27842805
}
27852806
// Options: [{"tags":{"returns":"[А-Я][А-я]+\\."}}]
27862807

2808+
/**
2809+
* @param notRet
2810+
* @description Тест.
2811+
*/
2812+
function quux () {
2813+
2814+
}
2815+
// Options: [{"tags":{"description":"[А-Я][А-я]+\\."}}]
2816+
27872817
/**
27882818
* Foo
27892819
* bar.
@@ -2800,6 +2830,14 @@ function quux () {
28002830
}
28012831
// Options: [{"tags":{"returns":true}}]
28022832

2833+
/**
2834+
* @description Foo bar.
2835+
*/
2836+
function quux () {
2837+
2838+
}
2839+
// Options: [{"tags":{"description":true}}]
2840+
28032841
/**
28042842
* Foo. {@see Math.sin}.
28052843
*/
@@ -2921,6 +2959,14 @@ const q = {
29212959

29222960
};
29232961
// Options: [{"contexts":[]}]
2962+
2963+
/**
2964+
* @description foo.
2965+
*/
2966+
function quux () {
2967+
2968+
}
2969+
// Options: [{"tags":{"param":true}}]
29242970
````
29252971

29262972

src/rules/matchDescription.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,19 @@ export default iterateJsdoc(({
5353
return;
5454
}
5555

56+
const hasOptionTag = (tagName) => {
57+
return Boolean(options.tags[tagName]);
58+
};
59+
60+
utils.forEachPreferredTag('description', (matchingJsdocTag, targetTagName) => {
61+
const description = (matchingJsdocTag.name + ' ' + matchingJsdocTag.description).trim();
62+
if (hasOptionTag(targetTagName)) {
63+
validateDescription(description, matchingJsdocTag);
64+
}
65+
});
66+
5667
const tags = utils.filterTags(({tag}) => {
57-
return tagsWithDescriptions.includes(tag) &&
58-
{}.hasOwnProperty.call(options.tags, tag) && options.tags[tag];
68+
return tagsWithDescriptions.includes(tag) && hasOptionTag(tag);
5969
});
6070

6171
tags.some((tag) => {

test/rules/assertions/matchDescription.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,31 @@ export default {
160160
}
161161
]
162162
},
163+
{
164+
code: `
165+
/**
166+
* Foo.
167+
*
168+
* @description foo foo.
169+
*/
170+
function quux (foo) {
171+
172+
}
173+
`,
174+
errors: [
175+
{
176+
line: 5,
177+
message: 'JSDoc description does not satisfy the regex pattern.'
178+
}
179+
],
180+
options: [
181+
{
182+
tags: {
183+
description: true
184+
}
185+
}
186+
]
187+
},
163188
{
164189
code: `
165190
/**
@@ -440,6 +465,28 @@ export default {
440465
}
441466
}]
442467
},
468+
{
469+
code: `
470+
/**
471+
* @description notRet
472+
* @returns Тест.
473+
*/
474+
function quux () {
475+
476+
}
477+
`,
478+
errors: [
479+
{
480+
line: 3,
481+
message: 'JSDoc description does not satisfy the regex pattern.'
482+
}
483+
],
484+
options: [{
485+
tags: {
486+
description: '[\u0410-\u042F][\u0410-\u044F]+\\.'
487+
}
488+
}]
489+
},
443490
{
444491
code: `
445492
/**
@@ -615,6 +662,22 @@ export default {
615662
}
616663
}]
617664
},
665+
{
666+
code: `
667+
/**
668+
* @param notRet
669+
* @description Тест.
670+
*/
671+
function quux () {
672+
673+
}
674+
`,
675+
options: [{
676+
tags: {
677+
description: '[\u0410-\u042F][\u0410-\u044F]+\\.'
678+
}
679+
}]
680+
},
618681
{
619682
code: `
620683
/**
@@ -643,6 +706,23 @@ export default {
643706
}
644707
]
645708
},
709+
{
710+
code: `
711+
/**
712+
* @description Foo bar.
713+
*/
714+
function quux () {
715+
716+
}
717+
`,
718+
options: [
719+
{
720+
tags: {
721+
description: true
722+
}
723+
}
724+
]
725+
},
646726
{
647727
code: `
648728
/**
@@ -842,6 +922,21 @@ export default {
842922
]
843923
}
844924
]
925+
},
926+
{
927+
code: `
928+
/**
929+
* @description foo.
930+
*/
931+
function quux () {
932+
933+
}
934+
`,
935+
options: [
936+
{tags: {
937+
param: true
938+
}}
939+
]
845940
}
846941
]
847942
};

0 commit comments

Comments
 (0)