Skip to content

Commit 62cdc02

Browse files
authored
Merge pull request #342 from yeonjuan/master
docs: trim bug in generating doc examples
2 parents 190e8f7 + ddbc47a commit 62cdc02

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,15 +388,15 @@ function quux (foo) {
388388
}
389389
// Message: Expected JSDoc block to be aligned.
390390

391-
/**
391+
/**
392392
* @param {Number} foo
393393
*/
394394
function quux (foo) {
395395

396396
}
397397
// Message: Expected JSDoc block to be aligned.
398398

399-
/**
399+
/**
400400
* @param {Number} foo
401401
*/
402402
function quux (foo) {
@@ -3410,7 +3410,7 @@ An option object may have the following key:
34103410
The following patterns are considered problems:
34113411

34123412
````js
3413-
/**
3413+
/**
34143414
* @param {HerType} baz - Foo.
34153415
*/
34163416
function quux(foo, bar, baz) {
@@ -3419,7 +3419,7 @@ function quux(foo, bar, baz) {
34193419
// Settings: {"jsdoc":{"preferredTypes":{"HerType":1000}}}
34203420
// Message: Invalid `settings.jsdoc.preferredTypes`. Values must be falsy, a string, or an object.
34213421

3422-
/**
3422+
/**
34233423
* @param {HerType} baz - Foo.
34243424
*/
34253425
function quux(foo, bar, baz) {
@@ -3446,7 +3446,7 @@ function quux(foo, bar) {
34463446
// Options: [{"definedTypes":["MyType"]}]
34473447
// Message: The type 'HisType' is undefined.
34483448

3449-
/**
3449+
/**
34503450
* @param {MyType} foo - Bar.
34513451
* @param {HisType} bar - Foo.
34523452
* @param {HerType} baz - Foo.
@@ -3458,7 +3458,7 @@ function quux(foo, bar, baz) {
34583458
// Options: [{"definedTypes":["MyType"]}]
34593459
// Message: The type 'HisType' is undefined.
34603460

3461-
/**
3461+
/**
34623462
* @param {MyType} foo - Bar.
34633463
* @param {HisType} bar - Foo.
34643464
* @param {HerType} baz - Foo.
@@ -3642,7 +3642,7 @@ function quux(foo, bar) {
36423642
}
36433643
// Options: [{"definedTypes":["MyType","HisType"]}]
36443644

3645-
/**
3645+
/**
36463646
* @param {MyType} foo - Bar.
36473647
* @param {HisType} bar - Foo.
36483648
* @param {HerType} baz - Foo.
@@ -3653,7 +3653,7 @@ function quux(foo, bar, baz) {
36533653
// Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":"HerType"},"histype":"HisType"}}}
36543654
// Options: [{"definedTypes":["MyType"]}]
36553655

3656-
/**
3656+
/**
36573657
* @param {MyType} foo - Bar.
36583658
* @param {HisType} bar - Foo.
36593659
* @param {HerType} baz - Foo.

src/bin/readme-assertions.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ import _ from 'lodash';
77
import glob from 'glob';
88

99
const trimCode = (code) => {
10-
let lines = code.trim().split('\n');
10+
let lines = code.replace(/^\n/, '').trimEnd().split('\n');
1111

12-
const indendation = lines[lines.length - 1].match(/^\s+/);
12+
const firsLineIndentation = lines[0].match(/^\s+/);
13+
const lastLineIndentation = lines[lines.length - 1].match(/^\s+/);
1314

14-
const indentSize = indendation ? indendation[0].length : 0;
15+
const firstIndentSize = firsLineIndentation ? firsLineIndentation[0].length : 0;
16+
const lastIndentSize = lastLineIndentation ? lastLineIndentation[0].length : 0;
1517

1618
lines = lines.map((line, index) => {
1719
if (index === 0) {
18-
return line;
20+
return line.slice(Math.min(firstIndentSize, lastIndentSize));
1921
}
2022

21-
return line.slice(indentSize);
23+
return line.slice(lastIndentSize);
2224
});
2325

2426
return lines.join('\n');

test/rules/assertions/checkExamples.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ export default {
637637
},
638638
{
639639
code: `
640-
/**
640+
/**
641641
* @example
642642
* foo(function (err) {
643643
* throw err;

0 commit comments

Comments
 (0)