dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.13k stars 4.04k forks source link

Treat acronyms/initialisms as words in naming conventions #31908

Open sharwell opened 5 years ago

sharwell commented 5 years ago

Currently, sequences of capital letters are treated as single-letter words during naming convention analysis. For camelCase and PascalCase naming, only the first and last letters of a sequence of capital letters should be treated as the start of a word. The last should only be treated as the start of a word if it is followed by a lowercase letter.

See #26556

Examples:

Name Words To camelCase To PascalCase
DTE DTE dte DTE
UIShellService UI, Shell, Service uiShellService UiShellService
anyCPUPlatformName any, CPU, Platform, Name anyCpuPlatformName AnyCpuPlatformName
DTEEvents DTE, Events dteEvents DteEvents
SERIALIZATION_DESCRIPTION SERIALIZATION, DESCRIPTION serializationDescription SerializationDescription
sharwell commented 5 years ago

🔗 Related to #22745

CyrusNajmabadi commented 5 years ago

UiShellService

Is that correct? I thought with pascal casing the idea was to capitalize hte first letter of each word. Since "UI" is basically two works ("User" and "Interface") it was expected to be UIShellService. I honestly don't know and even looking in my own codebases i can see inconsistency here.

It's also a little odd that when the entire thing is an acronym (i.e. DTE) that hte pascal version it to keep it that way.

Note: this is very minor. It's just tht i realized i have no idea what the right thing is to do here, and we might have some conflicts here with how others see things.

Joe4evr commented 5 years ago

A special case is made for two-letter acronyms in which both letters are capitalized, as shown in the following identifier:

IOStream

So says Capitalization Conventions.

CyrusNajmabadi commented 5 years ago

Following that doc would be nice if possible. Thanks @Joe4evr !