csharp icon indicating copy to clipboard operation
csharp copied to clipboard

Enforce .NET framework naming rules

Open ErikSchierboom opened this issue 6 years ago • 11 comments

The official C# capitalization conventions define how things should be named in C#. Note that these are officially guidelines, but they are followed by virtually everyone. As such, they are the de facto standard and we should make any violation of the naming conventions an error. See:

  • https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-naming-conventions?view=vs-2017
  • https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017

ErikSchierboom avatar Apr 01 '19 18:04 ErikSchierboom

The fact that they're official makes me inclined to just enforce, at least as a warning, maybe even as error.

As far as I can tell from the links that you've provided, they're guidelines only because C# does not have a language feature to block on improper naming and this document was not available pre version 1. This allows older code to work always, but not necessarily make it a loose rule.

SleeplessByte avatar Apr 03 '19 16:04 SleeplessByte

As far as I can tell from the links that you've provided, they're guidelines only because C# does not have a language feature to block on improper naming

That is correct, and it is about to change (with version 3 of the Roslyn compiler). Would you prefer a warning or an error?

ErikSchierboom avatar Apr 03 '19 16:04 ErikSchierboom

If it will error later, make it an error now. It will still compile but show up as error which is a nice intermediary

SleeplessByte avatar Apr 03 '19 16:04 SleeplessByte

Well, I'm not sure it will be an error, but it will be enforceable in the future. So still an error?

ErikSchierboom avatar Apr 03 '19 16:04 ErikSchierboom

Yeah. I think it makes sense. My argument is always: if it's official, there will be tooling. If there's tooling, there's official dependency on it following the guidelines.

Therefore enforce via error.

SleeplessByte avatar Apr 03 '19 16:04 SleeplessByte

Sound reasoning. I'll do a PR.

ErikSchierboom avatar Apr 04 '19 06:04 ErikSchierboom

I've looked into it, and the editors (VS/VS Code/Rider) don't currently enforce the editorconfig settings. We can revisit this once the editorconfig support has been baked into the compiler. Progress for this feature can be checked here.

ErikSchierboom avatar Jun 08 '19 07:06 ErikSchierboom

I think that should help unblock this issue:

https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/overview#enable-on-build

valentin-p avatar Mar 03 '21 07:03 valentin-p

Yeah, that looks good.

ErikSchierboom avatar Mar 03 '21 07:03 ErikSchierboom