mm_eslint 1.2.4 → 1.2.5

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 +30 -18
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1793,27 +1793,39 @@ Detector.prototype._checkRecommen = function (name, rule_type, config, recommend
1793
1793
 
1794
1794
  if (should_recommend) {
1795
1795
  // 生成推荐建议:将目标词替换为推荐类别词
1796
- const suggestions = category_words.map((word) => {
1797
- // 智能替换:保持原始大小写格式
1798
- const regex = new RegExp(word, 'gi');
1799
- return name.replace(regex, (match) => {
1800
- // 保持原始大小写格式
1801
- if (match === match.toUpperCase()) {
1802
- return category.toUpperCase();
1803
- } else if (match[0] === match[0].toUpperCase()) {
1804
- return category[0].toUpperCase() + category.slice(1);
1805
- } else {
1806
- return category;
1796
+ const suggestions = [];
1797
+
1798
+ // 为每个检测到的目标词生成一个推荐
1799
+ words.forEach((word) => {
1800
+ if (category_words.includes(word)) {
1801
+ // 只生成使用类别词替换的推荐,不包含原始词
1802
+ const regex = new RegExp(word, 'gi');
1803
+ const suggestion = name.replace(regex, (match) => {
1804
+ // 保持原始大小写格式
1805
+ if (match === match.toUpperCase()) {
1806
+ return category.toUpperCase();
1807
+ } else if (match[0] === match[0].toUpperCase()) {
1808
+ return category[0].toUpperCase() + category.slice(1);
1809
+ } else {
1810
+ return category;
1811
+ }
1812
+ });
1813
+
1814
+ // 只有当推荐结果与原始名称不同时才添加
1815
+ if (suggestion !== name) {
1816
+ suggestions.push(suggestion);
1807
1817
  }
1808
- });
1818
+ }
1809
1819
  });
1810
1820
 
1811
- recommendations.push({
1812
- original: name,
1813
- category: category,
1814
- suggestions: suggestions,
1815
- message: `检测到"${category_words.join('、')}",推荐使用: ${suggestions.join(', ')}`
1816
- });
1821
+ if (suggestions.length > 0) {
1822
+ recommendations.push({
1823
+ original: name,
1824
+ category: category,
1825
+ suggestions: suggestions,
1826
+ message: `检测到"${category_words.join('、')}",推荐使用: ${suggestions.join(', ')}`
1827
+ });
1828
+ }
1817
1829
  }
1818
1830
  }
1819
1831
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_eslint",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
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": [