Skip to content
forked from belav/csharpier

CSharpier is an opinionated code formatter for c#.

License

Notifications You must be signed in to change notification settings

faktored/csharpier

 
 

Repository files navigation

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 has no plans to add more. It follows the Option Philosophy of prettier.

Work In Progress

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.

Features

  • 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

Before

public class ClassName {
    public string ShortPropertyName {
        get;
        set; 
    }

    public void LongUglyMethod(string longParameter1, string longParameter2, string longParameter3) { 
        this.LongUglyMethod("1234567890", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    }
}

After

public class ClassName
{
    public string ShortPropertyName { get; set; }

    public void LongUglyMethod(
        string longParameter1,
        string longParameter2,
        string longParameter3
    ) {
        this.LongUglyMethod(
            "1234567890",
            "abcdefghijklmnopqrstuvwxyz",
            "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        );
    }
}

Installation

dotnet tool install -g csharpier

Basic Usage

Run csharpier from the directory you wish to format.

dotnet csharpier

MsBuild Package

If you prefer to have csharpier run when a project is built, you can use the CSharpier.MSBuild nuget package

Install-Package CSharpier.MSBuild

Documentation

Command Line Interface
Configuration File
Editors and CI/CD
Ignoring Files
ChangeLog
MSBuild Package

Contributing

See Development Readme

Join Us Discord

About

CSharpier is an opinionated code formatter for c#.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 97.8%
  • TypeScript 1.3%
  • PowerShell 0.4%
  • JavaScript 0.2%
  • HTML 0.2%
  • Dockerfile 0.1%