CSharpier is an opinionated code formatter for c#. It uses Roslyn to parse your code and re-prints it using its own rules.
The printing process was ported from prettier but has evolved over time.
CSharpier provides a few basic options that affect formatting and has no plans to add more. It follows the Option Philosophy of prettier.
CSharpier is still in active development.
- The rules it uses to format code are not yet finalized and some of the results are a little ugly.
- The rules it uses to format your code will change over time.
- It has been tested against a large number of public repositories to validate that the changes it makes do not lose any syntax but there is a possibility it will break your code.
- This process has been automated and runs each time code is pushed.
I encourage you to try it out on your own code and report any bugs, code that doesn't format well, or opinions on how you think the formatting should change. If you can live with the fact that the formatting will be changing over time, it is reasonably safe to use. In addition to a steadily growing set of unit tests; csharpier is tested against ~60k c# files from a range of public repositories to validate it does not result in the lose of any source code.
- It is fast. It can format a solution of ~11,000 files in ~30 seconds.
- It supports validating the syntax of the code it produces to ensure the only changes made were whitespace and line breaks.
- It formats c# <= 9.0
Try it out at Playground
public class ClassName {
public string ShortPropertyName {
get;
set;
}
public void LongUglyMethod(string longParameter1, string longParameter2, string longParameter3) {
this.LongUglyMethod("1234567890", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}
}
public class ClassName
{
public string ShortPropertyName { get; set; }
public void LongUglyMethod(
string longParameter1,
string longParameter2,
string longParameter3
) {
this.LongUglyMethod(
"1234567890",
"abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
);
}
}
dotnet tool install -g csharpier
Run csharpier from the directory you wish to format.
dotnet csharpier
If you prefer to have csharpier run when a project is built, you can use the CSharpier.MSBuild nuget package
Install-Package CSharpier.MSBuild
Command Line Interface
Configuration File
Editors and CI/CD
Ignoring Files
ChangeLog
MSBuild Package