Closed QuintillusCFC closed 2 years ago
This blog has some opinions:
dotnet format
command. They don't seem very impressed with it, but maybe it's improved since the blog was written.I haven't done a deep dive yet, but it seems like there should be some decent options. No matter which we go with, it'd be good to get some opinions from the other devs before committing the rules (although we can always vote to change some rules later).
No matter what tool we go with, we should probably add a pre-commit hook to do the code formatting automatically on staged files before committing, as described here.
I've looked into this and tried some of suggested extensions. I think one good option may be to configure Visual Studio with an .editorconfig
(see here), and configure omnisharp to use .editorconfig
for Visual Studio Code (see here). I'm not sure about Rider since I don't have it, but I would be surprised if it wasn't easy to also configure omnisharp / whatever the default formatter is to use .editorconfig
. The pro of going this route is that for visual studio and visual studio code (assuming you already have the C# extension installed), there's no need to install an additional extension for formatting.
That does look promising. Rider does support it (see https://www.jetbrains.com/help/rider/Using_EditorConfig.html#export-code-style-settings), and EditorConfig seems to have a website listing editor support at https://editorconfig.org/ . And as Sean-Brown's research indicates, StyleCop also uses .editorconfig, as does SonarLint.
I might yet try Resharper on top of Visual Studio, but it's not a solution for this problem since it can't be used by everyone.
As mentioned by @Sean-Brown , and previously at CFC, we should have code formatting happen automagically, especially as the project and the potential for inconsistency grows.
Ideally, this will be something that can be used across IDEs. I don't know if that's feasible in the .NET world though. If you are a .NET person and know a good solution, you can take this issue and run with it!
Also of note is that we haven't settled on many code styles yet, except for using tabs for indentation rather than spaces. There are definite inconsistencies, so a plugin that fixes everything in the project at once will result in a huge change set. It might be better to have one that applies when files are saved. But taking this issue might also mean herding some cats to agree on currently diverging standards.