Skip to content

Commit 7e01278

Browse files
hugojosefsonanthony-redFox
authored andcommitted
Fix args regression: readme --shallow --format (Invalid second argument) (#968)
* Add shared_options to readme command. This makes --shallow and --format work again. * Update yarn.lock based on package.json. * Move readme example to where it works, remove superfluous usage string. yargs@>=7 throws exceptions on incorrectly structured builder objects. * Update expected readme test fixture. * Update bin-readme snapshot. * s/_.assign/Object.assign/g thanks to node@>=4. * Update yarn.lock based on package.json (lint-staged@6) * Override flow error message.
1 parent b6e7e7d commit 7e01278

File tree

9 files changed

+387
-249
lines changed

9 files changed

+387
-249
lines changed

__tests__/__snapshots__/bin-readme.js.snap

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ exports[`readme command --readme-file 1`] = `
77
88
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
99
10+
### Table of Contents
11+
12+
- [foo](#foo)
13+
- [bar](#bar)
14+
1015
## foo
1116
1217
A function with documentation.
@@ -36,6 +41,11 @@ exports[`readme command updates README.md 1`] = `
3641
3742
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
3843
44+
### Table of Contents
45+
46+
- [foo](#foo)
47+
- [bar](#bar)
48+
3949
## foo
4050
4151
A function with documentation.

__tests__/fixture/readme/README.output.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
66

7+
### Table of Contents
8+
9+
- [foo](#foo)
10+
- [bar](#bar)
11+
712
## foo
813

914
A function with documentation.

bin/documentation.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var argv = yargs
2121
}
2222
})
2323
.example('documentation build foo.js -f md > API.md')
24+
.example('documentation readme index.js -s "API Docs" --github')
2425
.version()
2526
.usage(
2627
`Usage:

src/commands/build.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports.describe = 'build documentation';
1818
* @returns {Object} yargs with options
1919
* @private
2020
*/
21-
module.exports.builder = _.assign(
21+
module.exports.builder = Object.assign(
2222
{},
2323
sharedOptions.sharedOutputOptions,
2424
sharedOptions.sharedInputOptions,

src/commands/readme.js

+30-27
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,49 @@ var fs = require('fs');
44
var remark = require('remark');
55
var path = require('path');
66
var documentation = require('../');
7+
var sharedOptions = require('./shared_options');
78
var inject = require('mdast-util-inject');
89
var chalk = require('chalk');
910
var disparity = require('disparity');
1011

1112
module.exports.command = 'readme [input..]';
1213
module.exports.description = 'inject documentation into your README.md';
14+
1315
/**
1416
* Add yargs parsing for the readme command
1517
* @param {Object} yargs module instance
1618
* @returns {Object} yargs with options
1719
* @private
1820
*/
19-
module.exports.builder = {
20-
usage:
21-
'Usage: documentation readme [--readme-file=README.md] --section "API"' +
22-
' [--compare-only] [other documentationjs options]',
23-
example: 'documentation readme index.js -s "API Docs" --github',
24-
'readme-file': {
25-
describe: 'The markdown file into which to inject documentation',
26-
default: 'README.md'
27-
},
28-
section: {
29-
alias: 's',
30-
describe:
31-
'The section heading after which to inject generated documentation',
32-
required: true
33-
},
34-
'diff-only': {
35-
alias: 'd',
36-
describe:
37-
'Instead of updating the given README with the generated documentation,' +
38-
' just check if its contents match, exiting nonzero if not.',
39-
default: false
40-
},
41-
quiet: {
42-
alias: 'q',
43-
describe: 'Quiet mode: do not print messages or README diff to stdout.',
44-
default: false
21+
module.exports.builder = Object.assign(
22+
{},
23+
sharedOptions.sharedOutputOptions,
24+
sharedOptions.sharedInputOptions,
25+
{
26+
'readme-file': {
27+
describe: 'The markdown file into which to inject documentation',
28+
default: 'README.md'
29+
},
30+
section: {
31+
alias: 's',
32+
describe:
33+
'The section heading after which to inject generated documentation',
34+
required: true
35+
},
36+
'diff-only': {
37+
alias: 'd',
38+
describe:
39+
'Instead of updating the given README with the generated documentation,' +
40+
' just check if its contents match, exiting nonzero if not.',
41+
default: false
42+
},
43+
quiet: {
44+
alias: 'q',
45+
describe: 'Quiet mode: do not print messages or README diff to stdout.',
46+
default: false
47+
}
4548
}
46-
};
49+
);
4750

4851
/**
4952
* Insert API documentation into a Markdown readme

src/commands/serve.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports.description = 'generate, update, and display HTML documentation';
1818
* @returns {Object} yargs with options
1919
* @private
2020
*/
21-
module.exports.builder = _.assign(
21+
module.exports.builder = Object.assign(
2222
{},
2323
sharedOptions.sharedOutputOptions,
2424
sharedOptions.sharedInputOptions,

src/infer/params.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function inferAndCombineParams(params, comment) {
5555
var mergedParamsAndErrors = mergeTrees(inferredParams, comment.params);
5656

5757
// Then merge the trees. This is the hard part.
58-
return _.assign(comment, {
58+
return Object.assign(comment, {
5959
params: mergedParamsAndErrors.mergedParams,
6060
errors: comment.errors.concat(mergedParamsAndErrors.errors)
6161
});
@@ -114,7 +114,7 @@ function paramToDoc(
114114
throw new Error('Encountered an unexpected parameter type');
115115
}
116116

117-
return _.assign(newAssignmentParam, {
117+
return Object.assign(newAssignmentParam, {
118118
default: generate(param.right, {
119119
compact: true
120120
}).code,
@@ -181,7 +181,7 @@ function paramToDoc(
181181
// instead we're going to (immutably) rename the parameters to their
182182
// indices
183183
properties: _.flatMap(param.elements, (element, idx) => {
184-
var indexedElement = _.assign({}, element, {
184+
var indexedElement = Object.assign({}, element, {
185185
name: String(idx),
186186
indexed: true
187187
});
@@ -190,16 +190,22 @@ function paramToDoc(
190190
};
191191
}
192192
return _.flatMap(param.elements, (element, idx) => {
193-
var indexedElement = _.assign({}, element, {
193+
var indexedElement = Object.assign({}, element, {
194194
name: String(idx)
195195
});
196196
return paramToDoc(indexedElement, prefix);
197197
});
198198
}
199199
case 'ObjectProperty': {
200-
return _.assign(paramToDoc(param.value, prefix + '.' + param.key.name || param.key.value), {
201-
name: prefix + '.' + param.key.name || param.key.value
202-
});
200+
return Object.assign(
201+
((paramToDoc(
202+
param.value,
203+
prefix + '.' + param.key.name || param.key.value
204+
): any): CommentTag),
205+
{
206+
name: prefix + '.' + param.key.name || param.key.value
207+
}
208+
);
203209
}
204210
case 'RestProperty': // (a, ...b)
205211
case 'RestElement': {
@@ -342,7 +348,7 @@ function combineTags(inferredTag, explicitTag) {
342348
(inferredTag.properties && inferredTag.properties.length) ||
343349
(explicitTag.properties && explicitTag.properties.length);
344350

345-
return _.assign(
351+
return Object.assign(
346352
explicitTag,
347353
hasProperties
348354
? {

src/nest.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var nestTag = (
4646
// get to this case because the recursive method
4747
// is always passed parts.slice(1)
4848
if (parts.length === 1) {
49-
_.assign(node, {
49+
Object.assign(node, {
5050
properties: (node.properties || []).concat(tag)
5151
});
5252
} else {
@@ -62,7 +62,9 @@ var nestTag = (
6262
if (tag.name.match(/^(\$\d+)/)) {
6363
errors.push({
6464
message:
65-
`Parent of ${tag.name} not found. To document a destructuring\n` +
65+
`Parent of ${
66+
tag.name
67+
} not found. To document a destructuring\n` +
6668
`type, add a @param tag in its position to specify the name of the\n` +
6769
`destructured parameter`,
6870
commentLineNumber: tag.lineNumber

0 commit comments

Comments
 (0)