I am trying to clean up warnings R# 6.1 is generating for my classes and one of the issues ReSharper is reporting is that I have incorrect capitalization on a variable. For instance I have var RECDLeft = new RECD();
and it recommends that I change it to var recdLeft = new RECD()
despite it being an acronymn defined in the list. I have manually added the RECD acronym to the list of acronyms because it wasn't asking me to add it in the quick fix menu. I have noticed that if I call the variable `var aRECDLeft' it recognizes the acronym properly. Is there a reason acronyms are not recognized at the beginning of a variable name? And is there a way to make R# recognize this usage besides moving the acronym to the second word?
Thanks, Mark Smith
In answer to your first question, I guess R# is trying to conform to Microsoft's C# conventions for acronyms:
Do capitalize both characters of two-character acronyms, except the first word of a camel-cased identifier.
A property named DBRate
is an example of a short acronym (DB) used as the first word of a Pascal-cased identifier. A parameter named ioChannel
is an example of a short acronym (IO) used as the first word of a camel-cased identifier.
Do capitalize only the first character of acronyms with three or more characters, except the first word of a camel-cased identifier.
A class named XmlWriter
is an example of a long acronym used as the first word of a Pascal-cased identifier. A parameter named htmlReader
is an example of a long acronym used as the first word of a camel-cased identifier.
Do not capitalize any of the characters of any acronyms, whatever their length, at the beginning of a camel-cased identifier.
A parameter named xmlStream
is an example of a long acronym (xml) used as the first word of a camel-cased identifier. A parameter named dbServerName
is an example of a short acronym (db) used as the first word of a camel-cased identifier.
I'm guessing the problem is that although the acronym is added, you are still violating the rule that variable names start with lowercase. You'd need to add a special rule for variable names that allows them to begin with that acronym. This is not the same as adding an acronym to the list.
As siride correctly points out, this is a special naming case that requires introducing a special naming rule for local variables that would be checked in addition to your default rule. Here's what you should do:
If you have other similar abbreviations, you should add an additional local var naming rule for each of them (the entire list of known abbreviations is available at C# Naming Style > Advanced settings > Abbreviations as plain text.) This is not very handy to do but it's not that you have a simple naming standard either )
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With