Skip to content

Commit 7988ed6

Browse files
committed
fix(require-description-complete-sentence): report bare punctuation; fixes #573
1 parent 512670c commit 7988ed6

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -11296,6 +11296,14 @@ function quux (foo) {
1129611296
}
1129711297
// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"tags":["template"]}]
1129811298
// Message: Sentence should start with an uppercase character.
11299+
11300+
/**
11301+
* Just a component.
11302+
* @param {Object} props Свойства.
11303+
* @return {ReactElement}.
11304+
*/
11305+
function quux () {}
11306+
// Message: Sentence must be more than punctuation.
1129911307
````
1130011308

1130111309
The following patterns are not considered problems:
@@ -11355,7 +11363,7 @@ function quux () {
1135511363
}
1135611364

1135711365
/**
11358-
* Foo. {@see Math.sin}.
11366+
* Foo {@see Math.sin}.
1135911367
*/
1136011368
function quux () {
1136111369

@@ -11627,6 +11635,13 @@ export default (foo) => {
1162711635

1162811636
/** @file To learn more,
1162911637
* see: https://github.com/d3/d3-ease. */
11638+
11639+
/**
11640+
* This is a complete sentence...
11641+
*/
11642+
function quux () {
11643+
11644+
}
1163011645
````
1163111646

1163211647

src/rules/requireDescriptionCompleteSentence.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@ const extractSentences = (text, abbreviationsRegex) => {
2424

2525
const sentenceEndGrouping = /([.?!])(?:\s+|$)/ug;
2626

27-
const puncts = txt.matchAll(sentenceEndGrouping);
27+
const puncts = [
28+
...txt.matchAll(sentenceEndGrouping),
29+
].map((sentEnd) => {
30+
return sentEnd[0];
31+
});
2832

2933
return txt
3034

3135
.split(/[.?!](?:\s+|$)/u)
3236

3337
// Re-add the dot.
3438
.map((sentence, idx) => {
35-
return /^\s*$/u.test(sentence) ? sentence : `${sentence}${puncts[idx] || ''}`;
39+
return !puncts[idx] && /^\s*$/u.test(sentence) ? sentence : `${sentence}${puncts[idx] || ''}`;
3640
});
3741
};
3842

@@ -118,6 +122,12 @@ const validateDescription = (
118122
reportOrig(msg, fixer, tagObj);
119123
};
120124

125+
if (sentences.some((sentence) => {
126+
return (/^[.?!]$/u).test(sentence);
127+
})) {
128+
report('Sentence must be more than punctuation.', null, tag);
129+
}
130+
121131
if (sentences.some((sentence) => {
122132
return !(/^\s*$/u).test(sentence) && !isCapitalized(sentence) && !isTable(sentence);
123133
})) {

test/rules/assertions/requireDescriptionCompleteSentence.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,22 @@ export default {
951951
}
952952
`,
953953
},
954+
{
955+
code: `
956+
/**
957+
* Just a component.
958+
* @param {Object} props Свойства.
959+
* @return {ReactElement}.
960+
*/
961+
function quux () {}
962+
`,
963+
errors: [
964+
{
965+
line: 5,
966+
message: 'Sentence must be more than punctuation.',
967+
},
968+
],
969+
},
954970
],
955971
valid: [
956972
{
@@ -1031,7 +1047,7 @@ export default {
10311047
{
10321048
code: `
10331049
/**
1034-
* Foo. {@see Math.sin}.
1050+
* Foo {@see Math.sin}.
10351051
*/
10361052
function quux () {
10371053
@@ -1488,5 +1504,15 @@ export default {
14881504
`,
14891505
ignoreReadme: true,
14901506
},
1507+
{
1508+
code: `
1509+
/**
1510+
* This is a complete sentence...
1511+
*/
1512+
function quux () {
1513+
1514+
}
1515+
`,
1516+
},
14911517
],
14921518
};

0 commit comments

Comments
 (0)