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.
- package/index.js +30 -18
- 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 =
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
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
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
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
|
});
|