A .NET global tool that formats C# source code using Roslyn, designed for use with the jj fix stdin/stdout API. Produces formatting output consistent with dotnet format by reading .editorconfig settings.
Install the tool globally from NuGet:
dotnet tool install --global FormatPipeThe tool reads C# source from stdin, can run analyzer fixes/checks, formats with .editorconfig settings resolved from the given file path, and writes the resulting source to stdout.
cat MyFile.cs | formatpipe --stdin-path MyFile.cs --fix-analyzers --format --check-analyzers| Option | Description |
|---|---|
--stdin-path |
The file path hint used to resolve .editorconfig settings (required) |
--fix-analyzers |
Runs dotnet format analyzers and applies available fixes before formatting |
--check-analyzers |
Runs dotnet format analyzers --verify-no-changes; exits 1 if warning/error diagnostics remain |
--format |
Runs Roslyn formatting after analyzer operations |
--max-fix-iterations |
Maximum analyzer fix passes; values less than 1 are treated as 5 |
When multiple stages are requested, formatpipe always runs:
- Analyzer fixes (
--fix-analyzers) - Formatting (
--format) - Analyzer verification (
--check-analyzers)
This keeps material code changes first and non-material formatting last.
stdout is reserved for the final source text. Analyzer diagnostics are written to stderr.
Exit codes: 0 success, 1 analyzer check failure, 2 tool/runtime failure.
Add the following to your jj configuration (~/.jjconfig.toml or .jj/repo/config.toml):
[fix.tools.formatpipe]
command = ["formatpipe", "--stdin-path", "$path"]
patterns = ["glob:'**/*.cs'"]To run analyzer fixes, formatting, and final verification in a single jj fix pass:
[fix.tools.formatpipe]
command = ["formatpipe", "--stdin-path", "$path", "--fix-analyzers", "--format", "--check-analyzers"]
patterns = ["glob:'**/*.cs'"]Then run:
jj fixThis will format all changed C# files in the current revision using Roslyn, respecting .editorconfig settings from the repository.
- Reads C# source code from stdin
- Walks the directory tree from the given
--stdin-pathupward to collect all.editorconfigfiles (stopping atroot = true) - Optionally runs
dotnet format analyzersto apply analyzer fixes - Optionally formats the source using
Microsoft.CodeAnalysis.Formatting.Formatter - Optionally runs analyzer verification (
--verify-no-changes) - Writes the resulting source to stdout
The formatting rules applied are the same subset that dotnet format uses for whitespace formatting: indentation, spacing, brace placement, and other layout rules defined in .editorconfig.
dotnet tool uninstall --global FormatPipe