Condividi tramite


CA2204: Literals should be spelled correctly

Item Value
RuleId CA2204
Category Microsoft.Usage
Breaking change Non-breaking

Cause

A literal string is passed as an argument for a localizable parameter, or to a localizable property, and the string contains one or more words that are not recognized by the Microsoft spelling checker library.

Rule description

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 variable that is passed to a Write or 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 or token. For information about the parsing algorithm, see CA1704: Identifiers should be spelled correctly.

Language

The spell checker currently checks only against English-based culture dictionaries. You can change the culture of your project in the project file, by adding the CodeAnalysisCulture element.

For example:

<Project ...>
  <PropertyGroup>
    <CodeAnalysisCulture>en-AU</CodeAnalysisCulture>

Important

If you set the culture to anything other than an English-based culture, this code analysis rule is silently disabled.

How to fix violations

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.

When to suppress warnings

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