Skip to content

Commit 063ffdc

Browse files
committed
feat(indent): Take care of indentation
close #1
1 parent 063135a commit 063ffdc

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

ARCHITECTURE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ architecture notes. It should be structured like that:
3434
{body}
3535
```
3636
37-
[See in context](./src/jsarch.js#L150-L160)
37+
[See in context](./src/jsarch.js#L153-L163)
3838
3939
4040
@@ -51,7 +51,7 @@ A sample tree structure could be:
5151
- 2
5252
- 3
5353
54-
[See in context](./src/jsarch.js#L228-L241)
54+
[See in context](./src/jsarch.js#L231-L244)
5555
5656
5757

src/jsarch.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ function jsArch({
107107
content + eol + eol +
108108
titleLevel + architectureNote.num.split('.').map(() => '#').join('') +
109109
' ' + architectureNote.title + eol + eol +
110-
architectureNote.content + eol + eol +
110+
architectureNote.content.replace(
111+
new RegExp('([\r\n]+)[ \t]{' + architectureNote.loc.indent + '}', 'g'),
112+
'$1'
113+
) + eol + eol +
111114
'[See in context](' +
112115
base + '/' + path.relative(cwd, architectureNote.filePath) +
113116
'#L' + architectureNote.loc.start.line + '-L' + architectureNote.loc.end.line +

src/jsarch.mocha.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,54 @@ Some content !
104104
105105
[See in context](./blob/master/kikoo.js#L3-L6)
106106
107+
`
108+
);
109+
})
110+
);
111+
});
112+
113+
it.only('with some indented architecture notes in a file', () => {
114+
initJSArch($);
115+
116+
globStub.returns(Promise.resolve([
117+
'/home/me/project/kikoo.js',
118+
]));
119+
120+
readFileAsyncStub.returns(Promise.resolve(`
121+
122+
/* Architecture Note #1: Title
123+
124+
Some content !
125+
Nice!
126+
*/
127+
128+
console.log('test');
129+
130+
`));
131+
132+
return $.run(['jsArch']).then(({ jsArch }) =>
133+
jsArch({
134+
patterns: ['**/*.js'],
135+
base: './blob/master',
136+
cwd: '/home/me/project',
137+
})
138+
.then((content) => {
139+
assert.deepEqual(readFileAsyncStub.args, [[
140+
'/home/me/project/kikoo.js',
141+
'utf-8',
142+
]]);
143+
assert.equal(content,
144+
`${JSARCH_PREFIX}# Architecture Notes
145+
146+
147+
148+
## Title
149+
150+
Some content !
151+
Nice!
152+
153+
[See in context](./blob/master/kikoo.js#L3-L7)
154+
107155
`
108156
);
109157
})

0 commit comments

Comments
 (0)