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

New rule proposal: LocalConstNamesMustBeginWithUpperCaseLetter #1312

Open
sharwell opened this issue Aug 28, 2015 · 3 comments
Open

New rule proposal: LocalConstNamesMustBeginWithUpperCaseLetter #1312

sharwell opened this issue Aug 28, 2015 · 3 comments

Comments

@sharwell
Copy link
Member

Category: Naming
Title: Local constant names must begin with upper case letter
Description: A violation of this rule occurs when a const variable declared within a method has a name that starts with a lower-case letter. For consistency with other const usages throughout the application, these variables should have a name that starts with an upper-case letter.
Rationale: In #1310, a new rule was added which enforces a local non-const variable naming convention which is identical to the naming convention used by private non-const fields. This rule proposes a matching rule for local const variables to use the same naming convention as private const fields.

Example:

public void Foo()
{
  const int x = 3; // SA13xx (LocalConstNamesMustBeginWithUpperCaseLetter)
  Console.WriteLine(x);
}
@ghost
Copy link

ghost commented Aug 28, 2015

I don't like the idea to enforce local consts to be started with an upper-case letter. I never named local consts like this in my code. If an identifier starts with an upper-case letter then it always has an external scope (class field, method, etc.) and the upper-case-started local consts would not be consistent with this.

I would rather treat them like immutable variables and prefer to enforce them to be started with a lower-case letter instead (maybe it make sense to check them within the newly proposed rule #1310 and not to create a separate rule).

@sharwell
Copy link
Member Author

@test20150828 Rule #1310 requires that local variables use the same naming convention as private fields. Like the original rule for private fields (SA1306), this rule does not evaluate variables marked const. This proposal is a consistent pairing with that rule - it applies the same naming convention for local const variables as is current applied for private const fields. Requiring that local const variables start with a lower case variable would introduce an inconsistency in our rules which I would like to avoid.

@sharwell sharwell changed the title SA1300 should check the names of local constants New rule proposal: LocalConstNamesMustBeginWithUpperCaseLetter Aug 28, 2015
@sharwell
Copy link
Member Author

I converted this to a new rule proposal.

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

1 participant