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

Implement CA1308: NormalizeStringsToUppercase #886

Merged
merged 2 commits into from
Mar 24, 2016

Conversation

mavasani
Copy link
Contributor

Strings should be normalized to uppercase. A small group of characters, when they are converted to lowercase, cannot make a round trip. To make a round trip means to convert the characters from one locale to another locale that represents character data differently, and then to accurately retrieve the original characters from the converted characters.

MSDN help: https://msdn.microsoft.com/en-us/library/bb386042.aspx

TODO: Implement a fixer

Fixes #416

@mavasani
Copy link
Contributor Author

Tagging @dotnet/roslyn-analysis for review.

@@ -4,45 +4,98 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Analyzer.Utilities;
using System.Linq;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort using

Strings should be normalized to uppercase. A small group of characters, when they are converted to lowercase, cannot make a round trip. To make a round trip means to convert the characters from one locale to another locale that represents character data differently, and then to accurately retrieve the original characters from the converted characters.

MSDN help: https://msdn.microsoft.com/en-us/library/bb386042.aspx

TODO: Implement a fixer

Fixes dotnet#416

compilationStartContext.RegisterOperationAction(operationAnalysisContext =>
{
if (operationAnalysisContext.Operation.IsInvalid)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to write this test in every operation analyzer? If so, we should have an analyzer analyzer for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JohnHamby @genlu can advice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically, checking for validity shouldn't be necessary here--the various properties of operation nodes are supposed to be available safely. In practice, today, some properties might misbehave for invalid nodes.

We could enhance the API to include a means to indicate during registration that the action should run only for nodes for which IsInvalid is false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could enhance the API to include a means to indicate during registration that the action should run only for nodes for which IsInvalid is false.

+1 on this, let me file an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ghost
Copy link

ghost commented Mar 24, 2016

👍

@mavasani mavasani merged commit 30a922e into dotnet:master Mar 24, 2016
@mavasani mavasani deleted the CA1308 branch March 24, 2016 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Port FxCop rule CA1308: NormalizeStringsToUppercase
3 participants