Skip to content

Commit 45370ea

Browse files
committed
refactor(smells): fix some code smells
1 parent 1b8870e commit 45370ea

File tree

6 files changed

+27
-28
lines changed

6 files changed

+27
-28
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# vuepress-jsdoc
22

3-
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/9ec565a85a134df2a0f6bdf905e438d4)](https://app.codacy.com/app/ph1p/vuepress-jsdoc?utm_source=github.com&utm_medium=referral&utm_content=ph1p/vuepress-jsdoc&utm_campaign=Badge_Grade_Settings)
3+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ph1p_vuepress-jsdoc&metric=alert_status)](https://sonarcloud.io/dashboard?id=ph1p_vuepress-jsdoc)
44
[![npm](https://img.shields.io/npm/v/vuepress-jsdoc.svg)](https://www.npmjs.com/package/vuepress-jsdoc)
55
[![vercel](https://img.shields.io/badge/vercel-demo-black)](https://vuepress-jsdoc-example.vercel.app)
66

77
This npm package is a command line script, which scans your JavaScript, Vue or Typescript source code and generates markdown files for vuepress with the help of [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown) and [vue-docgen-cli](https://github.com/vue-styleguidist/vue-styleguidist/tree/dev/packages/vue-docgen-cli).
88

99
![CLI ./example](https://user-images.githubusercontent.com/15351728/131877824-0124e47f-9080-4976-88d0-84ad04b64f24.gif)
10+
1011
## How to
1112

1213
```bash

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const parseArguments = (argv: CLIArguments) => {
5959
* @param {object} argv passed arguments
6060
*/
6161
export const generate = async (argv: CLIArguments) => {
62-
const { exclude, srcFolder, codeFolder, docsFolder, title, readme, rmPattern, partials } = parseArguments(argv);
62+
const { exclude, srcFolder, codeFolder, docsFolder, title, readme, rmPattern } = parseArguments(argv);
6363

6464
const startTime = +new Date();
6565

@@ -77,7 +77,7 @@ export const generate = async (argv: CLIArguments) => {
7777
if (!file.isDir) {
7878
readline.clearLine(process.stdout, 0);
7979
readline.cursorTo(process.stdout, 0);
80-
process.stdout.write(`${chalk.dim(` ${file.path} `)}`);
80+
process.stdout.write(chalk.dim(` ${file.path} `));
8181
await new Promise(resolve => setTimeout(resolve, 20));
8282
}
8383
}

src/interfaces.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,14 @@ export interface CLIArguments {
1818
readme: string;
1919
watch: boolean;
2020
}
21+
22+
export interface ParseReturn {
23+
success: boolean;
24+
dest: string;
25+
file: DirectoryFile;
26+
content: string;
27+
empty: boolean;
28+
excluded?: boolean;
29+
relativePathSrc: string;
30+
relativePathDest: string;
31+
}

src/lib/list-folder.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import chalk from 'chalk';
21
import fs from 'fs/promises';
32
import mm from 'micromatch';
43
import path from 'path';

src/lib/parser.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import chalk from 'chalk';
21
import fs from 'fs/promises';
32
import jsdoc2md from 'jsdoc-to-markdown';
43
import mkdirp from 'mkdirp';
@@ -7,21 +6,10 @@ import compileTemplates from 'vue-docgen-cli/lib/compileTemplates';
76
import { extractConfig } from 'vue-docgen-cli/lib/docgen';
87

98
import { StatisticType } from '../constants';
10-
import { DirectoryFile } from '../interfaces';
9+
import { DirectoryFile, ParseReturn } from '../interfaces';
1110

1211
import { parseVuepressFileHeader } from './comment-parser';
1312

14-
interface ParseReturn {
15-
success: boolean;
16-
dest: string;
17-
file: DirectoryFile;
18-
content: string;
19-
empty: boolean;
20-
excluded?: boolean;
21-
relativePathSrc: string;
22-
relativePathDest: string;
23-
}
24-
2513
export const parseFile = async (
2614
file: DirectoryFile,
2715
srcFolder: string,

src/lib/utils.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
/**
22
* Get extension of file
3-
*
4-
* @param {string} path
3+
* @param path
54
* @returns extension of file
65
*/
76
export const getExtension = (path: string) => path.substring(path.length, path.lastIndexOf('.'));
87

98
/**
109
* Check if extension ist correct
11-
*
12-
* @param {string} path
13-
* @param {array} extensions
14-
* @returns a boolean
10+
* @param path
11+
* @param extensions
12+
* @returns boolean
1513
*/
1614
export const checkExtension = (path: string, extensions: string[]) => extensions.indexOf(getExtension(path)) >= 0;
1715

1816
/**
1917
* Get filename without extension
20-
*
21-
* @param {string} path
18+
* @param path
2219
* @returns filename
2320
*/
2421
export const getFilename = (path: string) =>
@@ -29,10 +26,13 @@ export const getFilename = (path: string) =>
2926

3027
/**
3128
* Async foreach loop
32-
* @param {array} array
33-
* @param {function} callback
29+
* @param array
30+
* @param callback
3431
*/
35-
export const asyncForEach = async (array: any[], callback: (result: any, index: number, array: any[]) => void) => {
32+
export const asyncForEach = async (
33+
array: any[],
34+
callback: (result: any, index: number, array: any[]) => Promise<void>
35+
) => {
3636
for (let index = 0; index < array.length; index++) {
3737
await callback(array[index], index, array);
3838
}

0 commit comments

Comments
 (0)