mm_eslint 1.1.7 → 1.1.9
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/index.js +77 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -205,6 +205,10 @@ class Detector {
|
|
|
205
205
|
function: [
|
|
206
206
|
"middleware", "controller", "component", "repository", "validator",
|
|
207
207
|
"transformer", "serializer", "interceptor", "decorator", "provider"
|
|
208
|
+
],
|
|
209
|
+
variable: [
|
|
210
|
+
"middleware", "controller", "component", "repository", "validator",
|
|
211
|
+
"transformer", "serializer", "interceptor", "decorator", "provider"
|
|
208
212
|
]
|
|
209
213
|
},
|
|
210
214
|
|
|
@@ -230,8 +234,8 @@ class Detector {
|
|
|
230
234
|
"data", "result", "output", "input", "param", "params", "parameter", "parameters",
|
|
231
235
|
"value", "values", "item", "items",
|
|
232
236
|
// 通用处理词汇(动词已经表达了处理,这些名词是冗余的)
|
|
233
|
-
"process", "
|
|
234
|
-
"
|
|
237
|
+
"process", "processor", "provider",
|
|
238
|
+
"builder", "adapter", "decorator", "proxy", "facade", "mediator",
|
|
235
239
|
"observer", "strategy", "command", "visitor", "iterator", "template",
|
|
236
240
|
"flyweight", "memento", "interpreter",
|
|
237
241
|
// 临时缓存词汇(动词已经表达了操作,这些名词是冗余的)
|
|
@@ -407,7 +411,7 @@ class Detector {
|
|
|
407
411
|
Object.keys(config).forEach((key) => {
|
|
408
412
|
if (merged_cfg[key] && typeof merged_cfg[key] === "object" && !Array.isArray(merged_cfg[key])) {
|
|
409
413
|
// 如果是对象配置(如规则配置),则深度合并
|
|
410
|
-
merged_cfg[key] =
|
|
414
|
+
merged_cfg[key] = this._deepMerge(merged_cfg[key], config[key]);
|
|
411
415
|
|
|
412
416
|
// 处理字符串形式的正则表达式
|
|
413
417
|
if (typeof merged_cfg[key].regex === "string") {
|
|
@@ -438,6 +442,37 @@ class Detector {
|
|
|
438
442
|
this.config = merged_cfg;
|
|
439
443
|
this._initRule();
|
|
440
444
|
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* 深度合并两个对象
|
|
448
|
+
* @param {Object} target 目标对象
|
|
449
|
+
* @param {Object} source 源对象
|
|
450
|
+
* @returns {Object} 合并后的对象
|
|
451
|
+
* @private
|
|
452
|
+
*/
|
|
453
|
+
_deepMerge(target, source) {
|
|
454
|
+
const result = { ...target };
|
|
455
|
+
|
|
456
|
+
Object.keys(source).forEach((key) => {
|
|
457
|
+
const source_val = source[key];
|
|
458
|
+
const target_val = target[key];
|
|
459
|
+
|
|
460
|
+
if (Array.isArray(source_val) && Array.isArray(target_val)) {
|
|
461
|
+
// 如果是数组,则合并数组(去重)
|
|
462
|
+
result[key] = [...new Set([...target_val, ...source_val])];
|
|
463
|
+
} else if (typeof source_val === 'object' && source_val !== null &&
|
|
464
|
+
typeof target_val === 'object' && target_val !== null &&
|
|
465
|
+
!Array.isArray(source_val) && !Array.isArray(target_val)) {
|
|
466
|
+
// 如果是对象,则递归深度合并
|
|
467
|
+
result[key] = this._deepMerge(target_val, source_val);
|
|
468
|
+
} else {
|
|
469
|
+
// 其他情况直接覆盖
|
|
470
|
+
result[key] = source_val;
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
return result;
|
|
475
|
+
}
|
|
441
476
|
}
|
|
442
477
|
|
|
443
478
|
/**
|
|
@@ -1555,6 +1590,8 @@ Detector.prototype._isIgnoreWord = function (name, rule_type) {
|
|
|
1555
1590
|
ignore_list = ignore_words_config.method || [];
|
|
1556
1591
|
} else if (rule_type === "function-name") {
|
|
1557
1592
|
ignore_list = ignore_words_config.function || [];
|
|
1593
|
+
} else if (rule_type === "variable-name") {
|
|
1594
|
+
ignore_list = ignore_words_config.variable || [];
|
|
1558
1595
|
}
|
|
1559
1596
|
|
|
1560
1597
|
// 检查名称是否完全匹配忽略词列表中的任何一个词
|
|
@@ -1727,6 +1764,15 @@ const class_name_rule = {
|
|
|
1727
1764
|
single_word: { type: "boolean" },
|
|
1728
1765
|
single_word_len: { type: "number" },
|
|
1729
1766
|
styles: { type: "array", items: { type: "string" } },
|
|
1767
|
+
ignore_words: {
|
|
1768
|
+
type: "object",
|
|
1769
|
+
properties: {
|
|
1770
|
+
class: { type: "array", items: { type: "string" } },
|
|
1771
|
+
method: { type: "array", items: { type: "string" } },
|
|
1772
|
+
function: { type: "array", items: { type: "string" } }
|
|
1773
|
+
},
|
|
1774
|
+
additionalProperties: false
|
|
1775
|
+
}
|
|
1730
1776
|
},
|
|
1731
1777
|
additionalProperties: false,
|
|
1732
1778
|
},
|
|
@@ -1775,6 +1821,15 @@ const function_name_rule = {
|
|
|
1775
1821
|
single_word: { type: "boolean" },
|
|
1776
1822
|
single_word_len: { type: "number" },
|
|
1777
1823
|
styles: { type: "array", items: { type: "string" } },
|
|
1824
|
+
ignore_words: {
|
|
1825
|
+
type: "object",
|
|
1826
|
+
properties: {
|
|
1827
|
+
class: { type: "array", items: { type: "string" } },
|
|
1828
|
+
method: { type: "array", items: { type: "string" } },
|
|
1829
|
+
function: { type: "array", items: { type: "string" } }
|
|
1830
|
+
},
|
|
1831
|
+
additionalProperties: false
|
|
1832
|
+
}
|
|
1778
1833
|
},
|
|
1779
1834
|
additionalProperties: false,
|
|
1780
1835
|
},
|
|
@@ -1842,6 +1897,15 @@ const method_name_rule = {
|
|
|
1842
1897
|
single_word: { type: "boolean" },
|
|
1843
1898
|
single_word_len: { type: "number" },
|
|
1844
1899
|
styles: { type: "array", items: { type: "string" } },
|
|
1900
|
+
ignore_words: {
|
|
1901
|
+
type: "object",
|
|
1902
|
+
properties: {
|
|
1903
|
+
class: { type: "array", items: { type: "string" } },
|
|
1904
|
+
method: { type: "array", items: { type: "string" } },
|
|
1905
|
+
function: { type: "array", items: { type: "string" } }
|
|
1906
|
+
},
|
|
1907
|
+
additionalProperties: false
|
|
1908
|
+
}
|
|
1845
1909
|
},
|
|
1846
1910
|
additionalProperties: false,
|
|
1847
1911
|
},
|
|
@@ -1926,6 +1990,13 @@ const variable_name_rule = {
|
|
|
1926
1990
|
single_word: { type: "boolean" },
|
|
1927
1991
|
single_word_len: { type: "number" },
|
|
1928
1992
|
styles: { type: "array", items: { type: "string" } },
|
|
1993
|
+
ignore_words: {
|
|
1994
|
+
type: "object",
|
|
1995
|
+
properties: {
|
|
1996
|
+
variable: { type: "array", items: { type: "string" } }
|
|
1997
|
+
},
|
|
1998
|
+
additionalProperties: false
|
|
1999
|
+
}
|
|
1929
2000
|
},
|
|
1930
2001
|
additionalProperties: false,
|
|
1931
2002
|
},
|
|
@@ -2534,9 +2605,9 @@ const instance_property_rule = {
|
|
|
2534
2605
|
!node.left.property.name.startsWith("_")
|
|
2535
2606
|
) {
|
|
2536
2607
|
const prop_name = node.left.property.name;
|
|
2537
|
-
//
|
|
2538
|
-
const detector = new Detector({ "
|
|
2539
|
-
const result = detector.checkName(prop_name, "
|
|
2608
|
+
// 实例属性应该符合变量命名规范(小写蛇形)
|
|
2609
|
+
const detector = new Detector({ "variable-name": options });
|
|
2610
|
+
const result = detector.checkName(prop_name, "variable-name");
|
|
2540
2611
|
|
|
2541
2612
|
if (!result.valid) {
|
|
2542
2613
|
result.errors.forEach((error) => {
|