From b418dbd51f11980effe666bbdcbc97bac0da0544 Mon Sep 17 00:00:00 2001 From: Brett Zamir Date: Sat, 28 Jan 2023 21:57:46 -0700 Subject: [PATCH] fix(`require-description-complete-sentence`): report bare punctuation; fixes #573 This reverts commit d77bd1cf74cb35ee06c5950bb3cacf17fdc35b79 with the intent to re-release. --- README.md | 17 ++++++++++- .../requireDescriptionCompleteSentence.js | 15 ++++++++-- .../requireDescriptionCompleteSentence.js | 28 ++++++++++++++++++- 3 files changed, 55 insertions(+), 5 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..b73a5aab3 100644 --- a/src/rules/requireDescriptionCompleteSentence.js +++ b/src/rules/requireDescriptionCompleteSentence.js @@ -24,15 +24,18 @@ 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 - .split(/[.?!](?:\s+|$)/u) // 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 +121,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 () { + + } + `, + }, ], };