mm_eslint 1.2.6 → 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README_EN.md +18 -18
- package/config.js +523 -0
- package/detector.js +998 -0
- package/index.js +268 -2836
- package/package.json +4 -2
- package/README.md +0 -410
package/README_EN.md
CHANGED
|
@@ -256,7 +256,7 @@ The plugin validates that each word in compound names does not exceed 8 characte
|
|
|
256
256
|
|
|
257
257
|
You can customize rule parameters through configuration:
|
|
258
258
|
|
|
259
|
-
|
|
259
|
+
````javascript
|
|
260
260
|
// Custom configuration example
|
|
261
261
|
const customConfig = {
|
|
262
262
|
"class-name": {
|
|
@@ -303,28 +303,28 @@ module.exports = [
|
|
|
303
303
|
},
|
|
304
304
|
},
|
|
305
305
|
];
|
|
306
|
-
|
|
306
|
+
````
|
|
307
307
|
|
|
308
308
|
### Available Recommendations
|
|
309
309
|
|
|
310
310
|
The plugin provides recommendations for common programming operations:
|
|
311
311
|
|
|
312
|
-
| Original Word | Recommended Word | Description
|
|
313
|
-
|
|
314
|
-
| `calculate`
|
|
315
|
-
| `generate`
|
|
316
|
-
| `initialize`
|
|
317
|
-
| `execute`
|
|
318
|
-
| `process`
|
|
319
|
-
| `retrieve`
|
|
320
|
-
| `persist`
|
|
321
|
-
| `compare`
|
|
322
|
-
| `duplicate`
|
|
323
|
-
| `transfer`
|
|
324
|
-
| `convert`
|
|
325
|
-
| `verify`
|
|
326
|
-
| `construct`
|
|
327
|
-
| `handle`
|
|
312
|
+
| Original Word | Recommended Word | Description |
|
|
313
|
+
| ------------- | ---------------- | ------------------------- |
|
|
314
|
+
| `calculate` | `calc` | Mathematical operations |
|
|
315
|
+
| `generate` | `gen` | Data generation |
|
|
316
|
+
| `initialize` | `init` | Initialization operations |
|
|
317
|
+
| `execute` | `exec` | Command execution |
|
|
318
|
+
| `process` | `run` | Data processing |
|
|
319
|
+
| `retrieve` | `load` | Data loading |
|
|
320
|
+
| `persist` | `save` | Data storage |
|
|
321
|
+
| `compare` | `cmp` | Comparison operations |
|
|
322
|
+
| `duplicate` | `copy` | Data copying |
|
|
323
|
+
| `transfer` | `move` | Data movement |
|
|
324
|
+
| `convert` | `to` | Type conversion |
|
|
325
|
+
| `verify` | `check` | Validation checks |
|
|
326
|
+
| `construct` | `create` | Object creation |
|
|
327
|
+
| `handle` | `run` | Event handling |
|
|
328
328
|
|
|
329
329
|
### Examples
|
|
330
330
|
|
package/config.js
ADDED
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 命名规范检测配置类
|
|
3
|
+
*/
|
|
4
|
+
class Config {
|
|
5
|
+
/**
|
|
6
|
+
* 构造函数
|
|
7
|
+
* @param {object} config 配置对象
|
|
8
|
+
*/
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = Object.assign({
|
|
11
|
+
// 忽略词
|
|
12
|
+
ignored_words: {
|
|
13
|
+
'class-name': [],
|
|
14
|
+
'method-name': [],
|
|
15
|
+
'variable-name': [],
|
|
16
|
+
'constant-name': []
|
|
17
|
+
},
|
|
18
|
+
// 禁止词
|
|
19
|
+
forbidden_words: {
|
|
20
|
+
'class-name': [],
|
|
21
|
+
'method-name': [],
|
|
22
|
+
'variable-name': [],
|
|
23
|
+
'constant-name': []
|
|
24
|
+
},
|
|
25
|
+
// 推荐词
|
|
26
|
+
recommended_words: {
|
|
27
|
+
'class-name': {
|
|
28
|
+
},
|
|
29
|
+
'method-name': {
|
|
30
|
+
},
|
|
31
|
+
'variable-name': {
|
|
32
|
+
},
|
|
33
|
+
'constant-name': {
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}, config);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 获取命名风格的正则表达式
|
|
42
|
+
* @param {string} style 命名风格
|
|
43
|
+
* @returns {RegExp} 正则表达式
|
|
44
|
+
*/
|
|
45
|
+
Config.prototype.getRegex = function (style) {
|
|
46
|
+
var regex = {
|
|
47
|
+
PascalCase: /^[A-Z][a-z]*([A-Z][a-z]*)*$/,
|
|
48
|
+
camelCase: /^[a-z][a-z]*([A-Z][a-z]*)*$/,
|
|
49
|
+
snake_case: /^[a-z][a-z0-9]*(_[a-z0-9]+)*$/,
|
|
50
|
+
UPPER_SNAKE_CASE: /^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$/,
|
|
51
|
+
lowercase: /^[a-z][a-z0-9]*$/,
|
|
52
|
+
UPPERCASE: /^[A-Z][A-Z0-9]*$/,
|
|
53
|
+
_camelCase: /^_[a-z][a-z0-9]*([A-Z][a-z0-9]*)*$/,
|
|
54
|
+
_snake_case: /^_[a-z][a-z0-9]*(_[a-z0-9]+)*$/,
|
|
55
|
+
_lowercase: /^_[a-z][a-z0-9]*$/,
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
return regex[style] || null;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 获取命名类型的规则配置
|
|
63
|
+
* @param {string} name_type 命名类型
|
|
64
|
+
* @returns {object} 规则配置对象
|
|
65
|
+
*/
|
|
66
|
+
Config.prototype.getRule = function (name_type) {
|
|
67
|
+
var rule = {
|
|
68
|
+
'class-name': {
|
|
69
|
+
name: '类名',
|
|
70
|
+
message:
|
|
71
|
+
'必须使用大驼峰命名法(PascalCase),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
72
|
+
min: 1,
|
|
73
|
+
max: 20,
|
|
74
|
+
styles: ['PascalCase'],
|
|
75
|
+
single_word: true,
|
|
76
|
+
single_word_len: 8,
|
|
77
|
+
},
|
|
78
|
+
'function-name': {
|
|
79
|
+
name: '函数名',
|
|
80
|
+
message:
|
|
81
|
+
'必须使用小驼峰命名法(camelCase),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
82
|
+
min: 1,
|
|
83
|
+
max: 20,
|
|
84
|
+
styles: ['camelCase'],
|
|
85
|
+
single_word: true,
|
|
86
|
+
single_word_len: 8,
|
|
87
|
+
},
|
|
88
|
+
'method-name': {
|
|
89
|
+
name: '方法名',
|
|
90
|
+
message:
|
|
91
|
+
'必须使用小驼峰命名法(camelCase),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
92
|
+
min: 1,
|
|
93
|
+
max: 20,
|
|
94
|
+
styles: ['camelCase'],
|
|
95
|
+
single_word: true,
|
|
96
|
+
single_word_len: 8
|
|
97
|
+
},
|
|
98
|
+
'variable-name': {
|
|
99
|
+
name: '变量名',
|
|
100
|
+
message:
|
|
101
|
+
'必须使用小写蛇形命名法(snake_case),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
102
|
+
min: 1,
|
|
103
|
+
max: 20,
|
|
104
|
+
styles: ['snake_case'],
|
|
105
|
+
single_word: true,
|
|
106
|
+
single_word_len: 8
|
|
107
|
+
},
|
|
108
|
+
'param-name': {
|
|
109
|
+
name: '参数名',
|
|
110
|
+
message:
|
|
111
|
+
'必须使用小写蛇形命名法(snake_case),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
112
|
+
min: 1,
|
|
113
|
+
max: 20,
|
|
114
|
+
styles: ['snake_case'],
|
|
115
|
+
single_word: true,
|
|
116
|
+
single_word_len: 8
|
|
117
|
+
},
|
|
118
|
+
'constant-name': {
|
|
119
|
+
name: '常量名',
|
|
120
|
+
message:
|
|
121
|
+
'必须使用大写蛇形命名法(UPPER_SNAKE_CASE),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
122
|
+
min: 1,
|
|
123
|
+
max: 20,
|
|
124
|
+
styles: ['UPPER_SNAKE_CASE'],
|
|
125
|
+
single_word: true,
|
|
126
|
+
single_word_len: 8
|
|
127
|
+
},
|
|
128
|
+
'property-class-name': {
|
|
129
|
+
name: '属性类名',
|
|
130
|
+
message:
|
|
131
|
+
'属性类必须使用大驼峰命名法(PascalCase),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
132
|
+
min: 1,
|
|
133
|
+
max: 20,
|
|
134
|
+
styles: ['PascalCase'],
|
|
135
|
+
single_word: true,
|
|
136
|
+
single_word_len: 8
|
|
137
|
+
},
|
|
138
|
+
'property-instance-class-name': {
|
|
139
|
+
name: '属性实例类名',
|
|
140
|
+
message:
|
|
141
|
+
'属性实例类必须使用小驼峰命名法(camelCase),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
142
|
+
min: 1,
|
|
143
|
+
max: 20,
|
|
144
|
+
styles: ['camelCase'],
|
|
145
|
+
single_word: true,
|
|
146
|
+
single_word_len: 8
|
|
147
|
+
},
|
|
148
|
+
'property-method-name': {
|
|
149
|
+
name: '属性方法名',
|
|
150
|
+
message:
|
|
151
|
+
'属性方法必须使用小驼峰命名法(camelCase),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
152
|
+
min: 1,
|
|
153
|
+
max: 20,
|
|
154
|
+
styles: ['camelCase'],
|
|
155
|
+
single_word: true,
|
|
156
|
+
single_word_len: 8
|
|
157
|
+
},
|
|
158
|
+
'property-value-name': {
|
|
159
|
+
name: '属性值名',
|
|
160
|
+
message:
|
|
161
|
+
'属性值必须使用小写蛇形命名法(snake_case),长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
162
|
+
min: 1,
|
|
163
|
+
max: 20,
|
|
164
|
+
styles: ['snake_case'],
|
|
165
|
+
single_word: true,
|
|
166
|
+
single_word_len: 8
|
|
167
|
+
},
|
|
168
|
+
'property-flexible-name': {
|
|
169
|
+
name: '灵活属性名',
|
|
170
|
+
message:
|
|
171
|
+
'灵活属性名支持多种命名风格,长度{min}-{max}字符,且优先使用单个单词,每个单词不超过{word_len}字符',
|
|
172
|
+
min: 1,
|
|
173
|
+
max: 20,
|
|
174
|
+
styles: ['snake_case', 'UPPER_SNAKE_CASE', 'PascalCase', 'camelCase', '_snake_case', '_camelCase'],
|
|
175
|
+
single_word: true,
|
|
176
|
+
single_word_len: 8
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
return rule[name_type] || null;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* 获取命名类型的禁止词列表
|
|
185
|
+
* @param {string} name_type 命名类型
|
|
186
|
+
* @returns {Array} 禁止词列表
|
|
187
|
+
*/
|
|
188
|
+
Config.prototype.getForbiddenWords = function (name_type) {
|
|
189
|
+
name_type = name_type.replace('property-', '').replace('instance-', '');
|
|
190
|
+
if (name_type == 'method-name') {
|
|
191
|
+
name_type = 'method-name';
|
|
192
|
+
}
|
|
193
|
+
var forbidden = {
|
|
194
|
+
'class-name': [
|
|
195
|
+
'manager',
|
|
196
|
+
'handler',
|
|
197
|
+
'processor',
|
|
198
|
+
'controller',
|
|
199
|
+
'service',
|
|
200
|
+
'provider',
|
|
201
|
+
'factory',
|
|
202
|
+
'builder',
|
|
203
|
+
'adapter',
|
|
204
|
+
'decorator',
|
|
205
|
+
'proxy',
|
|
206
|
+
'facade',
|
|
207
|
+
'mediator',
|
|
208
|
+
'observer',
|
|
209
|
+
'strategy',
|
|
210
|
+
'command',
|
|
211
|
+
'visitor',
|
|
212
|
+
'iterator',
|
|
213
|
+
'template',
|
|
214
|
+
'flyweight',
|
|
215
|
+
'memento',
|
|
216
|
+
'interpreter',
|
|
217
|
+
'model',
|
|
218
|
+
'view',
|
|
219
|
+
'route',
|
|
220
|
+
'router',
|
|
221
|
+
'component',
|
|
222
|
+
'widget',
|
|
223
|
+
'panel',
|
|
224
|
+
'dialog',
|
|
225
|
+
'window',
|
|
226
|
+
'form',
|
|
227
|
+
'field',
|
|
228
|
+
'property',
|
|
229
|
+
'entity',
|
|
230
|
+
],
|
|
231
|
+
'method-name': [
|
|
232
|
+
'data',
|
|
233
|
+
'result',
|
|
234
|
+
'output',
|
|
235
|
+
'input',
|
|
236
|
+
'param',
|
|
237
|
+
'params',
|
|
238
|
+
'parameter',
|
|
239
|
+
'parameters',
|
|
240
|
+
'value',
|
|
241
|
+
'values',
|
|
242
|
+
'item',
|
|
243
|
+
'items',
|
|
244
|
+
'process',
|
|
245
|
+
'processor',
|
|
246
|
+
'provider',
|
|
247
|
+
'builder',
|
|
248
|
+
'adapter',
|
|
249
|
+
'decorator',
|
|
250
|
+
'proxy',
|
|
251
|
+
'facade',
|
|
252
|
+
'mediator',
|
|
253
|
+
'observer',
|
|
254
|
+
'strategy',
|
|
255
|
+
'command',
|
|
256
|
+
'visitor',
|
|
257
|
+
'iterator',
|
|
258
|
+
'template',
|
|
259
|
+
'flyweight',
|
|
260
|
+
'memento',
|
|
261
|
+
'interpreter',
|
|
262
|
+
'temp',
|
|
263
|
+
'tmp',
|
|
264
|
+
'temporary',
|
|
265
|
+
'cached',
|
|
266
|
+
'buffered',
|
|
267
|
+
'idx',
|
|
268
|
+
'counter',
|
|
269
|
+
],
|
|
270
|
+
'variable-name': [
|
|
271
|
+
'object',
|
|
272
|
+
'array',
|
|
273
|
+
'map',
|
|
274
|
+
'set',
|
|
275
|
+
'collection',
|
|
276
|
+
'container',
|
|
277
|
+
'instance',
|
|
278
|
+
'data',
|
|
279
|
+
'item',
|
|
280
|
+
'items',
|
|
281
|
+
'element',
|
|
282
|
+
'elements',
|
|
283
|
+
'entry',
|
|
284
|
+
'entries',
|
|
285
|
+
'temp',
|
|
286
|
+
'tmp',
|
|
287
|
+
'temporary',
|
|
288
|
+
'cached',
|
|
289
|
+
'buffer',
|
|
290
|
+
'buffered',
|
|
291
|
+
'input',
|
|
292
|
+
'output',
|
|
293
|
+
'result',
|
|
294
|
+
'destination',
|
|
295
|
+
'index',
|
|
296
|
+
'idx',
|
|
297
|
+
'counter',
|
|
298
|
+
'length',
|
|
299
|
+
'total',
|
|
300
|
+
'sum',
|
|
301
|
+
'pointer',
|
|
302
|
+
'reference',
|
|
303
|
+
'ref',
|
|
304
|
+
'handle',
|
|
305
|
+
'handler',
|
|
306
|
+
'entity',
|
|
307
|
+
'column',
|
|
308
|
+
'property',
|
|
309
|
+
'attribute'
|
|
310
|
+
],
|
|
311
|
+
'constant-name': [
|
|
312
|
+
'manager',
|
|
313
|
+
'handler',
|
|
314
|
+
'processor',
|
|
315
|
+
'controller',
|
|
316
|
+
'service',
|
|
317
|
+
'provider',
|
|
318
|
+
'factory',
|
|
319
|
+
'builder',
|
|
320
|
+
'adapter',
|
|
321
|
+
'decorator',
|
|
322
|
+
'proxy',
|
|
323
|
+
'facade',
|
|
324
|
+
'mediator',
|
|
325
|
+
'observer',
|
|
326
|
+
'strategy',
|
|
327
|
+
'command',
|
|
328
|
+
'visitor',
|
|
329
|
+
'iterator',
|
|
330
|
+
'template',
|
|
331
|
+
'flyweight',
|
|
332
|
+
'memento',
|
|
333
|
+
'interpreter',
|
|
334
|
+
'model',
|
|
335
|
+
'view',
|
|
336
|
+
'route',
|
|
337
|
+
'router',
|
|
338
|
+
'component',
|
|
339
|
+
'widget',
|
|
340
|
+
'panel',
|
|
341
|
+
'dialog',
|
|
342
|
+
'window',
|
|
343
|
+
'form',
|
|
344
|
+
'field',
|
|
345
|
+
'property',
|
|
346
|
+
'entity',
|
|
347
|
+
'data',
|
|
348
|
+
'result',
|
|
349
|
+
'output',
|
|
350
|
+
'input',
|
|
351
|
+
'temp',
|
|
352
|
+
'tmp',
|
|
353
|
+
'temporary',
|
|
354
|
+
'cached',
|
|
355
|
+
'buffer',
|
|
356
|
+
'buffered'
|
|
357
|
+
]
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// 优先返回配置中的禁用词,其次返回硬编码禁用词
|
|
361
|
+
var config = this.config.forbidden_words[name_type];
|
|
362
|
+
var hardcoded = forbidden[name_type];
|
|
363
|
+
|
|
364
|
+
// 如果配置中的禁用词为空数组,则使用硬编码禁用词
|
|
365
|
+
if (config && config.length > 0) {
|
|
366
|
+
return config;
|
|
367
|
+
} else if (hardcoded && hardcoded.length > 0) {
|
|
368
|
+
return hardcoded;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
return [];
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* 获取推荐词映射
|
|
376
|
+
* @param {string} name_type 名称类型
|
|
377
|
+
* @returns {object} 推荐词映射
|
|
378
|
+
*/
|
|
379
|
+
Config.prototype.getRecommendedWords = function (name_type) {
|
|
380
|
+
name_type = name_type.replace('property-', '').replace('instance-', '');
|
|
381
|
+
if (name_type == 'method-name') {
|
|
382
|
+
name_type = 'method-name';
|
|
383
|
+
}
|
|
384
|
+
var recommend = {
|
|
385
|
+
'class-name': {
|
|
386
|
+
'App': ['Application'],
|
|
387
|
+
'Config': ['Configuration'],
|
|
388
|
+
'Env': ['Environment'],
|
|
389
|
+
'Init': ['Initialization'],
|
|
390
|
+
'Auth': ['Authentication'],
|
|
391
|
+
'Authz': ['Authorization'],
|
|
392
|
+
'Valid': ['Validation'],
|
|
393
|
+
'Serializer': ['Serialization'],
|
|
394
|
+
'Deserializer': ['Deserialization'],
|
|
395
|
+
'Transformer': ['Transformation'],
|
|
396
|
+
'Impl': ['Implementation'],
|
|
397
|
+
'Proc': ['Processor'],
|
|
398
|
+
'Dcr': ['Decorator'],
|
|
399
|
+
'Prov': ['Provider'],
|
|
400
|
+
'Facade': ['Facade'],
|
|
401
|
+
'Obs': ['Observer'],
|
|
402
|
+
'Strat': ['Strategy'],
|
|
403
|
+
'Mnt': ['Memento'],
|
|
404
|
+
'Intp': ['Interpreter'],
|
|
405
|
+
'Cmp': ['Component'],
|
|
406
|
+
'Info': ['Information'],
|
|
407
|
+
'Conn': ['Connection'],
|
|
408
|
+
'Ext': ['Extension'],
|
|
409
|
+
'Asst': ['Assistant'],
|
|
410
|
+
'WebSocket': ['Websocket']
|
|
411
|
+
},
|
|
412
|
+
'method-name': {
|
|
413
|
+
'get': ['fetch', 'retrieve', 'obtain', 'query'],
|
|
414
|
+
'set': ['assign', 'setting', 'update'],
|
|
415
|
+
'add': ['append', 'insert'],
|
|
416
|
+
'del': ['delete'],
|
|
417
|
+
'check': ['validate', 'verify'],
|
|
418
|
+
'calc': ['calculate', 'compute', 'evaluate'],
|
|
419
|
+
'init': ['initialize', 'initialization', 'prepare'],
|
|
420
|
+
'calc': ['calculate'],
|
|
421
|
+
'gen': ['generate'],
|
|
422
|
+
'exec': ['execute'],
|
|
423
|
+
'run': ['process', 'handle'],
|
|
424
|
+
'load': ['retrieve'],
|
|
425
|
+
'save': ['persist'],
|
|
426
|
+
'cmp': ['compare'],
|
|
427
|
+
'copy': ['duplicate'],
|
|
428
|
+
'move': ['transfer'],
|
|
429
|
+
'to': ['convert', 'transform', 'transformation'],
|
|
430
|
+
'check': ['verify', 'validate'],
|
|
431
|
+
'create': ['construct'],
|
|
432
|
+
'calc': ['compute', 'calculate'],
|
|
433
|
+
'avg': ['average'],
|
|
434
|
+
'zip': ['compress'],
|
|
435
|
+
'unzip': ['decompress'],
|
|
436
|
+
'App': ['Application'],
|
|
437
|
+
'config': ['configure', 'Configuration'],
|
|
438
|
+
'env': ['Environment'],
|
|
439
|
+
'auth': ['authorize', 'Authentication'],
|
|
440
|
+
'authz': ['Authorization'],
|
|
441
|
+
'valid': ['Validation'],
|
|
442
|
+
'stringify': ['serialize', 'serialization'],
|
|
443
|
+
'parse': ['deserialize', 'deserialization'],
|
|
444
|
+
'impl': ['Implementation'],
|
|
445
|
+
'info': ['Information'],
|
|
446
|
+
'conn': ['Connection']
|
|
447
|
+
},
|
|
448
|
+
'variable-name': {
|
|
449
|
+
'obj': ['object'],
|
|
450
|
+
'arr': ['array'],
|
|
451
|
+
'str': ['string'],
|
|
452
|
+
'num': ['number'],
|
|
453
|
+
'bool': ['boolean'],
|
|
454
|
+
'fn': ['function'],
|
|
455
|
+
'tmp': ['temporary'],
|
|
456
|
+
'def': ['default'],
|
|
457
|
+
'max': ['maximum'],
|
|
458
|
+
'min': ['minimum'],
|
|
459
|
+
'avg': ['average']
|
|
460
|
+
},
|
|
461
|
+
'constant-name': {
|
|
462
|
+
'MAX': ['Maximum'],
|
|
463
|
+
'MIN': ['Minimum'],
|
|
464
|
+
'AVG': ['Average']
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
// 优先返回配置中的推荐词,其次返回硬编码推荐词
|
|
469
|
+
var config = this.config.recommended_words[name_type];
|
|
470
|
+
var hardcoded = recommend[name_type];
|
|
471
|
+
|
|
472
|
+
// 如果配置中的推荐词不为空对象,则使用配置推荐词
|
|
473
|
+
if (config && Object.keys(config).length > 0) {
|
|
474
|
+
return config;
|
|
475
|
+
} else if (hardcoded && Object.keys(hardcoded).length > 0) {
|
|
476
|
+
return hardcoded;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
return {};
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* 获取忽略词列表
|
|
484
|
+
* @param {string} name_type 名称类型
|
|
485
|
+
* @returns {Array} 忽略词列表
|
|
486
|
+
*/
|
|
487
|
+
Config.prototype.getIgnoredWords = function (name_type) {
|
|
488
|
+
if (name_type == 'function-name') {
|
|
489
|
+
name_type = 'method-name';
|
|
490
|
+
}
|
|
491
|
+
var ignore = {
|
|
492
|
+
'class-name': [
|
|
493
|
+
'Middleware', 'Component', 'Controller', 'Repository', 'Interface', 'Transformer', 'Template'
|
|
494
|
+
],
|
|
495
|
+
'method-name': [
|
|
496
|
+
'constructor', 'prototype', 'hasOwnProperty',
|
|
497
|
+
'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString',
|
|
498
|
+
'arguments',
|
|
499
|
+
'Middleware', 'Component', 'Controller', 'Repository', 'Interface', 'Transform', 'Template'
|
|
500
|
+
],
|
|
501
|
+
'variable-name': [
|
|
502
|
+
'i', 'k', 'x', 'y', 'z', 'n', 'm', 'o', 'middleware', 'component', 'controller', 'repository', 'interface', 'transformer', 'template'
|
|
503
|
+
],
|
|
504
|
+
'param-name': [
|
|
505
|
+
'middleware', 'component', 'controller', 'repository', 'interface', 'transformer', 'template'
|
|
506
|
+
]
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
// 优先返回配置中的忽略词,其次返回硬编码忽略词
|
|
510
|
+
var config = this.config.ignored_words[name_type];
|
|
511
|
+
var hardcoded = ignore[name_type];
|
|
512
|
+
|
|
513
|
+
// 如果配置中的忽略词为空数组,则使用硬编码忽略词
|
|
514
|
+
if (config && config.length > 0) {
|
|
515
|
+
return config;
|
|
516
|
+
} else if (hardcoded && hardcoded.length > 0) {
|
|
517
|
+
return hardcoded;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
return [];
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
module.exports = { Config };
|