mm_eslint 1.1.0 → 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.
Files changed (2) hide show
  1. package/index.js +36 -9
  2. 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
- if (this._hasBadWord(name, type)) {
558
- errors.push(`${config.name}包含禁止的废话词`);
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 {boolean} 是否包含禁止词
1417
+ * @returns {string|null} 检测到的废话词,未检测到返回null
1417
1418
  * @private
1418
1419
  */
1419
- Detector.prototype._hasBadWord = function (name, type) {
1420
+ Detector.prototype._checkBadWord = function (name, type) {
1420
1421
  if (!name || !type) {
1421
- return false;
1422
+ return null;
1422
1423
  }
1423
1424
 
1424
1425
  const forbidden_words = this.config.forbidden_words[type] || [];
@@ -1430,12 +1431,38 @@ Detector.prototype._hasBadWord = function (name, type) {
1430
1431
 
1431
1432
  // 如果名称是单个单词,不进行废话词检测
1432
1433
  if (!this._isCompoundName(name)) {
1433
- return false;
1434
+ return null;
1434
1435
  }
1435
1436
 
1436
- return forbidden_words.some((word) =>
1437
- nameLower.includes(word.toLowerCase()),
1438
- );
1437
+ // 检查名称是否包含废话词作为独立的单词(而不是子字符串)
1438
+ for (const word of forbidden_words) {
1439
+ const wordLower = word.toLowerCase();
1440
+
1441
+ // 检查是否作为独立的单词存在
1442
+ // 1. 作为整个名称(单个单词)
1443
+ if (nameLower === wordLower) {
1444
+ continue; // 单个单词允许使用
1445
+ }
1446
+
1447
+ // 2. 作为复合名称的一部分(以下划线分隔)
1448
+ if (nameLower.includes('_')) {
1449
+ const words = nameLower.split('_');
1450
+ if (words.includes(wordLower)) {
1451
+ return word;
1452
+ }
1453
+ }
1454
+
1455
+ // 3. 作为驼峰命名的一部分(包括小驼峰和大驼峰)
1456
+ if (/^[a-z]+([A-Z][a-z]+)+$/.test(name) || /^[A-Z][a-z]+([A-Z][a-z]+)+$/.test(name)) {
1457
+ const camelWords = name.replace(/([A-Z])/g, '_$1').toLowerCase().split('_');
1458
+ if (camelWords.includes(wordLower)) {
1459
+ // 返回原词,保持大小写格式
1460
+ return word;
1461
+ }
1462
+ }
1463
+ }
1464
+
1465
+ return null;
1439
1466
  };
1440
1467
 
1441
1468
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_eslint",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "ESLint plugin for naming conventions - PascalCase, camelCase, snake_case, and UPPER_SNAKE_CASE naming rules",
5
5
  "main": "index.js",
6
6
  "keywords": [