Skip to content

Commit

Permalink
Fix: dot in abbreviation is treated like an end
Browse files Browse the repository at this point in the history
Fixes #145
  • Loading branch information
qfox committed Dec 7, 2015
1 parent 21f5eda commit 9805a4e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
26 changes: 22 additions & 4 deletions lib/rules/validate-jsdoc/require-description-complete-sentence.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports.options = {
* does not start with an upper case letter.
* It also matches a period not fllowed by an upper case letter.
*/
var RE_NEW_LINE_START_WITH_UPPER_CASE = /((\n\s*\n)|\.)\s*[a-z]/g;
var RE_NEW_LINE_START_WITH_UPPER_CASE = /((\n\s*\n)|(?:\w{2,})\.)\s*[a-z]/g;

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

Expand Down Expand Up @@ -52,9 +52,13 @@ function requireDescriptionCompleteSentence(node, err) {
}

var loc = doc.loc.start;
var sanitized = doc.description.replace(/\{([^}]+)\}/, function(_, m) {
return '{' + (new Array(m.length + 1)).join('*') + '}';
});
var sanitized = doc.description
.replace(/(`)([^`]+)\1/, quotedSanitizer)
.replace(/(')([^']+)\1/, quotedSanitizer)
.replace(/(")([^"]+)\1/, quotedSanitizer)
.replace(/\{([^}]+)\}/, function(_, m) {
return '{' + (new Array(m.length + 1)).join('*') + '}';
});
var lines = sanitized.split(RE_END_DESCRIPTION);

var errors = [];
Expand Down Expand Up @@ -157,3 +161,17 @@ function returnAllMatches(input, regex) {
} while (match !== null);
return indexes;
}

/**
* Quoted part sanitizer used for replace matcher.
*
* @private
* @param {string} _ - Full matched string
* @param {string} q - Quote character
* @param {string} m - Matched string
* @returns {string} - Sanitized string
*/
function quotedSanitizer(_, q, m) {
var endsWithDot = /\.\s*$/.test(m);
return q + (new Array(m.length + (endsWithDot ? 0 : 1))).join('*') + q + (endsWithDot ? '.' : '');
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,19 @@ describe('lib/rules/validate-jsdoc/require-description-complete-sentence', funct
code: function () {
/**
* Some `description`.
*
* @param {number} p description without hyphen
*/
function fun(p) {}
},
errors: 0
}, {
it: 'should report final non-word characters without dot',
code: function () {
/**
* Some `description`
*/
function fun(p) {}
},
errors: 1
}, {
it: 'should report missing period at end of first line',
code: function () {
Expand Down Expand Up @@ -177,6 +184,38 @@ describe('lib/rules/validate-jsdoc/require-description-complete-sentence', funct
*/
function fun(p) {}
}
}, {
it: 'should not report strings like "e.g." #145',
code: function () {
/**
* Checks if token is part of an @-word (e.g. `@import`, `@include`).
*/
function fun(p) {}
}
}, {
it: 'should not report sentences ending with dots inside quotes',
code: function () {
/**
* He said: "mickey."
*/
function fun(p) {}
}
}, {
it: 'should not report sentences ending with dots inside quotes',
code: function () {
/**
* She said "Mickey." but he asked her to shut up.
*/
function fun(p) {}
}
}, {
it: 'should not report sentences with periods inside quotes',
code: function () {
/**
* "r2. d2".
*/
function fun(p) {}
}
}
/* jshint ignore:end */
]);
Expand Down

0 comments on commit 9805a4e

Please sign in to comment.