Skip to content

Commit eb1089e

Browse files
committed
Stop inferring parameters if fn is within a call.
Fixes #191 This a specific exception for the case identified in 191: we could, instead, include only cases of clear proximity, like var foo = function, or function foo.
1 parent 8ca0e08 commit eb1089e

File tree

6 files changed

+780
-0
lines changed

6 files changed

+780
-0
lines changed

lib/infer/params.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ module.exports = function () {
8282
return newParam;
8383
}
8484

85+
function abort() {
86+
return false
87+
}
88+
8589
types.visit(comment.context.ast, {
90+
visitCallExpression: abort,
8691
visitFunction: function (path) {
8792

8893
// Ensure that explicitly specified parameters are not overridden

test/fixture/nearby_params.input.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** Attempt to establish a cookie-based session in exchange for credentials.
2+
* @function
3+
* @name sessions.create
4+
* @param {object} credentials
5+
* @param {string} credentials.name Login username. Also accepted as `username` or `email`.
6+
* @param {string} credentials.password Login password
7+
* @param {function} [callback] Gets passed `(err, { success:Boolean })`.
8+
* @returns {Promise} promise, to be resolved on success or rejected on failure
9+
*/
10+
sessions.addMethod('create', 'POST / form', {
11+
// normalize request body params
12+
before({ body }) {
13+
}
14+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# sessions.create
2+
3+
Attempt to establish a cookie-based session in exchange for credentials.
4+
5+
6+
**Parameters**
7+
8+
- `credentials` **object**
9+
- `credentials.name` **string** Login username. Also accepted as `username` or `email`.
10+
11+
- `credentials.password` **string** Login password
12+
13+
- `callback` **[function]** Gets passed `(err, { success:Boolean })`.
14+
15+
16+
17+
Returns **Promise** promise, to be resolved on success or rejected on failure
18+
19+
20+
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
[
2+
{
3+
"description": "Attempt to establish a cookie-based session in exchange for credentials.",
4+
"tags": [
5+
{
6+
"title": "function",
7+
"description": null,
8+
"lineNumber": 1,
9+
"name": null
10+
},
11+
{
12+
"title": "name",
13+
"description": null,
14+
"lineNumber": 3,
15+
"name": "sessions.create"
16+
},
17+
{
18+
"title": "param",
19+
"description": null,
20+
"lineNumber": 4,
21+
"type": {
22+
"type": "NameExpression",
23+
"name": "object"
24+
},
25+
"name": "credentials",
26+
"properties": [
27+
{
28+
"title": "param",
29+
"description": "Login username. Also accepted as `username` or `email`.",
30+
"lineNumber": 5,
31+
"type": {
32+
"type": "NameExpression",
33+
"name": "string"
34+
},
35+
"name": "credentials.name"
36+
},
37+
{
38+
"title": "param",
39+
"description": "Login password",
40+
"lineNumber": 6,
41+
"type": {
42+
"type": "NameExpression",
43+
"name": "string"
44+
},
45+
"name": "credentials.password"
46+
}
47+
]
48+
},
49+
{
50+
"title": "param",
51+
"description": "Login username. Also accepted as `username` or `email`.",
52+
"lineNumber": 5,
53+
"type": {
54+
"type": "NameExpression",
55+
"name": "string"
56+
},
57+
"name": "credentials.name"
58+
},
59+
{
60+
"title": "param",
61+
"description": "Login password",
62+
"lineNumber": 6,
63+
"type": {
64+
"type": "NameExpression",
65+
"name": "string"
66+
},
67+
"name": "credentials.password"
68+
},
69+
{
70+
"title": "param",
71+
"description": "Gets passed `(err, { success:Boolean })`.",
72+
"lineNumber": 7,
73+
"type": {
74+
"type": "OptionalType",
75+
"expression": {
76+
"type": "NameExpression",
77+
"name": "function"
78+
}
79+
},
80+
"name": "callback"
81+
},
82+
{
83+
"title": "returns",
84+
"description": "promise, to be resolved on success or rejected on failure",
85+
"lineNumber": 8,
86+
"type": {
87+
"type": "NameExpression",
88+
"name": "Promise"
89+
}
90+
}
91+
],
92+
"loc": {
93+
"start": {
94+
"line": 1,
95+
"column": 0
96+
},
97+
"end": {
98+
"line": 9,
99+
"column": 3
100+
}
101+
},
102+
"context": {
103+
"loc": {
104+
"start": {
105+
"line": 10,
106+
"column": 0
107+
},
108+
"end": {
109+
"line": 14,
110+
"column": 3
111+
}
112+
},
113+
"code": "/** Attempt to establish a cookie-based session in exchange for credentials.\n * @function\n * @name sessions.create\n * @param {object} credentials\n * @param {string} credentials.name Login username. Also accepted as `username` or `email`.\n * @param {string} credentials.password Login password\n * @param {function} [callback] Gets passed `(err, { success:Boolean })`.\n * @returns {Promise} promise, to be resolved on success or rejected on failure\n */\nsessions.addMethod('create', 'POST / form', {\n // normalize request body params\n before({ body }) {\n }\n});\n"
114+
},
115+
"errors": [
116+
{
117+
"message": "type object found, Object is standard",
118+
"commentLineNumber": 4
119+
}
120+
],
121+
"function": null,
122+
"name": "sessions.create",
123+
"params": [
124+
{
125+
"title": "param",
126+
"description": null,
127+
"lineNumber": 4,
128+
"type": {
129+
"type": "NameExpression",
130+
"name": "object"
131+
},
132+
"name": "credentials",
133+
"properties": [
134+
{
135+
"title": "param",
136+
"description": "Login username. Also accepted as `username` or `email`.",
137+
"lineNumber": 5,
138+
"type": {
139+
"type": "NameExpression",
140+
"name": "string"
141+
},
142+
"name": "credentials.name"
143+
},
144+
{
145+
"title": "param",
146+
"description": "Login password",
147+
"lineNumber": 6,
148+
"type": {
149+
"type": "NameExpression",
150+
"name": "string"
151+
},
152+
"name": "credentials.password"
153+
}
154+
]
155+
},
156+
{
157+
"title": "param",
158+
"description": "Gets passed `(err, { success:Boolean })`.",
159+
"lineNumber": 7,
160+
"type": {
161+
"type": "OptionalType",
162+
"expression": {
163+
"type": "NameExpression",
164+
"name": "function"
165+
}
166+
},
167+
"name": "callback"
168+
}
169+
],
170+
"returns": [
171+
{
172+
"title": "returns",
173+
"description": "promise, to be resolved on success or rejected on failure",
174+
"lineNumber": 8,
175+
"type": {
176+
"type": "NameExpression",
177+
"name": "Promise"
178+
}
179+
}
180+
],
181+
"kind": "function",
182+
"members": {
183+
"instance": [],
184+
"static": []
185+
},
186+
"path": [
187+
"sessions.create"
188+
]
189+
}
190+
]

test/fixture/nearby_params.output.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# sessions.create
2+
3+
Attempt to establish a cookie-based session in exchange for credentials.
4+
5+
6+
**Parameters**
7+
8+
- `credentials` **object**
9+
- `credentials.name` **string** Login username. Also accepted as `username` or `email`.
10+
11+
- `credentials.password` **string** Login password
12+
13+
- `callback` **[function]** Gets passed `(err, { success:Boolean })`.
14+
15+
16+
17+
Returns **Promise** promise, to be resolved on success or rejected on failure
18+
19+
20+

0 commit comments

Comments
 (0)