Skip to main content

What is CSharpier?

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 follows the Option Philosophy of prettier. Option requests are out of scope for CSharpier, they will be closed without discussion.

Quick Start

Install CSharpier in a project with the following command.

dotnet tool install csharpier

Then format the contents of the project

dotnet csharpier .

See Install a local tool and CLI Usage for more information

CSharpier can also format on save in your editor, as a pre-commit hook, as part of your build or even programatically. Then you can ensure code was formatted with a CI/CD tool.


Try it out


Before

public class ClassName {
public void CallMethod() {
var shuffle = shuffle.Skip(26).LogQuery("Bottom Half").InterleaveSequenceWith(shuffle.Take(26).LogQuery("Top Half"), shuffle.Skip(26).LogQuery("Bottom Half")).LogQuery("Shuffle").ToArray();
}
}

After

public class ClassName
{
public void CallMethod()
{
var shuffle = shuffle
.Skip(26)
.LogQuery("Bottom Half")
.InterleaveSequenceWith(
shuffle.Take(26).LogQuery("Top Half"),
shuffle.Skip(26).LogQuery("Bottom Half")
)
.LogQuery("Shuffle")
.ToArray();
}
}