Vannevelj / VSDiagnostics

A collection of static analyzers based on Roslyn that integrate with VS
GNU General Public License v2.0
65 stars 16 forks source link

Conflicting naming styles with R# #617

Open Hosch250 opened 7 years ago

Hosch250 commented 7 years ago

R# says to use _camelCase naming for private static fields. VSD says to use PascalCase names for them. I usually use R#'s suggestions, but who is right here?

Vannevelj commented 7 years ago

Did VSD explicitly account for this in the code? Regardless: I think _camelCase is probably best.

JohanLarsson commented 7 years ago

R# is configurable.

Hosch250 commented 7 years ago

I'm using the default R# configuration.

Hosch250 commented 7 years ago

Here is VSD's code:

if (modifiers.Any(SyntaxKind.InternalKeyword) ||
    modifiers.Any(SyntaxKind.ProtectedKeyword) ||
    modifiers.Any(SyntaxKind.PublicKeyword))
{
    CheckNaming(variable.Identifier, "field", NamingConvention.UpperCamelCase, context);
}
else if (modifiers.Any(SyntaxKind.PrivateKeyword) ||
           nodeAsField.Modifiers.Count == 0 /* no access modifier defaults to private */)
{
    if (modifiers.Any(SyntaxKind.StaticKeyword) || modifiers.Any(SyntaxKind.ConstKeyword))
    {
        CheckNaming(variable.Identifier, "field", NamingConvention.UpperCamelCase, context);
    }
    else
    {
        CheckNaming(variable.Identifier, "field", NamingConvention.UnderscoreLowerCamelCase, context);
    }
}
JohanLarsson commented 7 years ago

StyleCop does not agree with underscore prefixes. An alternative can be to try to detect the convention used in the document/project.