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 #573
  • Loading branch information
brettz9 committed Jan 29, 2023
1 parent 512670c commit 7988ed6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 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
14 changes: 12 additions & 2 deletions src/rules/requireDescriptionCompleteSentence.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ 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 +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);
})) {
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 7988ed6

Please sign in to comment.