Skip to content

Commit b9ffead

Browse files
committed
Update Rule: inlined tags in requireDescriptionCompleteSentence
Fixes #180 Closes gh-181
1 parent c771b25 commit b9ffead

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ 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)|\.)\s*[a-z]/g;
1515

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

1818
var RE_END_DESCRIPTION = /\n/g;
1919

@@ -24,7 +24,7 @@ var RE_END_DESCRIPTION = /\n/g;
2424
* upper case letter where the previous line does not have a period
2525
* Note that numbers count as word characters.
2626
*/
27-
var RE_NEW_LINE_UPPERCASE = /\w(?![.])(\W)*\n\W*[A-Z]/g;
27+
var RE_NEW_LINE_UPPERCASE = /\w(?!\.)(\W)*\n\W*[A-Z]/g;
2828

2929
/**
3030
* Checks that a sentence followed by a blank line has a period
@@ -34,7 +34,7 @@ var RE_NEW_LINE_UPPERCASE = /\w(?![.])(\W)*\n\W*[A-Z]/g;
3434
*
3535
* This also matches white-space followed by a period.
3636
*/
37-
var RE_END_WITH_PERIOD = /(\s\.|[^\s\.])(?!\.)(\n|$)[*\s]*(\n|$)/g;
37+
var RE_END_WITH_PERIOD = /(\s\.|[^\s\.])(?!\.)(\n|$)\s*(\n|$)/g;
3838

3939
/**
4040
* Requires description to be a complete sentence in a jsdoc comment.
@@ -47,44 +47,47 @@ var RE_END_WITH_PERIOD = /(\s\.|[^\s\.])(?!\.)(\n|$)[*\s]*(\n|$)/g;
4747
*/
4848
function requireDescriptionCompleteSentence(node, err) {
4949
var doc = node.jsdoc;
50-
if (!doc || !doc.tags.length || !doc.description || !doc.description.length) {
50+
if (!doc || !doc.description || !doc.description.length) {
5151
return;
5252
}
5353

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

5760
var errors = [];
5861

59-
if (START_DESCRIPTION.test(doc.description)) {
60-
var matches = returnAllMatches(doc.description, START_DESCRIPTION);
62+
if (START_DESCRIPTION.test(sanitized)) {
63+
var matches = returnAllMatches(sanitized, START_DESCRIPTION);
6164
matches.map(function(match) {
6265
match.message = 'Description must start with an upper case letter';
6366
match.index = match.start;
6467
});
6568
errors = errors.concat(matches);
6669
}
6770

68-
if (RE_NEW_LINE_START_WITH_UPPER_CASE.test(doc.description)) {
69-
var matches1 = returnAllMatches(doc.description, RE_NEW_LINE_START_WITH_UPPER_CASE);
71+
if (RE_NEW_LINE_START_WITH_UPPER_CASE.test(sanitized)) {
72+
var matches1 = returnAllMatches(sanitized, RE_NEW_LINE_START_WITH_UPPER_CASE);
7073
matches1.map(function(match) {
7174
match.message = 'Sentence must start with an upper case letter';
7275
match.index = match.end - 1;
7376
});
7477
errors = errors.concat(matches1);
7578
}
7679

77-
if (RE_END_WITH_PERIOD.test(doc.description)) {
78-
var matches2 = returnAllMatches(doc.description, RE_END_WITH_PERIOD);
80+
if (RE_END_WITH_PERIOD.test(sanitized)) {
81+
var matches2 = returnAllMatches(sanitized, RE_END_WITH_PERIOD);
7982
matches2.map(function(match) {
8083
match.message = 'Sentence must end with a period';
8184
match.index = match.start;
8285
});
8386
errors = errors.concat(matches2);
8487
}
8588

86-
if (RE_NEW_LINE_UPPERCASE.test(doc.description)) {
87-
var matches3 = returnAllMatches(doc.description, RE_NEW_LINE_UPPERCASE);
89+
if (RE_NEW_LINE_UPPERCASE.test(sanitized)) {
90+
var matches3 = returnAllMatches(sanitized, RE_NEW_LINE_UPPERCASE);
8891
matches3.map(function(match) {
8992
match.message = 'You started a new line with an upper case letter but ' +
9093
'previous line does not end with a period';

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ describe('lib/rules/validate-jsdoc/require-description-complete-sentence', funct
166166
*/
167167
function fun(p) {}
168168
}
169+
}, {
170+
it: 'should not report inlined tags #180',
171+
code: function () {
172+
/**
173+
* Heading.
174+
*
175+
* This method uses the algorithm defined here:
176+
* {@link http://stackoverflow.com/questions/1073336/circle-line-segment-collision-detection-algorithm}
177+
*/
178+
function fun(p) {}
179+
}
169180
}
170181
/* jshint ignore:end */
171182
]);

0 commit comments

Comments
 (0)