From 7988ed60d158520f75954625d150e551d3883de5 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sat, 28 Jan 2023 21:46:51 -0700 Subject: [PATCH] fix(`require-description-complete-sentence`): report bare punctuation; fixes #573 --- README.md | 17 ++++++++++- .../requireDescriptionCompleteSentence.js | 14 ++++++++-- .../requireDescriptionCompleteSentence.js | 28 ++++++++++++++++++- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0f8c271b3..bf4c3d9f9 100644 --- a/README.md +++ b/README.md @@ -11296,6 +11296,14 @@ function quux (foo) { } // "jsdoc/require-description-complete-sentence": ["error"|"warn", {"tags":["template"]}] // Message: Sentence should start with an uppercase character. + +/** + * Just a component. + * @param {Object} props Свойства. + * @return {ReactElement}. + */ +function quux () {} +// Message: Sentence must be more than punctuation. ```` The following patterns are not considered problems: @@ -11355,7 +11363,7 @@ function quux () { } /** - * Foo. {@see Math.sin}. + * Foo {@see Math.sin}. */ function quux () { @@ -11627,6 +11635,13 @@ export default (foo) => { /** @file To learn more, * see: https://github.com/d3/d3-ease. */ + +/** + * This is a complete sentence... + */ +function quux () { + +} ```` diff --git a/src/rules/requireDescriptionCompleteSentence.js b/src/rules/requireDescriptionCompleteSentence.js index 1888d4e1b..8b000e2bb 100644 --- a/src/rules/requireDescriptionCompleteSentence.js +++ b/src/rules/requireDescriptionCompleteSentence.js @@ -24,7 +24,11 @@ const extractSentences = (text, abbreviationsRegex) => { const sentenceEndGrouping = /([.?!])(?:\s+|$)/ug; - const puncts = txt.matchAll(sentenceEndGrouping); + const puncts = [ + ...txt.matchAll(sentenceEndGrouping), + ].map((sentEnd) => { + return sentEnd[0]; + }); return txt @@ -32,7 +36,7 @@ const extractSentences = (text, abbreviationsRegex) => { // Re-add the dot. .map((sentence, idx) => { - return /^\s*$/u.test(sentence) ? sentence : `${sentence}${puncts[idx] || ''}`; + return !puncts[idx] && /^\s*$/u.test(sentence) ? sentence : `${sentence}${puncts[idx] || ''}`; }); }; @@ -118,6 +122,12 @@ const validateDescription = ( reportOrig(msg, fixer, tagObj); }; + if (sentences.some((sentence) => { + return (/^[.?!]$/u).test(sentence); + })) { + report('Sentence must be more than punctuation.', null, tag); + } + if (sentences.some((sentence) => { return !(/^\s*$/u).test(sentence) && !isCapitalized(sentence) && !isTable(sentence); })) { diff --git a/test/rules/assertions/requireDescriptionCompleteSentence.js b/test/rules/assertions/requireDescriptionCompleteSentence.js index dce073c5f..ad5c29596 100644 --- a/test/rules/assertions/requireDescriptionCompleteSentence.js +++ b/test/rules/assertions/requireDescriptionCompleteSentence.js @@ -951,6 +951,22 @@ export default { } `, }, + { + code: ` + /** + * Just a component. + * @param {Object} props Свойства. + * @return {ReactElement}. + */ + function quux () {} + `, + errors: [ + { + line: 5, + message: 'Sentence must be more than punctuation.', + }, + ], + }, ], valid: [ { @@ -1031,7 +1047,7 @@ export default { { code: ` /** - * Foo. {@see Math.sin}. + * Foo {@see Math.sin}. */ function quux () { @@ -1488,5 +1504,15 @@ export default { `, ignoreReadme: true, }, + { + code: ` + /** + * This is a complete sentence... + */ + function quux () { + + } + `, + }, ], };