Skip to content

Commit 3479aaf

Browse files
authored
Merge pull request gajus#312 from brettz9/require-description-complete-sentence-tag
require-description-complete-sentence explicit `@description` tag validation
2 parents 3cff001 + 97644cd commit 3479aaf

File tree

4 files changed

+67
-9
lines changed

4 files changed

+67
-9
lines changed
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.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3404,18 +3404,20 @@ function quux () {
34043404
<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence"></a>
34053405
### <code>require-description-complete-sentence</code>
34063406

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

34093410
* Description must start with an uppercase alphabetical character.
34103411
* Paragraphs must start with an uppercase alphabetical character.
34113412
* Sentences must end with a period.
3412-
* Every line in a paragraph (except the first) which starts with an uppercase character must be preceded by a line ending with a period.
3413+
* Every line in a paragraph (except the first) which starts with an uppercase
3414+
character must be preceded by a line ending with a period.
34133415

34143416
|||
34153417
|---|---|
34163418
|Context|everywhere|
3417-
|Tags|`param`, `returns`|
3418-
|Aliases|`arg`, `argument`, `return`|
3419+
|Tags|`param`, `returns`, `description`|
3420+
|Aliases|`arg`, `argument`, `return`, `desc`|
34193421

34203422
The following patterns are considered problems:
34213423

@@ -3428,6 +3430,14 @@ function quux () {
34283430
}
34293431
// Message: Sentence should start with an uppercase character.
34303432

3433+
/**
3434+
* @description foo.
3435+
*/
3436+
function quux () {
3437+
3438+
}
3439+
// Message: Sentence should start with an uppercase character.
3440+
34313441
/**
34323442
* Foo)
34333443
*/
@@ -3670,6 +3680,13 @@ function quux () {
36703680
*/
36713681
function quux () {
36723682

3683+
}
3684+
3685+
/**
3686+
* @description Foo.
3687+
*/
3688+
function quux () {
3689+
36733690
}
36743691
````
36753692

src/rules/requireDescriptionCompleteSentence.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,20 @@ export default iterateJsdoc(({
111111
sourceCode,
112112
jsdoc,
113113
report,
114-
jsdocNode
114+
jsdocNode,
115+
utils
115116
}) => {
116117
if (!jsdoc.tags ||
117118
validateDescription(jsdoc.description, report, jsdocNode, sourceCode)
118119
) {
119120
return;
120121
}
121122

123+
utils.forEachPreferredTag('description', (matchingJsdocTag, targetTagName) => {
124+
const description = (matchingJsdocTag.name + ' ' + matchingJsdocTag.description).trim();
125+
validateDescription(description, report, jsdocNode, sourceCode, targetTagName);
126+
});
127+
122128
const tags = jsdoc.tags.filter((tag) => {
123129
return ['param', 'arg', 'argument', 'returns', 'return'].includes(tag.tag);
124130
});

test/rules/assertions/requireDescriptionCompleteSentence.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,29 @@ export default {
2323
}
2424
`
2525
},
26+
{
27+
code: `
28+
/**
29+
* @description foo.
30+
*/
31+
function quux () {
32+
33+
}
34+
`,
35+
errors: [
36+
{
37+
message: 'Sentence should start with an uppercase character.'
38+
}
39+
],
40+
output: `
41+
/**
42+
* @description Foo.
43+
*/
44+
function quux () {
45+
46+
}
47+
`
48+
},
2649
{
2750
code: `
2851
/**
@@ -551,6 +574,16 @@ export default {
551574
*/
552575
function quux () {
553576
577+
}
578+
`
579+
},
580+
{
581+
code: `
582+
/**
583+
* @description Foo.
584+
*/
585+
function quux () {
586+
554587
}
555588
`
556589
}

0 commit comments

Comments
 (0)