Skip to content

Commit 71824f4

Browse files
committed
Fix tag/param.js crazy formatting
1 parent ff6192d commit 71824f4

File tree

1 file changed

+157
-160
lines changed

1 file changed

+157
-160
lines changed

tags/param.js

Lines changed: 157 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -1,177 +1,174 @@
11
var tnd = require("bit-docs-type-annotate").typeNameDescription;
22

3-
var ordered = function( params ) {
4-
var arr = [];
5-
for ( var n in params ) {
6-
var param = params[n];
7-
arr[param.order] = param;
8-
}
9-
return arr;
10-
};
11-
var indexOf = function(arr, name){
12-
return arr.map(function(item){return item.name}).indexOf(name);
13-
};
14-
var getFunctionParams = function(tagData){
15-
if(tagData.types){
16-
for(var i =0; i< tagData.types.length; i++ ){
17-
if(tagData.types[i].type === "function"){
18-
return tagData.types[i].params;
19-
}
3+
var ordered = function (params) {
4+
var arr = [];
5+
for (var n in params) {
6+
var param = params[n];
7+
arr[param.order] = param;
8+
}
9+
return arr;
10+
};
11+
12+
var indexOf = function (arr, name) {
13+
return arr.map(function (item) { return item.name }).indexOf(name);
14+
};
15+
16+
var getFunctionParams = function (tagData) {
17+
if (tagData.types) {
18+
for (var i = 0; i < tagData.types.length; i++) {
19+
if (tagData.types[i].type === "function") {
20+
return tagData.types[i].params;
2021
}
2122
}
22-
};
23-
var addParam = function(param, params) {
24-
if ( indexOf(params, param.name) != -1) {
25-
// probably needs to swap
26-
params.splice(indexOf(params, param.name),1, param);
27-
} else {
28-
// add to params
23+
}
24+
};
2925

30-
params.push(param);
31-
}
32-
};
26+
var addParam = function (param, params) {
27+
if (indexOf(params, param.name) != -1) {
28+
// probably needs to swap
29+
params.splice(indexOf(params, param.name), 1, param);
30+
} else {
31+
// add to params
32+
params.push(param);
33+
}
34+
};
3335

34-
/**
35-
* @module {Object} bit-docs-js/tags/param @param
36-
* @parent bit-docs-js/tags
37-
*
38-
* Specifies parameter information for [bit-docs-js/tags/function] or
39-
* [bit-docs-js/tags/signature].
40-
*
41-
* A "parameter" is a method definition variable, like `a` in `function(a)`.
42-
*
43-
* @signature `@param {TYPE} NAME [DESCRIPTION]`
44-
*
45-
* @codestart javascript
46-
* /**
47-
* * Finds an order by id.
48-
* * @param {String} [id=0] Order identification number.
49-
* * @param {function(Order)} [success(order)] Callback function.
50-
* *|
51-
* findById: function( id, success ) {
52-
* @codeend
53-
*
54-
* Use `@param` within a [bit-docs-js/tags/function] comment block, or after
55-
* an [bit-docs-js/tags/signature] tag.
56-
*
57-
* @param {bit-docs-js/typeExpression} TYPE A [bit-docs-js/typeExpression type expression].
58-
*
59-
* Use [bit-docs-js/tags/option @option] to describe a function's arguments,
60-
* or an object's properties.
61-
*
62-
* @param {bit-docs-js/nameExpression} NAME A [bit-docs-js/nameExpression name expression].
63-
*
64-
* @body
65-
*
66-
* ## Use within a comment block
67-
*
68-
* If the comment block precedes a function declaration, like:
69-
*
70-
* @codestart javascript
71-
* /**
72-
* * Finds an order by id.
73-
* * @param {String} [id=0] Order identification number.
74-
* * @param {function(Order)} [success(order)] Filter order search by this.
75-
* *|
76-
* findById: function( id, success ) {
77-
* @codeend
78-
*
79-
* Then bit-docs will automatically set the type to function for the
80-
* [bit-docs-js/DocObject] representing that comment, and create params with
81-
* names only (in this case `id` and `success`, and no description).
82-
*
83-
* The comment's `@param`s tags should use the same names as the function.
84-
* Any param that specifies a name that isn't present is added at the end of
85-
* the arguments.
86-
*
87-
* ## Use after @signature
88-
*
89-
* Use `@param` to specify the parameter variables of a signature.
90-
*
91-
* @codestart javascript
92-
* /**
93-
* * Finds an order by id.
94-
* *
95-
* * @signature `Order.findById(id=0,[success])`
96-
* *
97-
* * @param {String} [id=0] Order identification number.
98-
* * @param {function(Order)} [success(order)] Callback function.
99-
* *|
100-
* findById: function( id, success ) {
101-
* @codeend
102-
*
103-
* When a `@signature` is used, any params automatically created from code
104-
* are overwritten.
105-
*/
106-
module.exports = {
36+
/**
37+
* @module {Object} bit-docs-js/tags/param @param
38+
* @parent bit-docs-js/tags
39+
*
40+
* Specifies parameter information for [bit-docs-js/tags/function] or
41+
* [bit-docs-js/tags/signature].
42+
*
43+
* A "parameter" is a method definition variable, like `a` in `function(a)`.
44+
*
45+
* @signature `@param {TYPE} NAME [DESCRIPTION]`
46+
*
47+
* @codestart javascript
48+
* /**
49+
* * Finds an order by id.
50+
* * @param {String} [id=0] Order identification number.
51+
* * @param {function(Order)} [success(order)] Callback function.
52+
* *|
53+
* findById: function( id, success ) {
54+
* @codeend
55+
*
56+
* Use `@param` within a [bit-docs-js/tags/function] comment block, or after
57+
* an [bit-docs-js/tags/signature] tag.
58+
*
59+
* @param {bit-docs-js/typeExpression} TYPE A [bit-docs-js/typeExpression type expression].
60+
*
61+
* Use [bit-docs-js/tags/option @option] to describe a function's arguments,
62+
* or an object's properties.
63+
*
64+
* @param {bit-docs-js/nameExpression} NAME A [bit-docs-js/nameExpression name expression].
65+
*
66+
* @body
67+
*
68+
* ## Use within a comment block
69+
*
70+
* If the comment block precedes a function declaration, like:
71+
*
72+
* @codestart javascript
73+
* /**
74+
* * Finds an order by id.
75+
* * @param {String} [id=0] Order identification number.
76+
* * @param {function(Order)} [success(order)] Filter order search by this.
77+
* *|
78+
* findById: function( id, success ) {
79+
* @codeend
80+
*
81+
* Then bit-docs will automatically set the type to function for the
82+
* [bit-docs-js/DocObject] representing that comment, and create params with
83+
* names only (in this case `id` and `success`, and no description).
84+
*
85+
* The comment's `@param`s tags should use the same names as the function.
86+
* Any param that specifies a name that isn't present is added at the end of
87+
* the arguments.
88+
*
89+
* ## Use after @signature
90+
*
91+
* Use `@param` to specify the parameter variables of a signature.
92+
*
93+
* @codestart javascript
94+
* /**
95+
* * Finds an order by id.
96+
* *
97+
* * @signature `Order.findById(id=0,[success])`
98+
* *
99+
* * @param {String} [id=0] Order identification number.
100+
* * @param {function(Order)} [success(order)] Callback function.
101+
* *|
102+
* findById: function( id, success ) {
103+
* @codeend
104+
*
105+
* When a `@signature` is used, any params automatically created from code
106+
* are overwritten.
107+
*/
108+
module.exports = {
109+
addMore: function (line, last) {
110+
if (last) last.description += "\n" + line;
111+
},
112+
add: function (line, tagData) {
113+
var param = tnd(line);
114+
/* TODO no print statements
115+
if(!param.type && !param.name){
116+
print("LINE: \n" + line + "\n does not match @param {TYPE} NAME DESCRIPTION");
117+
}
118+
*/
119+
// only do nested lookup if actually nested
120+
if (tagData && tagData !== this) {
121+
var params = getFunctionParams(tagData);
122+
if (params) {
123+
addParam(param, params);
124+
return param;
125+
}
126+
}
107127

108-
addMore: function( line, last ) {
109-
if ( last ) last.description += "\n" + line;
110-
},
111-
add: function( line, tagData ) {
128+
// if we have a signiture, add this param to the last
129+
// signiture
130+
if (this.signatures) {
131+
this.signatures[this.signatures.length - 1].params.push(param);
132+
} else {
133+
var params = getFunctionParams(this);
134+
// check types (created by typedef) for a function type
112135

113-
var param = tnd(line);
114-
/* TODO no print statements
115-
if(!param.type && !param.name){
116-
print("LINE: \n" + line + "\n does not match @param {TYPE} NAME DESCRIPTION");
117-
}
118-
*/
119-
// only do nested lookup if actually nested
120-
if(tagData && tagData !== this) {
121-
var params = getFunctionParams(tagData);
122-
if(params) {
123-
addParam(param, params);
124-
return param;
136+
// params not found
137+
if (!params) {
138+
// create a params directly on the current object
139+
if (!this.params) {
140+
this.params = [];
125141
}
142+
params = this.params;
126143
}
127144

145+
// we are the _body's_ param
146+
// check if one by the same name hasn't already been created
147+
addParam(param, params);
148+
}
128149

129-
// if we have a signiture, add this param to the last
130-
// signiture
131-
if(this.signatures){
132-
this.signatures[this.signatures.length-1].params.push(param);
133-
} else {
134-
135-
var params = getFunctionParams(this);
136-
// check types (created by typedef) for a function type
137-
150+
this._curParam = param;
138151

139-
// params not found
140-
if(!params){
141-
// create a params directly on the current object
142-
if (!this.params ) {
143-
this.params = [];
144-
}
145-
params = this.params;
152+
return param;
153+
},
154+
done: function () {
155+
// recursively look for description properties
156+
var findDescriptions = function (obj) {
157+
for (var prop in obj) {
158+
var val = obj[prop]
159+
isObject = val && typeof val === "object"
160+
if (prop === "description") {
161+
obj.description = obj.description.trim();
162+
} else if (isObject && obj[prop].forEach) {
163+
obj[prop].forEach(findDescriptions);
164+
} else if (isObject) {
165+
findDescriptions(val);
146166
}
147-
148-
149-
// we are the _body's_ param
150-
// check if one by the same name hasn't already been created
151-
addParam(param, params);
152167
}
153-
this._curParam = param;
154-
return param;
155-
},
156-
done : function(){
168+
};
157169

170+
findDescriptions(this);
158171

159-
// recursively look for description properties
160-
var findDescriptions = function(obj){
161-
for(var prop in obj){
162-
var val = obj[prop]
163-
isObject = val && typeof val === "object"
164-
if(prop === "description"){
165-
obj.description = obj.description.trim();
166-
} else if(isObject && obj[prop].forEach){
167-
obj[prop].forEach(findDescriptions);
168-
} else if(isObject){
169-
findDescriptions(val);
170-
}
171-
}
172-
};
173-
findDescriptions(this);
174-
175-
delete this._curParam;
176-
}
177-
};
172+
delete this._curParam;
173+
}
174+
};

0 commit comments

Comments
 (0)