From b1a3acdccb9db132cc62d964a146f875c1857dd4 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Mon, 26 Sep 2016 12:45:35 +0200 Subject: [PATCH] Fix more complex requireDescriptionCompleteSentence cases --- .../require-description-complete-sentence.js | 6 +-- .../require-description-complete-sentence.js | 41 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/lib/rules/validate-jsdoc/require-description-complete-sentence.js b/lib/rules/validate-jsdoc/require-description-complete-sentence.js index d48d670..ccffc2c 100644 --- a/lib/rules/validate-jsdoc/require-description-complete-sentence.js +++ b/lib/rules/validate-jsdoc/require-description-complete-sentence.js @@ -52,9 +52,9 @@ function requireDescriptionCompleteSentence(node, err) { } var sanitized = doc.description - .replace(/(`)([^`]+)\1/, quotedSanitizer) - .replace(/(')([^']+)\1/, quotedSanitizer) - .replace(/(")([^"]+)\1/, quotedSanitizer) + .replace(/(`)([^`]+)\1/g, quotedSanitizer) + .replace(/(')([^']+)\1/g, quotedSanitizer) + .replace(/(")([^"]+)\1/g, quotedSanitizer) // sanitize HTML tags which close .replace(/<([^ >]+)[^>]*>[\s\S]*?.*?<\/\1>|<[^\/]+\/>/g, htmlSanitizer) // sanitize self-closing HTML tags eg
diff --git a/test/lib/rules/validate-jsdoc/require-description-complete-sentence.js b/test/lib/rules/validate-jsdoc/require-description-complete-sentence.js index 9e6cbc2..c514d2d 100644 --- a/test/lib/rules/validate-jsdoc/require-description-complete-sentence.js +++ b/test/lib/rules/validate-jsdoc/require-description-complete-sentence.js @@ -147,6 +147,33 @@ describe('lib/rules/validate-jsdoc/require-description-complete-sentence', funct function fun(p) {} }, errors: 1 + }, { + it: 'should not report because of strings between backtick', + code: function () { + /** + * Some `fo.o` and some `b.ar`. Also some `ba.r` and some `.foo`. + */ + function fun(p) {} + }, + errors: 0 + }, { + it: 'should not report because of strings between single quotes', + code: function () { + /** + * Some 'fo.o' and some 'b.ar'. Also some 'ba.r' and some '.foo'. + */ + function fun(p) {} + }, + errors: 0 + }, { + it: 'should not report because of strings between double quotes', + code: function () { + /** + * Some "fo.o" and some "b.ar". Also some "ba.r" and some ".foo". + */ + function fun(p) {} + }, + errors: 0 }, { it: 'should report missing period at end of first line', code: function () { @@ -232,6 +259,20 @@ describe('lib/rules/validate-jsdoc/require-description-complete-sentence', funct */ function quux() {} } + }, { + it: 'should not report correct sentences formatted as (complex) lists', + code: function () { + /** + * To become a `Foo.Bar`, `element` has to: + * + * - be an `HTMLElement` + * - have an `options` property + * - have `foo` and `bar` properties in its `options` object + * - not have a foo (`.bar`) as source, or if it does: + * - have `options.foo` set to `true` + */ + function quux() {} + } }, { it: 'should not report sentences with html tags inside', code: function () {