mm_eslint 1.1.1 → 1.1.2
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 +21 -15
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -554,8 +554,9 @@ Detector.prototype._checkBadWords = function (name, config, errors) {
|
|
|
554
554
|
type = 'function';
|
|
555
555
|
}
|
|
556
556
|
|
|
557
|
-
|
|
558
|
-
|
|
557
|
+
const bad_word = this._checkBadWord(name, type);
|
|
558
|
+
if (bad_word) {
|
|
559
|
+
errors.push(`${config.name}包含禁止的废话词"${bad_word}"`);
|
|
559
560
|
}
|
|
560
561
|
};
|
|
561
562
|
|
|
@@ -1413,12 +1414,12 @@ Detector.prototype._isConstPat = function (prop_name, value) {
|
|
|
1413
1414
|
* 检查是否包含禁止的废话词(拼接命名检测)
|
|
1414
1415
|
* @param {string} name - 名称
|
|
1415
1416
|
* @param {string} type - 代码实体类型(class/function/variable)
|
|
1416
|
-
* @returns {
|
|
1417
|
+
* @returns {string|null} 检测到的废话词,未检测到返回null
|
|
1417
1418
|
* @private
|
|
1418
1419
|
*/
|
|
1419
|
-
Detector.prototype.
|
|
1420
|
+
Detector.prototype._checkBadWord = function (name, type) {
|
|
1420
1421
|
if (!name || !type) {
|
|
1421
|
-
return
|
|
1422
|
+
return null;
|
|
1422
1423
|
}
|
|
1423
1424
|
|
|
1424
1425
|
const forbidden_words = this.config.forbidden_words[type] || [];
|
|
@@ -1430,33 +1431,38 @@ Detector.prototype._hasBadWord = function (name, type) {
|
|
|
1430
1431
|
|
|
1431
1432
|
// 如果名称是单个单词,不进行废话词检测
|
|
1432
1433
|
if (!this._isCompoundName(name)) {
|
|
1433
|
-
return
|
|
1434
|
+
return null;
|
|
1434
1435
|
}
|
|
1435
1436
|
|
|
1436
1437
|
// 检查名称是否包含废话词作为独立的单词(而不是子字符串)
|
|
1437
|
-
|
|
1438
|
+
for (const word of forbidden_words) {
|
|
1438
1439
|
const wordLower = word.toLowerCase();
|
|
1439
1440
|
|
|
1440
1441
|
// 检查是否作为独立的单词存在
|
|
1441
1442
|
// 1. 作为整个名称(单个单词)
|
|
1442
1443
|
if (nameLower === wordLower) {
|
|
1443
|
-
|
|
1444
|
+
continue; // 单个单词允许使用
|
|
1444
1445
|
}
|
|
1445
1446
|
|
|
1446
1447
|
// 2. 作为复合名称的一部分(以下划线分隔)
|
|
1447
1448
|
if (nameLower.includes('_')) {
|
|
1448
1449
|
const words = nameLower.split('_');
|
|
1449
|
-
|
|
1450
|
+
if (words.includes(wordLower)) {
|
|
1451
|
+
return word;
|
|
1452
|
+
}
|
|
1450
1453
|
}
|
|
1451
1454
|
|
|
1452
|
-
// 3.
|
|
1453
|
-
if (/^[a-z]+([A-Z][a-z]+)+$/.test(name)) {
|
|
1455
|
+
// 3. 作为驼峰命名的一部分(包括小驼峰和大驼峰)
|
|
1456
|
+
if (/^[a-z]+([A-Z][a-z]+)+$/.test(name) || /^[A-Z][a-z]+([A-Z][a-z]+)+$/.test(name)) {
|
|
1454
1457
|
const camelWords = name.replace(/([A-Z])/g, '_$1').toLowerCase().split('_');
|
|
1455
|
-
|
|
1458
|
+
if (camelWords.includes(wordLower)) {
|
|
1459
|
+
// 返回原词,保持大小写格式
|
|
1460
|
+
return word;
|
|
1461
|
+
}
|
|
1456
1462
|
}
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
return null;
|
|
1460
1466
|
};
|
|
1461
1467
|
|
|
1462
1468
|
/**
|