👎 | 👍 |
---|---|
- Applies google's official protobuf style guide
- Indentation with 2 spaces
- Import groups are sorted alphabetically
- Makes all string literals double quoted:
option opt = 'foo';
=>option opt = "foo";
- Makes all enum fields uppercase:
enum E { field = 1 }
=>enum E { FIELD = 1 }
- Makes opening braces on the declaration line:
message M {
- Strips redundant semicolons:
enum E { A = 0;;;; };;;;
=>enum E {A = 0;}
- Full comment support
protofmt
is written in Haskell, you can use cabal
to install it.
git clone https://github.com/pabloariasal/protofmt.git
cd protofmt
cabal install
Just pass the file to be formatted:
protofmt <path_to_unformatted_proto_file>
Example:
$ cat unformatted.proto
syntax = 'proto3';
message M { string field = 1; };
$ protofmt unformatted.proto
syntax = "proto3";
message M {
string field = 1;
}
$ protofmt unformatted.proto | tee formatted.proto
syntax = "proto3";
message M {
string field = 1;
}
$ cat formatted.proto
syntax = "proto3";
message M {
string field = 1;
}
- Only protobuf 3
inf
andnan
are not supported as floating point literals (PR welcome)- enum fields must be decimal literals (no hex, octal or binary) (PR welcome)
- No service definitions (PR welcome)
- No
optional
norrequired
keywords supported (PR welcome)
- Only one file can be processed at once
- No
--in-place
flag supported - No
--recursive
flag supported - No
--diff
flag to display a diff between formatted and unformatted file (status code 0 if no diff)