Skip to content

Commit

Permalink
Merge pull request #342 from yeonjuan/master
Browse files Browse the repository at this point in the history
docs: trim bug in generating doc examples
  • Loading branch information
brettz9 committed Jul 15, 2019
2 parents 190e8f7 + ddbc47a commit 62cdc02
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
16 changes: 8 additions & 8 deletions README.md
Expand Up @@ -388,15 +388,15 @@ function quux (foo) {
}
// Message: Expected JSDoc block to be aligned.

/**
/**
* @param {Number} foo
*/
function quux (foo) {

}
// Message: Expected JSDoc block to be aligned.

/**
/**
* @param {Number} foo
*/
function quux (foo) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -3642,7 +3642,7 @@ function quux(foo, bar) {
}
// Options: [{"definedTypes":["MyType","HisType"]}]

/**
/**
* @param {MyType} foo - Bar.
* @param {HisType} bar - Foo.
* @param {HerType} baz - Foo.
Expand All @@ -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.
Expand Down
12 changes: 7 additions & 5 deletions src/bin/readme-assertions.js
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion test/rules/assertions/checkExamples.js
Expand Up @@ -637,7 +637,7 @@ export default {
},
{
code: `
/**
/**
* @example
* foo(function (err) {
* throw err;
Expand Down

0 comments on commit 62cdc02

Please sign in to comment.