Skip to content

Commit c652c16

Browse files
committed
Formatted code.
Added max-lines-per-function eslint flag.
1 parent 1b3d6ed commit c652c16

File tree

7 files changed

+202
-152
lines changed

7 files changed

+202
-152
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
],
55
"rules": {
66
"global-require": 0,
7+
"max-lines-per-function": 0,
78
"no-catch-shadow": 0,
89
"no-param-reassign": 0,
910
"no-shadow": 0,

lib/doxdox.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const DEFAULT_IGNORE_PATHS = [
1515
'!./Gulpfile.js'
1616
];
1717

18-
const REPLACE_FILENAME_REGEXP = new RegExp(`^(${process.cwd()}/|./)`);
18+
const REPLACE_FILENAME_REGEXP = new RegExp(`^(${process.cwd()}/|./)`, 'u');
1919

2020
/**
2121
* Parse a file with custom parser.
@@ -30,27 +30,27 @@ const REPLACE_FILENAME_REGEXP = new RegExp(`^(${process.cwd()}/|./)`);
3030
*/
3131

3232
const parseFile = (input, config) =>
33-
loaders.loadParser(setConfigDefaults(config)).then(parser => new Promise((resolve, reject) => {
33+
loaders.loadParser(setConfigDefaults(config)).then(parser =>
34+
new Promise((resolve, reject) => {
3435

35-
fs.readFile(input, 'utf8', (err, data) => {
36+
fs.readFile(input, 'utf8', (err, data) => {
3637

37-
if (err) {
38+
if (err) {
3839

39-
return reject(err);
40+
return reject(err);
4041

41-
}
42+
}
4243

43-
const filename = input.replace(REPLACE_FILENAME_REGEXP, '');
44+
const filename = input.replace(REPLACE_FILENAME_REGEXP, '');
4445

45-
return resolve({
46-
'methods': parser(data, filename),
47-
'name': filename
48-
});
49-
50-
});
46+
return resolve({
47+
'methods': parser(data, filename),
48+
'name': filename
49+
});
5150

52-
}));
51+
});
5352

53+
}));
5454

5555
/**
5656
* Parse array of files, and then render the parsed data through the defined layout plugin.
@@ -66,11 +66,13 @@ const parseFile = (input, config) =>
6666
* @public
6767
*/
6868

69-
const parseFiles = (files, config) => loaders.loadPlugin(setConfigDefaults(config)).then(plugin =>
70-
Promise.all(files.map(input => parseFile(input, config)))
71-
.then(files => plugin(Object.assign({
72-
'files': files.filter(file => file.methods.length)
73-
}, setConfigDefaults(config)))));
69+
const parseFiles = (files, config) =>
70+
loaders.loadPlugin(setConfigDefaults(config)).then(plugin =>
71+
Promise.all(files.map(input => parseFile(input, config))).then(files =>
72+
plugin({
73+
'files': files.filter(file => file.methods.length),
74+
...setConfigDefaults(config)
75+
})));
7476

7577
/**
7678
* Parse array of directory globs and/or files, and then render the parsed data through the defined layout plugin.
@@ -86,10 +88,11 @@ const parseFiles = (files, config) => loaders.loadPlugin(setConfigDefaults(confi
8688
* @public
8789
*/
8890

89-
const parseInputs = (inputs, config) => globby(inputs.concat(DEFAULT_IGNORE_PATHS,
90-
formatPathsArrayToIgnore(setConfigDefaults(config).ignore)
91-
)).then(files => parseFiles(files, config));
92-
91+
const parseInputs = (inputs, config) =>
92+
globby(inputs.concat(
93+
DEFAULT_IGNORE_PATHS,
94+
formatPathsArrayToIgnore(setConfigDefaults(config).ignore)
95+
)).then(files => parseFiles(files, config));
9396

9497
module.exports = {
9598
parseFile,

lib/loaders.js

Lines changed: 79 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,44 @@
33
const fs = require('fs');
44
const path = require('path');
55

6-
const HANDLEBARS_PATTERN = /\.(hbs|handlebars)$/;
7-
const JAVASCRIPT_PATTERN = /\.(js)$/;
6+
const HANDLEBARS_PATTERN = /\.(hbs|handlebars)$/u;
7+
const JAVASCRIPT_PATTERN = /\.(js)$/u;
88

99
const NODE_MODULE_DIRECTORIES = [
1010
path.join(__dirname, '..', 'node_modules'),
1111
path.join(process.cwd(), 'node_modules')
1212
];
1313

1414
/**
15-
* Find which node_modules directory to load package from.
16-
*
17-
* findPackagePath('doxdox-parser-dox').then(parser => {});
18-
* findPackagePath('doxdox-plugin-bootstrap').then(plugin => {});
19-
*
20-
* @param {String} pkg Package name as string.
21-
* @return {Object} Promise
22-
* @private
23-
*/
15+
* Find which node_modules directory to load package from.
16+
*
17+
* findPackagePath('doxdox-parser-dox').then(parser => {});
18+
* findPackagePath('doxdox-plugin-bootstrap').then(plugin => {});
19+
*
20+
* @param {String} pkg Package name as string.
21+
* @return {Object} Promise
22+
* @private
23+
*/
2424

2525
const findPackagePath = pkg =>
26-
Promise.all(NODE_MODULE_DIRECTORIES.map(dir => new Promise(resolve => {
26+
Promise.all(NODE_MODULE_DIRECTORIES.map(dir =>
27+
new Promise(resolve => {
2728

28-
const filepath = path.join(dir, pkg);
29+
const filepath = path.join(dir, pkg);
2930

30-
fs.stat(filepath, (err, stats) => {
31+
fs.stat(filepath, (err, stats) => {
3132

32-
if (!err && stats.isDirectory()) {
33+
if (!err && stats.isDirectory()) {
3334

34-
return resolve(filepath);
35+
return resolve(filepath);
3536

36-
}
37+
}
3738

38-
return resolve(null);
39+
return resolve(null);
3940

40-
});
41+
});
4142

42-
}))).then(dirs => dirs.filter(dir => dir));
43+
}))).then(dirs => dirs.filter(dir => dir));
4344

4445
/**
4546
* Load parser based on user defined choice.
@@ -53,47 +54,52 @@ const findPackagePath = pkg =>
5354
* @private
5455
*/
5556

56-
const loadParser = config => new Promise((resolve, reject) => {
57+
const loadParser = config =>
58+
new Promise((resolve, reject) => {
5759

58-
fs.stat(config.parser, (err, stats) => {
60+
fs.stat(config.parser, (err, stats) => {
5961

60-
if (err) {
62+
if (err) {
6163

62-
findPackagePath(`doxdox-parser-${config.parser}`).then(parser => {
64+
findPackagePath(`doxdox-parser-${config.parser}`).then(parser => {
6365

64-
if (parser.length) {
66+
if (parser.length) {
6567

66-
resolve(require(parser[0]));
68+
resolve(require(parser[0]));
6769

68-
} else {
70+
} else {
6971

70-
reject(new Error('Invalid parser specified.'));
72+
reject(new Error('Invalid parser specified.'));
7173

72-
}
74+
}
7375

74-
});
76+
});
7577

76-
} else if (stats && stats.isFile() && config.parser.match(JAVASCRIPT_PATTERN)) {
78+
} else if (
79+
stats &&
80+
stats.isFile() &&
81+
config.parser.match(JAVASCRIPT_PATTERN)
82+
) {
7783

78-
if (path.isAbsolute(config.parser)) {
84+
if (path.isAbsolute(config.parser)) {
7985

80-
resolve(require(config.parser));
86+
resolve(require(config.parser));
8187

82-
} else {
88+
} else {
8389

84-
resolve(require(path.join(process.cwd(), config.parser)));
90+
resolve(require(path.join(process.cwd(), config.parser)));
8591

86-
}
92+
}
8793

88-
} else {
94+
} else {
8995

90-
reject(new Error('Invalid parser specified.'));
96+
reject(new Error('Invalid parser specified.'));
9197

92-
}
98+
}
9399

94-
});
100+
});
95101

96-
});
102+
});
97103

98104
/**
99105
* Load layout plugin based on user defined choice.
@@ -108,52 +114,61 @@ const loadParser = config => new Promise((resolve, reject) => {
108114
* @private
109115
*/
110116

111-
const loadPlugin = config => new Promise((resolve, reject) => {
117+
const loadPlugin = config =>
118+
new Promise((resolve, reject) => {
112119

113-
fs.stat(config.layout, (err, stats) => {
120+
fs.stat(config.layout, (err, stats) => {
114121

115-
if (err) {
122+
if (err) {
116123

117-
findPackagePath(`doxdox-plugin-${config.layout}`).then(plugin => {
124+
findPackagePath(`doxdox-plugin-${config.layout}`).then(plugin => {
118125

119-
if (plugin.length) {
126+
if (plugin.length) {
120127

121-
resolve(require(plugin[0]));
128+
resolve(require(plugin[0]));
122129

123-
} else {
130+
} else {
124131

125-
reject(new Error('Invalid layout specified.'));
132+
reject(new Error('Invalid layout specified.'));
126133

127-
}
134+
}
128135

129-
});
136+
});
130137

131-
} else if (stats && stats.isFile() && config.layout.match(HANDLEBARS_PATTERN)) {
138+
} else if (
139+
stats &&
140+
stats.isFile() &&
141+
config.layout.match(HANDLEBARS_PATTERN)
142+
) {
132143

133-
resolve(require('doxdox-plugin-handlebars'));
144+
resolve(require('doxdox-plugin-handlebars'));
134145

135-
} else if (stats && stats.isFile() && config.layout.match(JAVASCRIPT_PATTERN)) {
146+
} else if (
147+
stats &&
148+
stats.isFile() &&
149+
config.layout.match(JAVASCRIPT_PATTERN)
150+
) {
136151

137-
if (path.isAbsolute(config.layout)) {
152+
if (path.isAbsolute(config.layout)) {
138153

139-
resolve(require(config.layout));
154+
resolve(require(config.layout));
140155

141-
} else {
156+
} else {
142157

143-
resolve(require(path.join(process.cwd(), config.layout)));
158+
resolve(require(path.join(process.cwd(), config.layout)));
144159

145-
}
160+
}
161+
162+
} else {
146163

147-
} else {
164+
reject(new Error('Invalid layout specified.'));
148165

149-
reject(new Error('Invalid layout specified.'));
166+
}
150167

151-
}
168+
});
152169

153170
});
154171

155-
});
156-
157172
module.exports = {
158173
findPackagePath,
159174
loadParser,

lib/utils.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const findPackageFileInPath = input => {
6262
*/
6363

6464
const formatPathsArrayToIgnore = paths =>
65-
paths.map(path => `!${path.replace(/^!/, '')}`);
65+
paths.map(path => `!${path.replace(/^!/u, '')}`);
6666

6767
/**
6868
* Sets default configuration values.
@@ -74,11 +74,12 @@ const formatPathsArrayToIgnore = paths =>
7474
* @public
7575
*/
7676

77-
const setConfigDefaults = config => Object.assign({
77+
const setConfigDefaults = config => ({
7878
'ignore': DEFAULT_CONFIG_IGNORE_PATHS,
7979
'parser': DEFAULT_CONFIG_PARSER,
80-
'plugin': DEFAULT_CONFIG_PLUGIN
81-
}, config);
80+
'plugin': DEFAULT_CONFIG_PLUGIN,
81+
...config
82+
});
8283

8384
module.exports = {
8485
findPackageFileInPath,

0 commit comments

Comments
 (0)