Skip to content

Commit

Permalink
fix(require-description-complete-sentence): report bare punctuation;
Browse files Browse the repository at this point in the history
…fixes gajus#573

This reverts commit 06ecb29 to prompt release.
  • Loading branch information
brettz9 committed Jan 29, 2023
1 parent 06ecb29 commit fba9bd7
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -11355,7 +11363,7 @@ function quux () {
}

/**
* Foo. {@see Math.sin}.
* Foo {@see Math.sin}.
*/
function quux () {

Expand Down Expand Up @@ -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 () {

}
````


Expand Down
16 changes: 12 additions & 4 deletions src/rules/requireDescriptionCompleteSentence.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const extractParagraphs = (text) => {

const extractSentences = (text, abbreviationsRegex) => {
const txt = text

// Remove all {} tags.
.replace(/\{[\s\S]*?\}\s*/gu, '')

Expand All @@ -24,15 +23,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] || ''}`;
});
};

Expand Down Expand Up @@ -118,6 +120,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);
})) {
Expand Down
28 changes: 27 additions & 1 deletion test/rules/assertions/requireDescriptionCompleteSentence.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down Expand Up @@ -1031,7 +1047,7 @@ export default {
{
code: `
/**
* Foo. {@see Math.sin}.
* Foo {@see Math.sin}.
*/
function quux () {
Expand Down Expand Up @@ -1488,5 +1504,15 @@ export default {
`,
ignoreReadme: true,
},
{
code: `
/**
* This is a complete sentence...
*/
function quux () {
}
`,
},
],
};

0 comments on commit fba9bd7

Please sign in to comment.