Skip to content

Commit f3985b0

Browse files
wooormAlexej Yaroshevich
authored andcommitted
requireDescriptionCompleteSentence: fix trailing non-word character bug
Trailing non-word character before period: ```js /** * (Description). */ function method() {} ``` ... was previously seens as having no final perdiod. Fixes #123 Closes gh-130
1 parent c74cc59 commit f3985b0

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,11 @@ function method() {}
750750
*/
751751
function method() {}
752752

753+
/**
754+
* (Description).
755+
*/
756+
function method() {}
757+
753758
/**
754759
* Description.
755760
*

lib/rules/validate-jsdoc/require-description-complete-sentence.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ var RE_NEW_LINE_UPPERCASE = /\w(?![.])(\W)*\n\W*[A-Z]/g;
3131
*
3232
* If the above line did not have a period this would match.
3333
* this also ensures that the last sentence in the description ends with a period.
34+
*
35+
* This also matches white-space followed by a period.
3436
*/
35-
var RE_END_WITH_PERIOD = /\w(?![.])(\W)*(\n|$)[*\s]*(\n|$)/g;
37+
var RE_END_WITH_PERIOD = /(\s\.|[^\s\.])(?!\.)(\n|$)[*\s]*(\n|$)/g;
3638

3739
/**
3840
* Requires description to be a complete sentence in a jsdoc comment.

test/lib/rules/validate-jsdoc/require-description-complete-sentence.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe('lib/rules/validate-jsdoc/require-description-complete-sentence', funct
119119
function fun(p) {}
120120
}
121121
}, {
122-
it: 'should report missing period',
122+
it: 'should report trailing white-space',
123123
code: function () {
124124
/**
125125
* Some description .
@@ -129,6 +129,17 @@ describe('lib/rules/validate-jsdoc/require-description-complete-sentence', funct
129129
function fun(p) {}
130130
},
131131
errors: 1
132+
}, {
133+
it: 'should not report final non-word characters',
134+
code: function () {
135+
/**
136+
* Some `description`.
137+
*
138+
* @param {number} p description without hyphen
139+
*/
140+
function fun(p) {}
141+
},
142+
errors: 0
132143
}, {
133144
it: 'should report missing period at end of first line',
134145
code: function () {

0 commit comments

Comments
 (0)