Skip to content

Commit a389ce0

Browse files
committed
Fix tag/option.js crazy formatting
1 parent c370e73 commit a389ce0

File tree

1 file changed

+177
-176
lines changed

1 file changed

+177
-176
lines changed

tags/option.js

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

3-
// go through the types and get the first one that has options
4-
var getOptions = function(param){
5-
if(!param.types) {
6-
return;
3+
// go through the types and get the first one that has options
4+
var getOptions = function (param) {
5+
if (!param.types) {
6+
return;
7+
}
8+
for (var i = 0; i < param.types.length; i++) {
9+
if (param.types[i].options) {
10+
return param.types[i].options;
711
}
8-
for(var i =0; i < param.types.length; i++) {
9-
if( param.types[i].options ) {
10-
return param.types[i].options;
11-
}
12-
}
13-
};
14-
// go through the types and return the first one that has params
15-
var getParams = function(param){
16-
if(!param.types) {
17-
return;
12+
}
13+
};
14+
15+
// go through the types and return the first one that has params
16+
var getParams = function (param) {
17+
if (!param.types) {
18+
return;
19+
}
20+
for (var i = 0; i < param.types.length; i++) {
21+
if (param.types[i].params) {
22+
return param.types[i].params;
1823
}
19-
for(var i =0; i < param.types.length; i++) {
20-
if( param.types[i].params ) {
21-
return param.types[i].params;
22-
}
24+
}
25+
};
26+
27+
// find matching type
28+
var getType = function (types, type) {
29+
for (var i = 0; i < types.length; i++) {
30+
if (types[i].type === type) {
31+
return types[i];
2332
}
24-
};
33+
}
34+
};
2535

26-
// find matching type
27-
var getType = function(types, type){
28-
for(var i =0; i < types.length; i++) {
29-
if( types[i].type === type ) {
30-
return types[i];
31-
}
32-
}
33-
};
34-
35-
var getOrMakeOptionByName = function(options, name){
36-
for(var i =0; i < options.length; i++) {
37-
if( options[i].name === name ) {
38-
return options[i];
39-
}
36+
var getOrMakeOptionByName = function (options, name) {
37+
for (var i = 0; i < options.length; i++) {
38+
if (options[i].name === name) {
39+
return options[i];
4040
}
41-
var option = {name: name};
42-
options.push(option);
43-
return option;
41+
}
42+
var option = { name: name };
43+
options.push(option);
44+
return option;
45+
};
46+
47+
var setOptionData = function (option, data) {
48+
option.description = data.description;
49+
50+
for (var prop in data) {
51+
option[prop] = data[prop];
52+
}
53+
};
54+
55+
/**
56+
* @module bit-docs-js/tags/option @option
57+
* @tag documentation
58+
* @parent bit-docs-js/tags
59+
*
60+
* Describes a property or argument of the object or function specified in
61+
* an [bit-docs-js/tags/param] tag.
62+
*
63+
* @signature `@option {TYPE} NAME [DESCRIPTION]`
64+
*
65+
* @codestart javascript
66+
* /**
67+
* * Retrieves a list of orders.
68+
* *
69+
* * @param {{}} params A parameter object with the following options:
70+
* * @option {String} type Specifies the type of order.
71+
* * @option {Number} [createdAt] Retrieves orders after this timestamp.
72+
* *
73+
* * @param {function(Orders.List)} [success(orders)] Callback function.
74+
* * @option orders A list of [Orders] that match `params`.
75+
* *|
76+
* find: function( params, success ) {
77+
* @codeend
78+
*
79+
*
80+
* @param {bit-docs/typeExpression} [TYPE] A [bit-docs/typeExpression type expression]. Examples:
81+
*
82+
* `{String}` - type is a `String`.
83+
* `{function(name)}` - type is a `function` that takes one `name` argument.
84+
*
85+
* `TYPE` does not need to be specified for types that are already described
86+
* in the `@option`'s corresponding function or object.
87+
*
88+
* For example, notice how there is no need to specify `{String}`:
89+
*
90+
* @codestart
91+
* /**
92+
* * @param {{type: String}} params An object with the following options:
93+
* * @option type Specifies the type of order.
94+
* * @option label Retrieves only orders with this label.
95+
* *|
96+
* @codeend
97+
*
98+
*
99+
* @param {bit-docs/nameExpression} NAME
100+
* A [bit-docs/nameExpression name expression]. Examples:
101+
*
102+
* `age` - age is item.
103+
* `[age]` - age is item, age is optional.
104+
* `[age=0]` - age defaults to 0.
105+
*
106+
*
107+
* @param {Markdown} [DESCRIPTION] Markdown content that continues for multiple lines.
108+
*/
109+
module.exports = {
110+
addMore: function (line, last) {
111+
if (last) last.description += "\n" + line;
44112
},
45-
setOptionData = function(option, data){
46-
option.description = data.description;
47-
48-
for(var prop in data){
49-
option[prop] = data[prop];
50-
}
51-
};
52-
53-
54-
/**
55-
* @module bit-docs-js/tags/option @option
56-
* @tag documentation
57-
* @parent bit-docs-js/tags
58-
*
59-
* Describes a property or argument of the object or function specified in
60-
* an [bit-docs-js/tags/param] tag.
61-
*
62-
* @@signature `@option {TYPE} NAME [DESCRIPTION]`
63-
*
64-
* @codestart javascript
65-
* /**
66-
* * Retrieves a list of orders.
67-
* *
68-
* * @param {{}} params A parameter object with the following options:
69-
* * @option {String} type Specifies the type of order.
70-
* * @option {Number} [createdAt] Retrieves orders after this timestamp.
71-
* *
72-
* * @param {function(Orders.List)} [success(orders)] Callback function.
73-
* * @option orders A list of [Orders] that match `params`.
74-
* *|
75-
* find: function( params, success ) {
76-
* @codeend
77-
*
78-
*
79-
* @param {bit-docs/typeExpression} [TYPE] A [bit-docs/typeExpression type expression]. Examples:
80-
*
81-
* `{String}` - type is a `String`.
82-
* `{function(name)}` - type is a `function` that takes one `name` argument.
83-
*
84-
* `TYPE` does not need to be specified for types that are already described
85-
* in the `@option`'s corresponding function or object.
86-
*
87-
* For example, notice how there is no need to specify `{String}`:
88-
*
89-
* @codestart
90-
* /**
91-
* * @param {{type: String}} params An object with the following options:
92-
* * @option type Specifies the type of order.
93-
* * @option label Retrieves only orders with this label.
94-
* *|
95-
* @codeend
96-
*
97-
*
98-
* @param {bit-docs/nameExpression} NAME
99-
* A [bit-docs/nameExpression name expression]. Examples:
100-
*
101-
* `age` - age is item.
102-
* `[age]` - age is item, age is optional.
103-
* `[age=0]` - age defaults to 0.
104-
*
105-
*
106-
* @param {Markdown} [DESCRIPTION] Markdown content that continues for multiple lines.
107-
*/
108-
module.exports = {
109-
110-
addMore: function( line, last ) {
111-
if ( last ) last.description += "\n" + line;
112-
},
113-
add: function( line, tagData ) {
114-
115-
var noNameData = tnd(line, true),
116-
data = tnd(line),
117-
i,
118-
option,
119-
obj;
120-
121-
if(tagData && this !== tagData) {
122-
var options = getOptions(tagData);
123-
124-
if(options) {
125-
option = getOrMakeOptionByName(options, data.name);
126-
setOptionData(option, data);
127-
return option;
128-
}
113+
add: function (line, tagData) {
114+
var noNameData = tnd(line, true),
115+
data = tnd(line),
116+
i,
117+
option,
118+
obj;
119+
120+
if (tagData && this !== tagData) {
121+
var options = getOptions(tagData);
122+
123+
if (options) {
124+
option = getOrMakeOptionByName(options, data.name);
125+
setOptionData(option, data);
126+
return option;
129127
}
128+
}
130129

131-
132-
// start processing
133-
if(this.type == "typedef" || this.type === "module"){
134-
// Typedef's can have option values, but those values can be objects
135-
// with options.
136-
// So, we should check in options objects first
137-
for( i = 0 ; i < this.types.length; i++ ) {
138-
obj = this.types[i];
139-
if( obj.type == "Object" ) {
140-
option = getOrMakeOptionByName(obj.options || [], data.name);
141-
if(option) {
142-
setOptionData(option, data);
143-
return option;
144-
}
130+
// start processing
131+
if (this.type == "typedef" || this.type === "module") {
132+
// Typedefs can have option values, but those values can be objects
133+
// with options.
134+
// So, we should check in options objects first
135+
for (i = 0; i < this.types.length; i++) {
136+
obj = this.types[i];
137+
if (obj.type == "Object") {
138+
option = getOrMakeOptionByName(obj.options || [], data.name);
139+
if (option) {
140+
setOptionData(option, data);
141+
return option;
145142
}
146143
}
147144
}
145+
}
148146

149-
150-
// we should look to find something matching
151-
var locations = [this._curReturn, this._curParam, (this.params && this.params[this.params.length - 1]), this];
152-
// only process this type of option if there is one value
153-
if(noNameData.types && noNameData.types.length == 1) {
154-
var typeData = noNameData.types[0];
155-
for(i = 0 ; i < locations.length; i++){
156-
obj = locations[i];
157-
if(obj){
158-
if(!obj.types){
159-
obj.types = [];
160-
}
161-
var type = getType(obj.types, typeData.type);
162-
if(type){
163-
// copy description
164-
type.description = noNameData.description;
165-
// copy any additional type info
166-
for(var prop in typeData){
167-
type[prop] = typeData[prop];
168-
}
169-
return type;
147+
// we should look to find something matching
148+
var locations = [this._curReturn, this._curParam, (this.params && this.params[this.params.length - 1]), this];
149+
150+
// only process this type of option if there is one value
151+
if (noNameData.types && noNameData.types.length == 1) {
152+
var typeData = noNameData.types[0];
153+
for (i = 0; i < locations.length; i++) {
154+
obj = locations[i];
155+
if (obj) {
156+
if (!obj.types) {
157+
obj.types = [];
158+
}
159+
var type = getType(obj.types, typeData.type);
160+
if (type) {
161+
// copy description
162+
type.description = noNameData.description;
163+
164+
// copy any additional type info
165+
for (var prop in typeData) {
166+
type[prop] = typeData[prop];
170167
}
168+
169+
return type;
171170
}
172171
}
173172
}
173+
}
174174

175-
var prevParam = this._curReturn || this._curParam || (this.params && this.params[this.params.length - 1]) || this;
175+
var prevParam = this._curReturn || this._curParam || (this.params && this.params[this.params.length - 1]) || this;
176176

177-
if(!data.name){
178-
console.log("LINE: \n" + line + "\n does not match @option [{TYPE}] NAME DESCRIPTION");
179-
}
177+
if (!data.name) {
178+
console.log("LINE: \n" + line + "\n does not match @option [{TYPE}] NAME DESCRIPTION");
179+
}
180180

181-
// try to get a params or options object
182-
var params = getParams(prevParam),
183-
options = getOptions(prevParam);
181+
// try to get a params or options object
182+
var params = getParams(prevParam),
183+
options = getOptions(prevParam);
184184

185-
if(!options && !params){
186-
if(prevParam.types[0]) {
187-
options = (prevParam.types[0].options = []);
188-
} else {
189-
console.log("LINE: \n" + line + "\n could not find an object or arguments to add options to.");
190-
return;
191-
}
185+
if (!options && !params) {
186+
if (prevParam.types[0]) {
187+
options = (prevParam.types[0].options = []);
188+
} else {
189+
console.log("LINE: \n" + line + "\n could not find an object or arguments to add options to.");
190+
return;
192191
}
193-
// get the named one
194-
option = getOrMakeOptionByName(options || params, data.name);
192+
}
195193

196-
// add to it
197-
setOptionData(option, data);
194+
// get the named one
195+
option = getOrMakeOptionByName(options || params, data.name);
198196

199-
return option;
200-
}
201-
};
197+
// add to it
198+
setOptionData(option, data);
199+
200+
return option;
201+
}
202+
};

0 commit comments

Comments
 (0)