This topic has not yet been rated - Rate this topic

CA2204: Literals should be spelled correctly

TypeName

LiteralsShouldBeSpelledCorrectly

CheckId

CA2204

Category

Microsoft.Usage

Breaking Change

Non Breaking

A method passes a literal string to that is used in a parameter or property that requires a localized string and the literal string contains one or more words that are not recognized by the Microsoft spelling checker library.

This rule checks a literal string that is passed as a value to a parameter or property when one or more of the following cases is true:

  • The LocalizableAttribute attribute of the parameter or property is set to true.

  • The parameter or property name contains "Text", "Message", or "Caption".

  • The name of the string parameter that is passed to a Console.Write or Console.WriteLine method is either "value" or "format".

This rule parses the literal string into words, tokenizing compound words, and checks the spelling of each word/token. For information about the parsing algorithm, see CA1704: Identifiers should be spelled correctly.

By default, the English (en) version of the spelling checker is used.

To fix a violation of this rule, correct the spelling of the word or add the word to a custom dictionary. For information about how to use custom dictionaries, see How to: Customize the Code Analysis Dictionary.

Do not suppress a warning from this rule. Correctly spelled words reduce the learning curve required for new software libraries.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Grammar error in the documentation
A method passes a literal string to [???] that is used

I put the [???] where the grammar error is.
CA1701
The documentation is not correct about the possibility to suppress CA1701 in resource strings. It doesn't work for compound words.
Custom Dictionary Ignored by CA2204

The CA2204 rule ignores words in the custom dictionary.

See the following connect bug:

https://connect.microsoft.com/VisualStudio/feedback/details/521030/?wa=wsignin1.0
Problem with compound words
I am experiencing an issue when I have compound words in my strings.  The compound words I'm using are company terms, so it is not suprising Code Analysis doens't recognize the terms, the compound words however typically are made up of two words that by themselves are correct.

CA2204: Microsoft.Naming: Correct the spelling of the unrecognized token 'CompanyTerm' in the literal '"The CompanyTerm ..."'.

I have attempted to add the words to the custom dictionary that is included in the project.  However doing so does not appear to relieve my problem, it only creates another.  After adding it to the custom dictionary I then have warning stating that I need to correct the casing in member, function, property, and variable names.

CA1702: Microsoft.Naming: The compound word 'CompanyTerm' in type name 'CompanyTermObject' exists as a discrete term.  If your usage is intended to be single word, case it as "Companyterm".