Skip to content

Commit 9805a4e

Browse files
committed
Fix: dot in abbreviation is treated like an end
Fixes #145
1 parent 21f5eda commit 9805a4e

File tree

2 files changed

+63
-6
lines changed

2 files changed

+63
-6
lines changed

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports.options = {
1111
* does not start with an upper case letter.
1212
* It also matches a period not fllowed by an upper case letter.
1313
*/
14-
var RE_NEW_LINE_START_WITH_UPPER_CASE = /((\n\s*\n)|\.)\s*[a-z]/g;
14+
var RE_NEW_LINE_START_WITH_UPPER_CASE = /((\n\s*\n)|(?:\w{2,})\.)\s*[a-z]/g;
1515

1616
var START_DESCRIPTION = /^\s*[a-z]/g;
1717

@@ -52,9 +52,13 @@ function requireDescriptionCompleteSentence(node, err) {
5252
}
5353

5454
var loc = doc.loc.start;
55-
var sanitized = doc.description.replace(/\{([^}]+)\}/, function(_, m) {
56-
return '{' + (new Array(m.length + 1)).join('*') + '}';
57-
});
55+
var sanitized = doc.description
56+
.replace(/(`)([^`]+)\1/, quotedSanitizer)
57+
.replace(/(')([^']+)\1/, quotedSanitizer)
58+
.replace(/(")([^"]+)\1/, quotedSanitizer)
59+
.replace(/\{([^}]+)\}/, function(_, m) {
60+
return '{' + (new Array(m.length + 1)).join('*') + '}';
61+
});
5862
var lines = sanitized.split(RE_END_DESCRIPTION);
5963

6064
var errors = [];
@@ -157,3 +161,17 @@ function returnAllMatches(input, regex) {
157161
} while (match !== null);
158162
return indexes;
159163
}
164+
165+
/**
166+
* Quoted part sanitizer used for replace matcher.
167+
*
168+
* @private
169+
* @param {string} _ - Full matched string
170+
* @param {string} q - Quote character
171+
* @param {string} m - Matched string
172+
* @returns {string} - Sanitized string
173+
*/
174+
function quotedSanitizer(_, q, m) {
175+
var endsWithDot = /\.\s*$/.test(m);
176+
return q + (new Array(m.length + (endsWithDot ? 0 : 1))).join('*') + q + (endsWithDot ? '.' : '');
177+
}

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

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,19 @@ describe('lib/rules/validate-jsdoc/require-description-complete-sentence', funct
134134
code: function () {
135135
/**
136136
* Some `description`.
137-
*
138-
* @param {number} p description without hyphen
139137
*/
140138
function fun(p) {}
141139
},
142140
errors: 0
141+
}, {
142+
it: 'should report final non-word characters without dot',
143+
code: function () {
144+
/**
145+
* Some `description`
146+
*/
147+
function fun(p) {}
148+
},
149+
errors: 1
143150
}, {
144151
it: 'should report missing period at end of first line',
145152
code: function () {
@@ -177,6 +184,38 @@ describe('lib/rules/validate-jsdoc/require-description-complete-sentence', funct
177184
*/
178185
function fun(p) {}
179186
}
187+
}, {
188+
it: 'should not report strings like "e.g." #145',
189+
code: function () {
190+
/**
191+
* Checks if token is part of an @-word (e.g. `@import`, `@include`).
192+
*/
193+
function fun(p) {}
194+
}
195+
}, {
196+
it: 'should not report sentences ending with dots inside quotes',
197+
code: function () {
198+
/**
199+
* He said: "mickey."
200+
*/
201+
function fun(p) {}
202+
}
203+
}, {
204+
it: 'should not report sentences ending with dots inside quotes',
205+
code: function () {
206+
/**
207+
* She said "Mickey." but he asked her to shut up.
208+
*/
209+
function fun(p) {}
210+
}
211+
}, {
212+
it: 'should not report sentences with periods inside quotes',
213+
code: function () {
214+
/**
215+
* "r2. d2".
216+
*/
217+
function fun(p) {}
218+
}
180219
}
181220
/* jshint ignore:end */
182221
]);

0 commit comments

Comments
 (0)