Skip to content

Commit

Permalink
feat(validateDescription): tighten constraint
Browse files Browse the repository at this point in the history
Currently it is possible to experience a false positive with the
`jsdoc/require-description-complete-sentence` rule.

The false positive is caused by starting a new line with a capital
letter when the previous line does not end with a period. Normally, this
is the correct behaviour, however, English sentences are more nuanced
than that.

The problem arises when using a word that starts with a capital letter
that just so happens to be at the start of a line. For instance, `I`, or
a programmatic word like `XMLHttpRequest`.

This PR tightens the constraint of the `isNewLinePrecededByAPeriod`
Function by checking for a lowercase letter immediately after an
uppercase letter.

This will still produce false positives if the new line starts with
`UserInterface` for example.
  • Loading branch information
James Whitney authored and brettz9 committed Dec 1, 2019
1 parent b36053e commit 3b5e301
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Expand Up @@ -5561,6 +5561,22 @@ function quux (foo) {
* | 1 | do it |
* | 2 | do it again |
*/
/**
* This is something that
* I want to test.
*/
function quux () {
}
/**
* When making HTTP requests, the
* URL is super important.
*/
function quux () {
}
````
Expand Down
2 changes: 1 addition & 1 deletion src/rules/requireDescriptionCompleteSentence.js
Expand Up @@ -45,7 +45,7 @@ const isNewLinePrecededByAPeriod = (text) => {
const lines = text.split('\n');

return !lines.some((line) => {
if (typeof lastLineEndsSentence === 'boolean' && !lastLineEndsSentence && /^[A-Z]/u.test(line)) {
if (typeof lastLineEndsSentence === 'boolean' && !lastLineEndsSentence && /^[A-Z][a-z]/u.test(line)) {
return true;
}

Expand Down
22 changes: 22 additions & 0 deletions test/rules/assertions/requireDescriptionCompleteSentence.js
Expand Up @@ -909,5 +909,27 @@ export default {
*/
`,
},
{
code: `
/**
* This is something that
* I want to test.
*/
function quux () {
}
`,
},
{
code: `
/**
* When making HTTP requests, the
* URL is super important.
*/
function quux () {
}
`,
},
],
};

0 comments on commit 3b5e301

Please sign in to comment.