Skip to content

Commit 3b5e301

Browse files
James Whitneybrettz9
authored andcommitted
feat(validateDescription): tighten constraint
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.
1 parent b36053e commit 3b5e301

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5561,6 +5561,22 @@ function quux (foo) {
55615561
* | 1 | do it |
55625562
* | 2 | do it again |
55635563
*/
5564+
5565+
/**
5566+
* This is something that
5567+
* I want to test.
5568+
*/
5569+
function quux () {
5570+
5571+
}
5572+
5573+
/**
5574+
* When making HTTP requests, the
5575+
* URL is super important.
5576+
*/
5577+
function quux () {
5578+
5579+
}
55645580
````
55655581
55665582

src/rules/requireDescriptionCompleteSentence.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const isNewLinePrecededByAPeriod = (text) => {
4545
const lines = text.split('\n');
4646

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

test/rules/assertions/requireDescriptionCompleteSentence.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,5 +909,27 @@ export default {
909909
*/
910910
`,
911911
},
912+
{
913+
code: `
914+
/**
915+
* This is something that
916+
* I want to test.
917+
*/
918+
function quux () {
919+
920+
}
921+
`,
922+
},
923+
{
924+
code: `
925+
/**
926+
* When making HTTP requests, the
927+
* URL is super important.
928+
*/
929+
function quux () {
930+
931+
}
932+
`,
933+
},
912934
],
913935
};

0 commit comments

Comments
 (0)