Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resharper Not Recognizing Acronym in List

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

like image 804
Mark Smith Avatar asked Mar 09 '12 14:03

Mark Smith


3 Answers

In answer to your first question, I guess R# is trying to conform to Microsoft's C# conventions for acronyms:

Capitalization Rules 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.

like image 62
Rich Tebb Avatar answered Nov 06 '22 18:11

Rich Tebb


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.

like image 33
siride Avatar answered Nov 06 '22 19:11

siride


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:

  1. Go to ReSharper > Options > Code Editing > C# > C# Naming Style
  2. Select Local variables, and click Edit.
  3. In the Edit Rule Settings dialog box, what you see by default is one single rule, lowerCamelCase. You could have changed it to another style though.
  4. What you need to do is add another naming rule by clicking Add and set both name prefix (RECD in your case) and style to UpperCamelCase. If you only add the prefix, ReSharper will keep bitching (and giving some funny renaming suggestions) because you also spell "Left" instead of "left".

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.

like image 2
Jura Gorohovsky Avatar answered Nov 06 '22 17:11

Jura Gorohovsky