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

Update S101: A special case should be made for two-letter acronyms in… #577

Merged
merged 3 commits into from
Jul 21, 2017

Conversation

michalb-sonar
Copy link
Contributor

@michalb-sonar michalb-sonar commented Jul 20, 2017

… which both letters are capitalized

Fix S101: "Class Name" infinite loop when class name contains non-Latin Characters
Fix S100: infinite loop when class name contains non-Latin Characters

Fix #174
Fix #576
Fix #526

… which both letters are capitalized

Fix S101: "Class Name" infinite loop when class name contains non-Latin Characters
Fix S100: infinite loop when class name contains non-Latin Characters
@Evangelink
Copy link
Contributor

@michalb-sonar let's put link to ticket using issue reference (#).

Copy link
Contributor

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

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

A couple of FP, few comments to fix and after it should be good. Algorithm seems quite long but not so complex.

{
"id": "S101",
"message": "Rename interface 'ITVImageScraper' to match camel case naming rules, consider using 'ITvImageScraper'.",
"message": "Rename interface 'ITVImageScraper' to match camel case naming rules, consider using 'ItvImageScraper'.",
Copy link
Contributor

Choose a reason for hiding this comment

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

For me we should not raise at all here:
I for interface, TV, Image, Scraper
We might want to detect whether this is an interface to allow/prevent this. What I mean is, in this case, it's ok if this is an interface, it's not otherwise.

@@ -28,7 +15,7 @@
},
{
"id": "S101",
"message": "Rename interface 'ITVInfoScraper' to match camel case naming rules, consider using 'ITvInfoScraper'.",
"message": "Rename interface 'ITVInfoScraper' to match camel case naming rules, consider using 'ItvInfoScraper'.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

@@ -15,7 +15,7 @@
},
{
"id": "S100",
"message": "Rename method 'expectMsgPF' to match camel case naming rules, consider using 'ExpectMsgPF'.",
"message": "Rename method 'expectMsgPF' to match camel case naming rules, consider using 'ExpectMsgPf'.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Haven't read the full description of the rule but is it allowed to have 2 letters acronym only if not at the end? If yes then fine, otherwise we have a FP here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought exactly the same. However, this doesn't raise because of two letter acronym, but because it doesn't start with uppercase letter.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah! Shall we not have a suggestion with the least possible change? (i.e. ExpectMsgPF)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried that, but then there are suboptimal cases - like we would suggest "FSm" instead of "FSM". I'll leave it for now, we can always revise it.


private static readonly Dictionary<SyntaxKind, string> TypeKindNameMapping = new Dictionary<SyntaxKind, string>
{
{SyntaxKind.StructDeclaration, "struct" },
Copy link
Contributor

Choose a reason for hiding this comment

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

That's minor but I would have added a space after the opening curly braces.

: input;
}

private static bool IsCharUpper(string input, int idx)
Copy link
Contributor

Choose a reason for hiding this comment

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

IsUpperChar maybe no?

bool isNameValid = IsTypeNameValid(identifier.ValueText,
typeDeclaration is InterfaceDeclarationSyntax,
typeDeclaration.Modifiers.Any(m => m.IsKind(SyntaxKind.StaticKeyword)),
context.SemanticModel.Compilation.IsTest(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Try to use the short form here: context.IsTest().

continue;
}

var ideal = i == 0 ? HandleFirstTypePart(part, requireInitialI, allowInitialI, 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

[minor] I would put ? on new line.

var ideal = i == 0 ? HandleFirstTypePart(part, requireInitialI, allowInitialI, 1)
: SuggestLessUppercase(part, 1);

var acceptable = i == 0 ? HandleFirstTypePart(part, requireInitialI, allowInitialI, 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

[minor] I would put ? on new line.

var idealNameVariant = new StringBuilder(identifierName.Length);
var acceptableNameVariant = new StringBuilder(identifierName.Length);

var parts = SplitToCamelCase(identifierName).ToList();
Copy link
Contributor

Choose a reason for hiding this comment

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

What about words?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are not words. It could also be a symbol, or a two-letter acronym, which makes it a bit confusing.

var parts = SplitToCamelCase(identifierName).ToList();
for (int i = 0; i < parts.Count; i++)
{
string part = parts[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

What about currentWord?

typeDeclaration.Modifiers.Any(m => m.IsKind(SyntaxKind.StaticKeyword)),
context.SemanticModel.Compilation.IsTest(),
out suggestion);
requireInitialI: typeDeclaration is InterfaceDeclarationSyntax,
Copy link
Contributor

Choose a reason for hiding this comment

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

So much easier to read :)

@michalb-sonar michalb-sonar merged commit a413ca7 into master Jul 21, 2017
@michalb-sonar michalb-sonar deleted the fix101 branch July 21, 2017 08:09
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.

2 participants