diff --git a/README.md b/README.md index fd024ff4b..eb712a0ca 100644 --- a/README.md +++ b/README.md @@ -388,7 +388,7 @@ function quux (foo) { } // Message: Expected JSDoc block to be aligned. -/** + /** * @param {Number} foo */ function quux (foo) { @@ -396,7 +396,7 @@ function quux (foo) { } // Message: Expected JSDoc block to be aligned. -/** + /** * @param {Number} foo */ function quux (foo) { @@ -3410,7 +3410,7 @@ An option object may have the following key: The following patterns are considered problems: ````js -/** + /** * @param {HerType} baz - Foo. */ function quux(foo, bar, baz) { @@ -3419,7 +3419,7 @@ function quux(foo, bar, baz) { // Settings: {"jsdoc":{"preferredTypes":{"HerType":1000}}} // Message: Invalid `settings.jsdoc.preferredTypes`. Values must be falsy, a string, or an object. -/** + /** * @param {HerType} baz - Foo. */ function quux(foo, bar, baz) { @@ -3446,7 +3446,7 @@ function quux(foo, bar) { // Options: [{"definedTypes":["MyType"]}] // Message: The type 'HisType' is undefined. -/** + /** * @param {MyType} foo - Bar. * @param {HisType} bar - Foo. * @param {HerType} baz - Foo. @@ -3458,7 +3458,7 @@ function quux(foo, bar, baz) { // Options: [{"definedTypes":["MyType"]}] // Message: The type 'HisType' is undefined. -/** + /** * @param {MyType} foo - Bar. * @param {HisType} bar - Foo. * @param {HerType} baz - Foo. @@ -3642,7 +3642,7 @@ function quux(foo, bar) { } // Options: [{"definedTypes":["MyType","HisType"]}] -/** + /** * @param {MyType} foo - Bar. * @param {HisType} bar - Foo. * @param {HerType} baz - Foo. @@ -3653,7 +3653,7 @@ function quux(foo, bar, baz) { // Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":"HerType"},"histype":"HisType"}}} // Options: [{"definedTypes":["MyType"]}] -/** + /** * @param {MyType} foo - Bar. * @param {HisType} bar - Foo. * @param {HerType} baz - Foo. diff --git a/src/bin/readme-assertions.js b/src/bin/readme-assertions.js index 20df69bb9..0fc7450ed 100644 --- a/src/bin/readme-assertions.js +++ b/src/bin/readme-assertions.js @@ -7,18 +7,20 @@ import _ from 'lodash'; import glob from 'glob'; const trimCode = (code) => { - let lines = code.trim().split('\n'); + let lines = code.replace(/^\n/, '').trimEnd().split('\n'); - const indendation = lines[lines.length - 1].match(/^\s+/); + const firsLineIndentation = lines[0].match(/^\s+/); + const lastLineIndentation = lines[lines.length - 1].match(/^\s+/); - const indentSize = indendation ? indendation[0].length : 0; + const firstIndentSize = firsLineIndentation ? firsLineIndentation[0].length : 0; + const lastIndentSize = lastLineIndentation ? lastLineIndentation[0].length : 0; lines = lines.map((line, index) => { if (index === 0) { - return line; + return line.slice(Math.min(firstIndentSize, lastIndentSize)); } - return line.slice(indentSize); + return line.slice(lastIndentSize); }); return lines.join('\n'); diff --git a/test/rules/assertions/checkExamples.js b/test/rules/assertions/checkExamples.js index 2cc6fc69a..b6bef81a0 100644 --- a/test/rules/assertions/checkExamples.js +++ b/test/rules/assertions/checkExamples.js @@ -637,7 +637,7 @@ export default { }, { code: ` - /** + /** * @example * foo(function (err) { * throw err;