-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.flutterdocblocker.js
273 lines (233 loc) · 8.14 KB
/
.flutterdocblocker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/**
* Program description.
* Copyright (C) 2018. Drew Gauderman
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const namedRegexp = require("named-js-regexp") //vscode doesnt support es2018 regex groups!! WTH!!!!!!!!!!
//author tag group
const author = [
'{%- for auth in authors %}',
'{%- if (author.name|trim) == (auth.name|trim) %}{% set add_author = false %}{% endif %}',
'/// [@author {{ auth.name|trim }}]',
'{%- endfor %}',
'{%- if add_author == true %}',
'/// [@author {{author.name|trim}}]',
'{%- endif %}',
]
//since tag group
const since = [
'{%- if since %}',
'/// [ @since v{{ since | join("", "version") | trim }} ]',
'{%- else %}',
'/// [ @since v{{version}} ]',
'{%- endif %}',
];
//version tag group
const version = [
'{%- set major = 1 %}',
'{%- set minor = 0 %}',
'{%- set patch = -1 %}',
'{%- for version in versions %}',
'{%- set major = version.major %}',
'{%- set minor = version.minor %}',
'{%- set patch = version.patch %}',
'/// [@version v{{major}}.{{minor}}.{{patch}} {{ version.date|trim }}]',
'{%- endfor %}',
'{%- if not started_within_block %}',
'/// [@version v{{major}}.{{minor}}.{{(patch|int)+1}} {{ now | date_format("dddd, mmmm dS, yyyy") }}]',
'{%- endif %}'
]
//global tag group
const global = [
'{%- if spaces == 0 %}',
'/// [@global]',
'{%- endif %}',
]
//description tag group
const description = [
'{%- for description in descriptions %}',
'/// [{{ description.text | trim }}]',
'{%- endfor %}',
'///',
]
//todo tag group
const todo = [
'{%- for todo in todos %}',
'///[ @todo {{todo.text|trim}}]',
'{%- endfor %}',
]
//stuff to expose
module.exports = {
//existing params to check for when updating existing docblock
params: [{
name: 'versions',
regex: namedRegexp(/(?:@version)\tv(:<major>[\d]+).(:<minor>[\d]+).(:<patch>[\d]+)\t(:<date>[\w\s,]+)$/gmi)
}, {
name: 'authors',
regex: namedRegexp(/(?:@author)\t(:<name>[\w\s<>@.]+)$/gmi)
}, {
name: 'since',
regex: namedRegexp(/(?:@since)\tv(:<version>[\w.]+)/gm)
}, {
name: 'descriptions',
regex: namedRegexp(/\*\s(:<text>[\\/\$&\->\w\s.:'"\[\]{}\(\)]+)$/gmi)
}, {
name: 'todos',
regex: namedRegexp(/(?:@todo)[\t\s]+(:<text>[\\/\$&\->\w\s.:'"\[\]{}\(\)]+)/gmi)
}, {
name: 'returns',
regex: namedRegexp(/(?:@return)[\t\s]+(:<text>[\\/\$&\->\w\s.:'"\[\]{}\(\)]+)/gmi)
},{
name: 'previous_vars',
regex: namedRegexp(/@var[\s]+(:<type>[\w]+)[\s]+(:<name>[$&.\->\w]+)(?:[\s]+(:<description>[\\/\$&\->\w\s.:'"\[\]{}\(\)]+)$)?/gm)
},{
name: 'previous_params',
regex: namedRegexp(/@param[\s]+(:<type>[\w]+)[\s]+(:<name>[$&.\->\w]+)(?:[\s]+(:<description>[\\/\$&\->\w\s.:'"\[\]{}\(\)]+)$)?/gm)
}],
//what to look out for when checking the code, and the template to use to spit back out
checkers: [{
name: 'classes',
regex: namedRegexp(/(?:^|\t|\s)(?:(?:return )?new )?class[\s]?(:<name>[\w]+)?(?:[\(](:<args_full>[\$\-\>.\s\w,\[\]'"]+)[\)])?(?:\sextends\s(:<extends>[\w]+))?/gi),
template: [{
name: 'args',
against: 'args_full',
regex: namedRegexp(/(:<value>[']{0,1}[$\w\s.]+[']{0,1})(?:[,\s]+|$)/g)
},
'{%- for class in classes -%}',
'///',
'{%- if descriptions %}',
...description,
'{%- else %}',
'/// [{{class.name | default("anonymouse class")}}{% if selected_text %}: {{selected_text|trim}}{% endif %}.]',
'///',
'{%- endif %}',
'{%- set add_author = true %}',
...author,
...since,
...version,
'{%- if class.extends %}',
'/// [@see {{class.extends}}]',
'{%- endif %}',
'{%- for arg in class.args %}',
'/// [@param {{ "" | get_data_type(arg.value) | lower }}{% for p in previous_params %}{% if p.description and (p.name|trim) == (arg.name|trim) %}\t{{ p.description }}{% endif %}{% endfor %}]',
'{%- endfor %}',
...global,
...todo,
'///',
'{%- endfor -%}'
]
}, {
name: 'vars',
//https://regex101.com/r/9wQynL/1/
regex: namedRegexp(/(?:^|\t|\s|;)(?:(:<declaration>const|let|var)\s)?(?:(:<scope>public|private|static|protected)\s)?(?:(:<type>[\w]+?)\s)?(:<name>[\$\-\>\w\.]+)[\s]?(:<seperator>[=]+)?[\s]?(:<value>[$\[\]{}\d\w\s\.,'"\/:?]+)?(?:;|,|$)/gi),
template: [
'{%- if not functions and not classes and not copyright -%}',
'{%- for var in vars -%}',
'///',
'{%- if descriptions %}',
...description,
'{%- else %}',
'{%- if selected_text %}',
'/// [{{selected_text}}]',
'///',
'{%- endif %}',
'{%- endif %}',
'{%- set add_author = false %}',
...author,
'{%- if var.scope %}',
...since,
'{%- endif %}',
'{%- set name = var.name | trim %}',
'{%- for p in previous_vars %}',
'{%- if p.description and (p.name|trim) == name %}',
'{%- set name = name + "\t" + p.description %}',
'{%- endif %}',
'{%- endfor %}',
'/// [@var {{ var.type | get_data_type(var.value) | lower}} {{name | trim}}]',
'{%- if var.scope %}',
'/// [@access {{var.scope}}]',
'{%- endif %}',
...global,
...todo,
'///',
'{%- endfor -%}',
'{%- endif -%}'
]
}, {
name: 'functions',
regex: namedRegexp(/(?:(:<scope>[\w]+)\s)?[\s;]?function (:<name>.+)\((:<args_full>.+)?\)/gi),
template: [{
name: 'args',
against: 'args_full',
//regex: namedRegexp(/(:<name>[$\->\w\.?]+)(:<seperator>[\s=]+)?(:<value>[\w{}'"\.,\[\]]+)?(?:,|$|;)/gi)
//regex: namedRegexp(/(:<type>[\w]+[\s])?(:<name>[\&\$\-\>\w\.]+)(?: = (:<value>(?:['"\[\{]?)(?:[\w\s'",=.:]+)?(?:['"\]\}]?)))?(?:,|$)/g)
regex: namedRegexp(/(?:(:<type>[\w]+)[\s])?(:<name>[$\w->]+)([\s=]+(:<value>[->\w\s.'":\[\]{}]+))?(?:,|$)/g)
},
'{%- for function in functions -%}',
'///',
'{%- if descriptions %}',
...description,
'{%- else %}',
'/// [{{function.name}}{% if selected_text %}: {{selected_text|trim}}{% endif %}]',
'///',
'{%- endif %}',
'{%- set add_author = true %}',
...author,
...since,
...version,
'{%- if function.scope %}',
'/// [@access {{function.scope | trim}}]',
'{%- endif %}',
...global,
'{%- set name_max_length = 0 %}',
'{%- for arg in function.args %}',
'{%- set arg_name = (arg.name) %}',
'{%- if (arg_name | length) > name_max_length %}',
'{%- set name_max_length = (arg_name | length) %}',
'{%- endif %}',
'{%- endfor -%}',
'{%- set type_max_length = 0 %}',
'{%- for arg in function.args %}',
'{%- set arg_type = (arg.type | get_data_type(arg.value) | lower) %}',
'{%- if (arg_type | length) > type_max_length %}',
'{%- set type_max_length = (arg_type | length) %}',
'{%- endif %}',
'{%- endfor -%}',
'{%- for arg in function.args %}', //start args
'{%- set arg_type = (arg.type | get_data_type(arg.value) | lower | make_length(type_max_length)) %}',
'{%- set arg_name = (arg.name | make_length(name_max_length)) %}',
'{%- set arg_desc = "" %}',
'{%- if arg.value or (not arg.value and arg.seperator) %}',
'{%- set arg_desc = "Optional." %}',
'{%- endif %}',
'{%- if arg.value %}',
'{%- set arg_desc = arg_desc + " Default: " + arg.value %}',
'{%- endif %}',
'{%- for p in previous_params %}',
'{%- if p.description and (p.name|trim) == (arg.name|trim) %}',
'{%- set arg_desc = p.description %}',
'{%- endif %}',
'{%- endfor %}',
'/// [@param {{ arg_type }}\t{{arg_name }}\t{{ arg_desc | trim }}]',
'{%- endfor %}', //end args
'{%- for return in returns %}',
'/// [@return {{return.text|trim}}]',
'{%- endfor %}',
'{%- if not returns %}',
'/// [@return void]',
'{%- endif %}',
...todo,
'///',
'{%- endfor -%}'
]
}],
};