profmt
A fast, deterministic Protocol Buffers formatter powered by tree-sitter and written in Rust.
profmt turns this:
syntax = "proto2";
import "validation.proto";
import "http.proto";
package example.v1;
service Greeter { rpc Hello(HelloRequest) returns(HelloResponse) {
option (http).route="/hello";
};
}
message HelloRequest { optional string name=1 [(validation).required=true]; };
into this:
syntax = "proto2";
import "validation.proto";
import "http.proto";
package example.v1;
service Greeter {
rpc Hello(HelloRequest) returns (HelloResponse) {
option (http).route = "/hello";
}
}
message HelloRequest {
optional string name = 1 [(validation).required = true];
}
and, with the configuration shown below, into this:
syntax = "proto2";
import "http.proto";
import "validation.proto";
package example.v1;
service Greeter {
rpc Hello(HelloRequest) returns (HelloResponse) {
option (http).route = "/hello";
}
}
message HelloRequest {
optional string name = 1 [(validation).required = true];
}
Quick start
Install profmt with Homebrew:
Or install it with Cargo:
Then format or check a project:
profmt finds .proto files, respects .gitignore, and formats files in
parallel. Pass one file without --write or --check to print the result,
or use - to read standard input.
Highlights
- Fast: directory discovery and formatting both run in parallel; a check never allocates the formatted output.
- Deterministic: parallel work still produces stable output and reporting.
- Configurable: project policy lives in
.profmt.toml, not formatter special cases. Every layout a project could reasonably choose either way is an option with apreservevariant. - Strict: invalid input, parse errors, and misspelled configuration keys fail visibly. Formatting never changes a token other than a string delimiter you asked for.
- Complete: proto2, proto3 and editions, including groups, extensions, streams, text-format option values and comments anywhere.
- Embeddable: the Rust library exposes the same formatter and allocation-free checks as the CLI.
Configuration
The defaults are project-neutral: two-space indentation, 80 columns, and the source's own choice wherever projects disagree.
Add .profmt.toml at the root of a project to change that:
= 4
= 120
= "double"
= "imports_first"
= "sorted"
= "semicolon"
= "separated"
= "normalized"
profmt searches the current directory and its parents for the nearest config file. CLI options override the file for one run.
See the configuration reference for every option and its default value.
Library
Use profmt as a Rust library when formatting needs to live inside another tool:
use ;
let options = FormatOptions ;
let output = format_with_options?;
assert_eq!;
# Ok::
Read the API documentation for the complete library interface.
More
Licence
profmt is available under the MIT licence.