Skip to content

Commit 836414c

Browse files
committed
缩写
1 parent 9683298 commit 836414c

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

Common/AcronymConstants.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ public static class AcronymConstants
1010
{
1111
public static readonly HashSet<string> CommonAcronyms = new(StringComparer.OrdinalIgnoreCase)
1212
{
13-
"ID", "NPC", "API", "URL", "HTTP", "HTTPS", "JSON", "XML", "SQL", "UI", "DB",
13+
"ID", "NPC", "API", "URL", "XML", "SQL", "UI", "DB",
1414
"CPU", "GPU", "RAM", "ROM", "USB", "DVD", "CD", "HD", "SSD", "HDD",
15-
"HTML", "CSS", "JS", "TS", "PHP", "ASP", "JSP", "CGI", "FTP", "SSH",
16-
"TCP", "UDP", "IP", "DNS", "DHCP", "VPN", "LAN", "WAN", "WIFI", "GPS",
15+
"CSS", "JS", "TS", "PHP", "ASP", "JSP", "CGI", "FTP", "SSH",
16+
"TCP", "UDP", "IP", "DNS", "VPN", "GPS",
1717
"AI", "ML", "DL", "CNN", "RNN", "GAN", "NLP", "OCR", "AR", "VR",
18-
"OS", "SDK", "IDE", "CLI", "GUI", "REST", "SOAP", "JWT", "OAuth", "CORS",
19-
"CRUD", "MVC", "MVP", "MVVM", "OOP", "AOP", "DI", "IoC", "ORM", "DAO",
20-
"DTO", "VO", "POJO", "POCO", "UUID", "GUID", "MD5", "SHA", "AES", "RSA"
18+
"OS", "SDK", "IDE", "CLI", "GUI", "JWT",
19+
"MVC", "MVP", "OOP", "AOP", "DI", "ORM", "DAO",
20+
"DTO", "VO", "MD5", "SHA", "AES", "RSA"
2121
};
2222
}

Rules/Naming/AcronymCasingConsistencyAnalyzer.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,13 @@ private void AnalyzeName(SyntaxNodeAnalysisContext context, string name, Locatio
137137

138138
foreach (var acronym in AcronymConstants.CommonAcronyms)
139139
{
140-
// 使用正则表达式查找缩写,确保它是完整的单词边界
141-
var pattern = $@"\b{Regex.Escape(acronym)}\b";
140+
// 使用更智能的正则表达式来匹配驼峰命名中的缩写
141+
// 匹配以下情况:
142+
// 1. 字符串开头的缩写:^Id, ^API
143+
// 2. 小写字母后的缩写(驼峰命名):iconId, httpAPI
144+
// 3. 大写字母后的缩写:HttpAPI, XMLHttpRequest
145+
// 4. 传统单词边界:some_id, some-api
146+
var pattern = $@"(?:^|(?<=[a-z])|(?<=[A-Z])|(?<=\b)){Regex.Escape(acronym)}(?=\b|(?=[A-Z])|(?=[a-z])|$)";
142147
var matches = Regex.Matches(name, pattern, RegexOptions.IgnoreCase);
143148

144149
foreach (Match match in matches)

0 commit comments

Comments
 (0)