Is there a pretty printer / code formatter for C# (as part of build system)? Read as: "lives outside of Visual Studio". It seems like there are plenty of these kinds of things for Java, C++/C, Go -- so it seems more than reasonable that C# should also have some code formatter that lives outside of the IDE?
(I'd actually like to couple the formatter with something like StyleCop, and have devs run it as part of the process before a commit).
NOTE: Not syntax highlighting, as in code in a web page. Instead, a Code beautifier, or code pretty printer, which would take code and format it to a style/standard coding format... which StyleCop does a style check to see if the code meets the format.
Prettier wasn't intended to format C++ code. You should install the C/C++ for Visual Studio Code extension developed by Microsoft, it supports code formatting.
The C/C++ extension for Visual Studio Code supports source code formatting using clang-format which is included with the extension. You can format an entire file with Format Document (Ctrl+Shift+I) or just the current selection with Format Selection (Ctrl+K Ctrl+F) in right-click context menu.
A program that improves the presentation of programming source code. Based on an analysis of the syntax, it indents lines appropriately and squashes extraneous blank spaces and lines in order to produce more readable code.
JetBrains also makes a free command line tool named CleanupCode that formats c# based on .editorconfig settings. I wrote a wrapper utility for it named ReGitLint that makes it easier and faster to run as a pre-commit hook or on the build server. This can help out a lot if you've got teammates using Visual Studio Code where ReSharper isn't an option.
To get up and going just run the following commands
dotnet tool install JetBrains.ReSharper.GlobalTools dotnet tool install ReGitLint
then add the following to .git/hooks/pre-commit
#!/bin/sh dotnet regitlint -f staged --fail-on-diff
To enforce formatting on jenkins add this to your build script
dotnet tool restore dotnet regitlint --jenkins
For more options check out the readme
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With