Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port FxCop rule CA2204: LiteralsShouldBeSpelledCorrectly #529

Open
ghost opened this issue Nov 21, 2015 · 4 comments
Open

Port FxCop rule CA2204: LiteralsShouldBeSpelledCorrectly #529

ghost opened this issue Nov 21, 2015 · 4 comments

Comments

@ghost
Copy link

ghost commented Nov 21, 2015

Title: Literals should be spelled correctly

Description:

A literal string in a method body contains one or more words that are not recognized by the Microsoft spelling checker library.

Dependency: Dataflow

Notes:

@mavasani
Copy link
Contributor

This rule uses StringContent dataflow analysis and should be implementable once we merge #1541

@mavasani mavasani modified the milestones: Unknown, 15.6 Jan 20, 2018
@mavasani
Copy link
Contributor

#1541 is merged.

@mavasani
Copy link
Contributor

This rule is blocked by absence of Naming service.

@jinujoseph jinujoseph modified the milestones: 15.7, 15.8 Apr 25, 2018
@daiplusplus
Copy link

daiplusplus commented Nov 7, 2018

I'd like to draw attention to a bug in the current (pre-Roslyn) CA2204 rule where compound-words in literals are flagged by the rule because it doesn't break the compound-words up despite documentation claiming otherwise ("This rule parses the literal string into words, tokenizing compound words, and checks the spelling of each word or token. "). This also impacts use of nameof() in C#.

For example in my project I have this line of code:

throw new InvalidOperationException( nameof(this.ReadMessages) + " invoked before method has returned." );

This currently gives me this code analysis build warning:

Warning - CA2204 - Literals should be spelled correctly - Correct the spelling of the unrecognized token 'ReadMessages' in the literal '"ReadMessages invoked before method has returned."'.

A workaround is to add the word "readmessages" to my Code Analysis Dictionary file's <Recognized><Word> list, however this is not a correct solution because it then makes "readmessages" (case-insensitive) a recognized word (which it isn't, it's a compound word) which then then causes this analysis warning to appear on my ReadMessages method:

Warning - CA1702 - Compound words should be cased correctly - The compound word 'ReadMessages' in member name 'MyClass.ReadMessagesAsync(NetworkStream, byte[])' exists as a discrete term. If your usage is intended to be single word, case it as 'Readmessages' or strip the first token entirely if it represents any sort of Hungarian notation.

(Note it instructs me to use Readmessages instead of ReadMessages).

I'd also like to request that the code-analysis rules automatically add any nameof() value (or better yet: any C# identifier in the project, regardless of access modifier (public, internal, etc)) be automatically added to the list of recognized words when checking string literals (with correct compound word handling, of course).

@mavasani mavasani modified the milestones: 15.8, Unknown Feb 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants