You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inconsistency between classic StyleCop and StyleCopAnalyzers with SA1303 #2082
This is an interesting deviation from StyleCop Classic. The url declaration is a local constant, which is technically not a field. I view this more like a local variable declaration, which should start with a lowercase letter. My preference would be to document this as a known change.
I'll label this needs discussion to hear more opinions.
You are right, @vweijsters. The rule 1303 is named ConstFieldNamesMustBeginWithUpperCaseLetter. So it should only define the behavior for (constant) fields.
But the real life interpretation seems already Const*NamesMustBeginWithUpperCaseLetter. Further I think, why should constant variables be named identically to "normal" ones?
For me, it would be OK to change the definition 1303 to cover constant variable, too.
Alternatively a new rule ConstVariableNamesMustBeginWithUpperCaseLetter should be introduced.
No update currently. Rather than create a new rule I'd rather update SA1303 to cover this case, but it seems low priority unless someone volunteers to implement it.
Actually it's not a bug. I was receiving SA1303 error for local camelCase const because I was using native StyleCop.MsBuild. But I don't like to use PascalCase for local consts. Then I started googling why StyleCop rise this error for local consts when rule name is ConstField. Then I found this thread and didn't get that it's about completely different tool. And today I've realized that current behavior of StyleCopAnalyzers is what I was looking for. @vweijsters, you are right in your comment: local const is not a field and should not be in PascalCase.
Sorry for confusion.
I've created a unit test for local const. May I create pull request for it?
At this point, changing SA1303 to cover local variables would produce a large amount of code churn in downstream projects that just doesn't seem worth it.
Activity
vweijsters commentedon Feb 11, 2016
This is an interesting deviation from StyleCop Classic. The
urldeclaration is a local constant, which is technically not a field. I view this more like a local variable declaration, which should start with a lowercase letter. My preference would be to document this as a known change.I'll label this needs discussion to hear more opinions.
sharwell commentedon Feb 11, 2016
❓ Does our existing analyzer for local variables report a warning for
const string Url = ...?vweijsters commentedon Feb 12, 2016
@sharwell No, it doesn't. Its explicitly excluded in the SA1312 analyzer (see link)
lukas-ais commentedon Mar 3, 2016
You are right, @vweijsters. The rule 1303 is named ConstFieldNamesMustBeginWithUpperCaseLetter. So it should only define the behavior for (constant) fields.
But the real life interpretation seems already Const*NamesMustBeginWithUpperCaseLetter. Further I think, why should constant variables be named identically to "normal" ones?
For me, it would be OK to change the definition 1303 to cover constant variable, too.
Alternatively a new rule ConstVariableNamesMustBeginWithUpperCaseLetter should be introduced.
khmurach commentedon Jul 7, 2017
Any update here?
sharwell commentedon Jul 7, 2017
No update currently. Rather than create a new rule I'd rather update SA1303 to cover this case, but it seems low priority unless someone volunteers to implement it.
khmurach commentedon Jul 7, 2017
I would like to help. May I?
sharwell commentedon Jul 7, 2017
@khmurach All yours 👍 Let me know if you have questions.
💡 This is much easier than SA1312 to implement, because
constvariables can't be declared in all the places where other variables can.khmurach commentedon Jul 10, 2017
Actually it's not a bug. I was receiving SA1303 error for local camelCase const because I was using native StyleCop.MsBuild. But I don't like to use PascalCase for local consts. Then I started googling why StyleCop rise this error for local consts when rule name is ConstField. Then I found this thread and didn't get that it's about completely different tool. And today I've realized that current behavior of StyleCopAnalyzers is what I was looking for. @vweijsters, you are right in your comment: local const is not a field and should not be in PascalCase.
Sorry for confusion.
I've created a unit test for local const. May I create pull request for it?
sharwell commentedon Nov 29, 2025
At this point, changing SA1303 to cover local variables would produce a large amount of code churn in downstream projects that just doesn't seem worth it.
Document known behavior change in SA1303