Skip to content

Commit 58c6892

Browse files
committed
Fix parameter sorting: avoid nesting errors and keep params together
1 parent 0c3f178 commit 58c6892

12 files changed

+2846
-67
lines changed

Diff for: lib/infer/params.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ function paramToDoc(param, comment, i, prefix) {
152152
return addPrefix(newParam);
153153
}
154154

155+
function insertBeforeDependents(comment, comments) {
156+
var dependentNamePrefix = comment.name + '.';
157+
for (var insertionIndex = 0; insertionIndex < comments.length; insertionIndex++) {
158+
if (comments[insertionIndex].name.indexOf(dependentNamePrefix) === 0) {
159+
break;
160+
}
161+
}
162+
return comments.slice(0, insertionIndex)
163+
.concat(comment)
164+
.concat(comments.slice(insertionIndex));
165+
}
166+
155167
/**
156168
* Infers param tags by reading function parameter names
157169
*
@@ -193,7 +205,7 @@ function inferParams() {
193205
comment.params = [];
194206
}
195207

196-
comment.params = comment.params.concat(doc);
208+
comment.params = insertBeforeDependents(doc, comment.params);
197209
} else if (!existingParams[doc.name].type) {
198210
// This param has a description, but potentially it can
199211
// be have an inferred type. Infer its type without
@@ -212,15 +224,6 @@ function inferParams() {
212224
paramOrder[doc.name] = i++;
213225
});
214226

215-
// Ensure that if params are specified partially or in
216-
// the wrong order, they'll be output in the order
217-
// they actually appear in code
218-
if (comment.params) {
219-
comment.params.sort(function (a, b) {
220-
return paramOrder[a.name] - paramOrder[b.name];
221-
});
222-
}
223-
224227
return comment;
225228
});
226229
}

Diff for: test/fixture/nest_params.input.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @param {string} employees[].department - The employee's department.
55
* @param {string} [type=minion] - The employee's type.
66
*/
7-
function foo(employee, type) {
7+
function foo(employees, type) {
88
}
99

1010
/**

Diff for: test/fixture/nest_params.output.json

-5
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,6 @@
271271
}
272272
]
273273
},
274-
{
275-
"title": "param",
276-
"name": "employee",
277-
"lineNumber": 7
278-
},
279274
{
280275
"name": "type",
281276
"lineNumber": 4,

Diff for: test/fixture/nest_params.output.md

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
- `employees` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>** The employees who are responsible for the project.
88
- `employees[].name` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name of an employee.
99
- `employees[].department` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The employee's department.
10-
- `employee`
1110
- `type` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** The employee's type. (optional, default `minion`)
1211

1312
# foo

Diff for: test/fixture/nest_params.output.md.json

-22
Original file line numberDiff line numberDiff line change
@@ -272,28 +272,6 @@
272272
}
273273
]
274274
},
275-
{
276-
"type": "listItem",
277-
"children": [
278-
{
279-
"type": "paragraph",
280-
"children": [
281-
{
282-
"type": "inlineCode",
283-
"value": "employee"
284-
},
285-
{
286-
"type": "text",
287-
"value": " "
288-
},
289-
{
290-
"type": "text",
291-
"value": " "
292-
}
293-
]
294-
}
295-
]
296-
},
297275
{
298276
"type": "listItem",
299277
"children": [

Diff for: test/fixture/params.output.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@
8888
},
8989
"errors": [],
9090
"params": [
91-
{
92-
"title": "param",
93-
"name": "a",
94-
"lineNumber": 5
95-
},
9691
{
9792
"name": "b",
9893
"lineNumber": 2,
@@ -153,6 +148,11 @@
153148
"name": "number"
154149
}
155150
},
151+
{
152+
"title": "param",
153+
"name": "a",
154+
"lineNumber": 5
155+
},
156156
{
157157
"title": "param",
158158
"name": "c",

Diff for: test/fixture/params.output.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ This function returns the number one.
66

77
**Parameters**
88

9-
- `a`
109
- `b` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** the second param
10+
- `a`
1111
- `c`
1212
- `$3` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
1313
- `$3.d`

Diff for: test/fixture/params.output.md.json

+22-22
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,6 @@
6363
"ordered": false,
6464
"type": "list",
6565
"children": [
66-
{
67-
"type": "listItem",
68-
"children": [
69-
{
70-
"type": "paragraph",
71-
"children": [
72-
{
73-
"type": "inlineCode",
74-
"value": "a"
75-
},
76-
{
77-
"type": "text",
78-
"value": " "
79-
},
80-
{
81-
"type": "text",
82-
"value": " "
83-
}
84-
]
85-
}
86-
]
87-
},
8866
{
8967
"type": "listItem",
9068
"children": [
@@ -158,6 +136,28 @@
158136
}
159137
]
160138
},
139+
{
140+
"type": "listItem",
141+
"children": [
142+
{
143+
"type": "paragraph",
144+
"children": [
145+
{
146+
"type": "inlineCode",
147+
"value": "a"
148+
},
149+
{
150+
"type": "text",
151+
"value": " "
152+
},
153+
{
154+
"type": "text",
155+
"value": " "
156+
}
157+
]
158+
}
159+
]
160+
},
161161
{
162162
"type": "listItem",
163163
"children": [

Diff for: test/fixture/sync/lots-of-options.input.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Global spectra deconvolution
3+
* @param {Array<Number>} x - Independent variable
4+
* @param {Array<Number>} yIn - Dependent variable
5+
* @param {Object} [options] - Options object
6+
* @param {Object} [options.sgOptions] - Options object for Savitzky-Golay filter. See https://github.com/mljs/savitzky-golay-generalized#options
7+
* @param {Number} [options.minMaxRatio = 0.00025] - Threshold to determine if a given peak should be considered as a noise
8+
* @param {Number} [options.broadRatio = 0.00] - If `broadRatio` is higher than 0, then all the peaks which second derivative
9+
* smaller than `broadRatio * maxAbsSecondDerivative` will be marked with the soft mask equal to true.
10+
* @param {Number} [options.noiseLevel = 3] - Noise threshold in spectrum units
11+
* @param {Boolean} [options.maxCriteria = true] - Peaks are local maximum(true) or minimum(false)
12+
* @param {Boolean} [options.smoothY = true] - Select the peak intensities from a smoothed version of the independent variables
13+
* @param {Boolean} [options.realTopDetection = false] - Use a quadratic optimizations with the peak and its 3 closest neighbors
14+
* to determine the true x,y values of the peak?
15+
* @param {Number} [options.heightFactor = 0] - Factor to multiply the calculated height (usually 2)
16+
* @param {Boolean} [options.boundaries = false] - Return also the inflection points of the peaks
17+
* @param {Number} [options.derivativeThreshold = 0] - Filters based on the amplitude of the first derivative
18+
* @return {Array<Object>}
19+
*/
20+
function gsd(x, yIn, options) {
21+
}
22+
23+
module.exports = gsd;

0 commit comments

Comments
 (0)