mm_eslint 1.1.5 → 1.1.7
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 +79 -10
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -189,6 +189,25 @@ class Detector {
|
|
|
189
189
|
'setup', 'init', 'internal', 'private', 'helper', 'util'
|
|
190
190
|
],
|
|
191
191
|
|
|
192
|
+
// 忽略词列表:这些词汇在命名检测时会被忽略,不进行长度和风格检测
|
|
193
|
+
ignore_words: {
|
|
194
|
+
// 类名忽略词:这些词汇在类名中允许使用,即使超过8个字符
|
|
195
|
+
class: [
|
|
196
|
+
"Controller", "Middleware", "Component", "Repository", "Validator",
|
|
197
|
+
"Transformer", "Serializer", "Interceptor", "Decorator", "Provider"
|
|
198
|
+
],
|
|
199
|
+
// 方法名忽略词:这些词汇在方法名中允许使用,即使超过8个字符
|
|
200
|
+
method: [
|
|
201
|
+
"middleware", "controller", "component", "repository", "validator",
|
|
202
|
+
"transformer", "serializer", "interceptor", "decorator", "provider"
|
|
203
|
+
],
|
|
204
|
+
// 函数名忽略词:这些词汇在函数名中允许使用,即使超过8个字符
|
|
205
|
+
function: [
|
|
206
|
+
"middleware", "controller", "component", "repository", "validator",
|
|
207
|
+
"transformer", "serializer", "interceptor", "decorator", "provider"
|
|
208
|
+
]
|
|
209
|
+
},
|
|
210
|
+
|
|
192
211
|
// 废话词
|
|
193
212
|
forbidden_words: {
|
|
194
213
|
// 类废话词:禁止在类名中使用的冗余拼接词汇(统一小写)
|
|
@@ -482,6 +501,16 @@ Detector.prototype._checkName = function (rule_type, name) {
|
|
|
482
501
|
const warnings = [];
|
|
483
502
|
const recommendations = [];
|
|
484
503
|
|
|
504
|
+
// 首先检查是否为忽略词,如果是则跳过其他检测
|
|
505
|
+
if (this._isIgnoreWord(name, rule_type)) {
|
|
506
|
+
return {
|
|
507
|
+
valid: true,
|
|
508
|
+
errors: [],
|
|
509
|
+
warnings: [],
|
|
510
|
+
recommendations: []
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
|
|
485
514
|
this._checkNameLength(name, config, errors);
|
|
486
515
|
this._checkNameFormat(name, rule_type, config, errors);
|
|
487
516
|
this._checkBadWords(name, config, errors);
|
|
@@ -1504,6 +1533,44 @@ Detector.prototype._isCompoundName = function (name) {
|
|
|
1504
1533
|
return false;
|
|
1505
1534
|
};
|
|
1506
1535
|
|
|
1536
|
+
/**
|
|
1537
|
+
* 检查是否为忽略词
|
|
1538
|
+
* @param {string} name - 名称
|
|
1539
|
+
* @param {string} rule_type - 规则类型
|
|
1540
|
+
* @returns {boolean} 是否为忽略词
|
|
1541
|
+
* @private
|
|
1542
|
+
*/
|
|
1543
|
+
Detector.prototype._isIgnoreWord = function (name, rule_type) {
|
|
1544
|
+
// 获取忽略词配置
|
|
1545
|
+
const ignore_words_config = this.config.ignore_words;
|
|
1546
|
+
if (!ignore_words_config) {
|
|
1547
|
+
return false;
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
// 根据规则类型获取对应的忽略词列表
|
|
1551
|
+
let ignore_list = [];
|
|
1552
|
+
if (rule_type === "class-name") {
|
|
1553
|
+
ignore_list = ignore_words_config.class || [];
|
|
1554
|
+
} else if (rule_type === "method-name") {
|
|
1555
|
+
ignore_list = ignore_words_config.method || [];
|
|
1556
|
+
} else if (rule_type === "function-name") {
|
|
1557
|
+
ignore_list = ignore_words_config.function || [];
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
// 检查名称是否完全匹配忽略词列表中的任何一个词
|
|
1561
|
+
// 支持精确匹配和包含匹配(如果名称包含忽略词,则整个名称都被忽略)
|
|
1562
|
+
// 支持大小写不敏感匹配
|
|
1563
|
+
const name_lower = name.toLowerCase();
|
|
1564
|
+
for (const ignore_word of ignore_list) {
|
|
1565
|
+
const ignore_word_lower = ignore_word.toLowerCase();
|
|
1566
|
+
if (name_lower === ignore_word_lower || name_lower.includes(ignore_word_lower)) {
|
|
1567
|
+
return true;
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
return false;
|
|
1572
|
+
};
|
|
1573
|
+
|
|
1507
1574
|
/**
|
|
1508
1575
|
* 检查推荐词并生成推荐建议
|
|
1509
1576
|
* @param {string} name - 名称
|
|
@@ -2087,18 +2154,20 @@ const constant_name_rule = {
|
|
|
2087
2154
|
return {
|
|
2088
2155
|
VariableDeclarator(node) {
|
|
2089
2156
|
if (node.id.type === "Identifier" && node.parent.kind === "const") {
|
|
2090
|
-
//
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2157
|
+
// 只对真正的常量应用常量命名规则
|
|
2158
|
+
if (isRealConstant(node)) {
|
|
2159
|
+
const constant_name = node.id.name;
|
|
2160
|
+
const detector = new Detector({ "constant-name": options });
|
|
2161
|
+
const result = detector.checkName(constant_name, "constant-name");
|
|
2094
2162
|
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2163
|
+
if (!result.valid) {
|
|
2164
|
+
result.errors.forEach((error) => {
|
|
2165
|
+
context.report({
|
|
2166
|
+
node: node.id,
|
|
2167
|
+
message: `常量名"${constant_name}"不符合规范: ${error}`,
|
|
2168
|
+
});
|
|
2100
2169
|
});
|
|
2101
|
-
}
|
|
2170
|
+
}
|
|
2102
2171
|
}
|
|
2103
2172
|
}
|
|
2104
2173
|
},
|