Skip to content

Commit a910cff

Browse files
committed
refactor: fix some code smells
1 parent 5340d78 commit a910cff

File tree

8 files changed

+46
-23
lines changed

8 files changed

+46
-23
lines changed

example/documentation/code/config.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/documentation/code/lib/jsdoc-to-markdown.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const jsdoc2md = require('jsdoc-to-markdown')
3131
**Kind**: Exported class
3232
<a name="module_jsdoc-to-markdown--JsdocToMarkdown+render"></a>
3333

34-
#### jsdoc2md.render([options]) -> <code>Promise</code>
34+
#### jsdoc2md.render([options]) <code>Promise</code>
3535
Returns markdown documentation from jsdoc-annoted source code.
3636

3737
**Kind**: instance method of [<code>JsdocToMarkdown</code>](#exp_module_jsdoc-to-markdown--JsdocToMarkdown)
@@ -64,7 +64,7 @@ Pass in filepaths (`**` glob matching supported) of javascript source files:
6464
```
6565
<a name="module_jsdoc-to-markdown--JsdocToMarkdown+getTemplateData"></a>
6666

67-
#### jsdoc2md.getTemplateData([options]) -> <code>Promise</code>
67+
#### jsdoc2md.getTemplateData([options]) <code>Promise</code>
6868
Returns the template data (jsdoc-parse output) which is fed into the output template (dmd).
6969

7070
**Kind**: instance method of [<code>JsdocToMarkdown</code>](#exp_module_jsdoc-to-markdown--JsdocToMarkdown)
@@ -77,7 +77,7 @@ Returns the template data (jsdoc-parse output) which is fed into the output temp
7777

7878
<a name="module_jsdoc-to-markdown--JsdocToMarkdown+getJsdocData"></a>
7979

80-
#### jsdoc2md.getJsdocData([options]) -> <code>Promise</code>
80+
#### jsdoc2md.getJsdocData([options]) <code>Promise</code>
8181
Returns raw data direct from the underlying [jsdoc3](https://github.com/jsdoc3/jsdoc).
8282

8383
**Kind**: instance method of [<code>JsdocToMarkdown</code>](#exp_module_jsdoc-to-markdown--JsdocToMarkdown)
@@ -94,14 +94,14 @@ Returns raw data direct from the underlying [jsdoc3](https://github.com/jsdoc3/j
9494

9595
<a name="module_jsdoc-to-markdown--JsdocToMarkdown+clear"></a>
9696

97-
#### jsdoc2md.clear() -> <code>Promise</code>
97+
#### jsdoc2md.clear() <code>Promise</code>
9898
By default, the output of each invocation of the main generation methods (`render`, `getTemplateData` etc) is stored in the cache (your system's [temporary directory](https://nodejs.org/dist/latest-v6.x/docs/api/os.html#os_os_tmpdir)). Future jsdoc2md invocations with the same input options and source code will return the output immediately from cache, making the tool much faster/cheaper. If the input options or source code changes, fresh output will be generated. This method clears the cache, which you should never need to do unless the cache is failing for some reason. On Mac OSX, the system tmpdir clears itself every few days meaning your jsdoc2md cache will also be routinely cleared.
9999

100100
**Kind**: instance method of [<code>JsdocToMarkdown</code>](#exp_module_jsdoc-to-markdown--JsdocToMarkdown)
101101
**Category**: async
102102
<a name="module_jsdoc-to-markdown--JsdocToMarkdown+getNamepaths"></a>
103103

104-
#### jsdoc2md.getNamepaths(options) -> <code>object</code>
104+
#### jsdoc2md.getNamepaths(options) <code>object</code>
105105
Returns all [jsdoc namepaths](http://usejsdoc.org/about-namepaths.html) found in the supplied source code.
106106

107107
**Kind**: instance method of [<code>JsdocToMarkdown</code>](#exp_module_jsdoc-to-markdown--JsdocToMarkdown)
@@ -113,7 +113,7 @@ Returns all [jsdoc namepaths](http://usejsdoc.org/about-namepaths.html) found in
113113

114114
<a name="module_jsdoc-to-markdown--JsdocToMarkdown+renderSync"></a>
115115

116-
#### jsdoc2md.renderSync([options]) -> <code>string</code>
116+
#### jsdoc2md.renderSync([options]) <code>string</code>
117117
Sync version of [render](#module_jsdoc-to-markdown--JsdocToMarkdown+render).
118118

119119
**Kind**: instance method of [<code>JsdocToMarkdown</code>](#exp_module_jsdoc-to-markdown--JsdocToMarkdown)
@@ -130,7 +130,7 @@ const docs = jsdoc2md.renderSync({ files: 'lib/*.js' })
130130
```
131131
<a name="module_jsdoc-to-markdown--JsdocToMarkdown+getTemplateDataSync"></a>
132132

133-
#### jsdoc2md.getTemplateDataSync([options]) -> <code>Array.&lt;object&gt;</code>
133+
#### jsdoc2md.getTemplateDataSync([options]) <code>Array.&lt;object&gt;</code>
134134
Sync version of [getTemplateData](#module_jsdoc-to-markdown--JsdocToMarkdown+getTemplateData).
135135

136136
**Kind**: instance method of [<code>JsdocToMarkdown</code>](#exp_module_jsdoc-to-markdown--JsdocToMarkdown)
@@ -142,7 +142,7 @@ Sync version of [getTemplateData](#module_jsdoc-to-markdown--JsdocToMarkdown+get
142142

143143
<a name="module_jsdoc-to-markdown--JsdocToMarkdown+getJsdocDataSync"></a>
144144

145-
#### jsdoc2md.getJsdocDataSync([options]) -> <code>Array.&lt;object&gt;</code>
145+
#### jsdoc2md.getJsdocDataSync([options]) <code>Array.&lt;object&gt;</code>
146146
Sync version of [getJsdocData](#module_jsdoc-to-markdown--JsdocToMarkdown+getJsdocData).
147147

148148
**Kind**: instance method of [<code>JsdocToMarkdown</code>](#exp_module_jsdoc-to-markdown--JsdocToMarkdown)

example/documentation/code/methods.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ headline: Custom Title!
88
## Functions
99

1010
<dl>
11-
<dt><a href="#ES6Method">ES6Method(param)</a> -> <code>string</code></dt>
11+
<dt><a href="#ES6Method">ES6Method(param)</a> <code>string</code></dt>
1212
<dd><p>A normal ES6 Method</p>
1313
</dd>
14-
<dt><a href="#standardMethod">standardMethod()</a> -> <code>string</code></dt>
14+
<dt><a href="#standardMethod">standardMethod()</a> <code>string</code></dt>
1515
<dd><p>A normal standard Method</p>
1616
</dd>
1717
</dl>
1818

1919
<a name="ES6Method"></a>
2020

21-
## ES6Method(param) -> <code>string</code>
21+
## ES6Method(param) <code>string</code>
2222
A normal ES6 Method
2323

2424
**Kind**: global function
@@ -29,7 +29,7 @@ A normal ES6 Method
2929

3030
<a name="standardMethod"></a>
3131

32-
## standardMethod() -> <code>string</code>
32+
## standardMethod() <code>string</code>
3333
A normal standard Method
3434

3535
**Kind**: global function

example/documentation/code/objects.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ name
2424
**Kind**: static property of [<code>obj</code>](#obj)
2525
<a name="obj.objMethod"></a>
2626

27-
### obj.objMethod(parameter) ->
27+
### obj.objMethod(parameter)
2828
A function with a parameter and returns the name
2929

3030
**Kind**: static method of [<code>obj</code>](#obj)

example/documentation/code/tests/class.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Get current name
3939
**Kind**: instance property of [<code>Test</code>](#Test)
4040
<a name="Test+generateFullName"></a>
4141

42-
### test.generateFullName() ->
42+
### test.generateFullName()
4343
Generate a fullname
4444

4545
**Kind**: instance method of [<code>Test</code>](#Test)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title: first.test
3+
---
4+
5+
# first.test
6+
7+
<a name="FirstTest"></a>
8+
9+
## FirstTest
10+
**Kind**: global class
11+
<a name="new_FirstTest_new"></a>
12+
13+
### new FirstTest()
14+
This is the FirstTest class
15+

src/interfaces.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface ParseReturn {
3333
export interface FileTree {
3434
name: string;
3535
path?: string;
36+
ext?: string;
3637
fullPath?: string;
3738
children?: FileTree[];
38-
}
39+
}

src/lib/list-folder.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,26 @@ export const listFolder = async (srcPath: string, exclude: string[] = [], mainPa
4747
// skip readmes as they are automatically resolved
4848
if (name.toLowerCase() === 'readme') continue;
4949

50-
if (!mm.isMatch(path.join(srcPath.replace(mainPath || srcPath, ''), dirent.name), exclude)) {
51-
const treeEntry: FileTree = {
52-
name,
53-
...(!isDir ? { path: `/${name}`, fullPath: path.join(srcPath, name), ext } : {})
54-
};
50+
const baseSrc = mainPath || srcPath;
5551

56-
tree.push(treeEntry);
52+
if (!mm.isMatch(path.join(srcPath.replace(baseSrc, ''), dirent.name), exclude)) {
53+
let treeEntry: FileTree = {
54+
name
55+
};
5756

5857
if (isDir) {
5958
treeEntry.children = [];
60-
paths.push(...(await listFolder(filePath, exclude, mainPath || srcPath, treeEntry.children)).paths);
59+
paths.push(...(await listFolder(filePath, exclude, baseSrc, treeEntry.children)).paths);
60+
} else {
61+
treeEntry = {
62+
...treeEntry,
63+
path: `/${name}`,
64+
fullPath: path.join(srcPath, name),
65+
ext
66+
};
6167
}
6268

69+
tree.push(treeEntry);
6370
paths.push(file);
6471
} else {
6572
excluded.push(file);

0 commit comments

Comments
 (0)