Skip to content

Commit

Permalink
Add proto formatting tool (#7266)
Browse files Browse the repository at this point in the history
* Add proto format option

* Add clang format options

* Fix proto format

* Fix fmt

* Fix SpacesInSquareBrackets to match with SpacesInSquareBrackets setting
  • Loading branch information
anilcse authored Sep 8, 2020
1 parent 9856327 commit a9547b5
Show file tree
Hide file tree
Showing 58 changed files with 943 additions and 1,197 deletions.
115 changes: 115 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
Language: Proto
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
RawStringFormats:
- Delimiter: pb
Language: TextProto
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...

5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,14 @@ devdoc-update:
### Protobuf ###
###############################################################################

proto-all: proto-tools proto-gen proto-lint proto-check-breaking proto-swagger-gen
proto-all: proto-tools proto-gen proto-lint proto-check-breaking proto-swagger-gen proto-format

proto-gen:
@./scripts/protocgen.sh

proto-format:
find ./ -not -path "./third_party/*" -name *.proto -exec clang-format -i {} \;

# This generates the SDK's custom wrapper for google.protobuf.Any. It should only be run manually when needed
proto-gen-any:
@./scripts/protocgen-any.sh
Expand Down
8 changes: 8 additions & 0 deletions contrib/devtools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ ifeq (, $(shell which protoc-gen-swagger))
else
@echo "protoc-gen-grpc-gateway already installed; skipping..."
endif
ifeq ($(UNAME_S),Linux)
@echo "Installing clang-format..."
sudo apt-get install clang-format
endif
ifeq ($(UNAME_S),Darwin)
@echo "Installing clang-format..."
brew install clang-format
endif

buf: buf-stamp

Expand Down
16 changes: 8 additions & 8 deletions proto/cosmos/auth/v1beta1/auth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/auth/types";
// for basic account functionality. Any custom account type should extend this
// type for additional functionality (e.g. vesting).
message BaseAccount {
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (cosmos_proto.implements_interface) = "AccountI";

bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
Expand All @@ -22,13 +22,13 @@ message BaseAccount {

// ModuleAccount defines an account for modules that holds coins on a pool.
message ModuleAccount {
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;
option (cosmos_proto.implements_interface) = "ModuleAccountI";

BaseAccount base_account = 1 [(gogoproto.embed) = true, (gogoproto.moretags) = "yaml:\"base_account\""];
string name = 2;
repeated string permissions = 3;
BaseAccount base_account = 1 [(gogoproto.embed) = true, (gogoproto.moretags) = "yaml:\"base_account\""];
string name = 2;
repeated string permissions = 3;
}

// Params defines the parameters for the auth module.
Expand All @@ -43,4 +43,4 @@ message Params {
[(gogoproto.customname) = "SigVerifyCostED25519", (gogoproto.moretags) = "yaml:\"sig_verify_cost_ed25519\""];
uint64 sig_verify_cost_secp256k1 = 5
[(gogoproto.customname) = "SigVerifyCostSecp256k1", (gogoproto.moretags) = "yaml:\"sig_verify_cost_secp256k1\""];
}
}
4 changes: 1 addition & 3 deletions proto/cosmos/auth/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/auth/types";
// GenesisState defines the auth module's genesis state.
message GenesisState {
// params defines all the paramaters of the module.
Params params = 1 [
(gogoproto.nullable) = false
];
Params params = 1 [(gogoproto.nullable) = false];

// accounts are the accounts present at genesis.
repeated google.protobuf.Any accounts = 2;
Expand Down
30 changes: 15 additions & 15 deletions proto/cosmos/auth/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@ import "cosmos_proto/cosmos.proto";
option go_package = "github.com/cosmos/cosmos-sdk/x/auth/types";

// Query defines the gRPC querier service.
service Query{
// Account returns account details based on address.
rpc Account (QueryAccountRequest) returns (QueryAccountResponse) {
option (google.api.http).get = "/cosmos/auth/v1beta1/accounts/{address}";
}

// Params queries all parameters.
rpc Params (QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/cosmos/auth/v1beta1/params";
}
service Query {
// Account returns account details based on address.
rpc Account(QueryAccountRequest) returns (QueryAccountResponse) {
option (google.api.http).get = "/cosmos/auth/v1beta1/accounts/{address}";
}

// Params queries all parameters.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/cosmos/auth/v1beta1/params";
}
}

// QueryAccountRequest is the request type for the Query/Account RPC method.
message QueryAccountRequest{
message QueryAccountRequest {
// address defines the address to query for.
bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];
}

// QueryAccountResponse is the response type for the Query/Account RPC method.
message QueryAccountResponse{
message QueryAccountResponse {
// account defines the account of the corresponding address.
google.protobuf.Any account = 1 [(cosmos_proto.accepts_interface) = "AccountI"];
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest{ }
message QueryParamsRequest {}

// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse{
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];
}
}
20 changes: 10 additions & 10 deletions proto/cosmos/bank/v1beta1/bank.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,30 @@ message Supply {
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
}

// DenomUnit represents a struct that describes a given
// DenomUnit represents a struct that describes a given
// denomination unit of the basic token.
message DenomUnit {
// denom represents the string name of the given denom unit (e.g uatom).
string denom = 1;
string denom = 1;
// exponent represents power of 10 exponent that one must
// raise the base_denom to in order to equal the given DenomUnit's denom
// 1 denom = 1^exponent base_denom
// (e.g. with a base_denom of uatom, one can create a DenomUnit of 'atom' with
// (e.g. with a base_denom of uatom, one can create a DenomUnit of 'atom' with
// exponent = 6, thus: 1 atom = 10^6 uatom).
uint32 exponent = 2;
uint32 exponent = 2;
// aliases is a list of string aliases for the given denom
repeated string aliases = 3;
repeated string aliases = 3;
}

// Metadata represents a struct that describes
// Metadata represents a struct that describes
// a basic token.
message Metadata {
string description = 1;
string description = 1;
// denom_units represents the list of DenomUnit's for a given coin
repeated DenomUnit denom_units = 2;
// base represents the base denom (should be the DenomUnit with exponent = 0).
string base = 3;
string base = 3;
// display indicates the suggested denom that should be
// displayed in clients.
string display = 4;
}
string display = 4;
}
27 changes: 8 additions & 19 deletions proto/cosmos/bank/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,28 @@ option go_package = "github.com/cosmos/cosmos-sdk/x/bank/types";
// GenesisState defines the bank module's genesis state.
message GenesisState {
// params defines all the paramaters of the module.
Params params = 1 [
(gogoproto.nullable) = false
];
Params params = 1 [(gogoproto.nullable) = false];

// balances is an array containing the balances of all the accounts.
repeated Balance balances = 2 [
(gogoproto.nullable) = false
];
repeated Balance balances = 2 [(gogoproto.nullable) = false];

// supply represents the total supply.
repeated cosmos.base.v1beta1.Coin supply = 3 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.nullable) = false
];
repeated cosmos.base.v1beta1.Coin supply = 3
[(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false];

// denom_metadata defines the metadata of the differents coins.
repeated Metadata denom_metadata = 4 [
(gogoproto.moretags) = "yaml:\"denom_metadata\"",
(gogoproto.nullable) = false
];
repeated Metadata denom_metadata = 4 [(gogoproto.moretags) = "yaml:\"denom_metadata\"", (gogoproto.nullable) = false];
}

// Balance defines an account address and balance pair used in the bank module's
// genesis state.
message Balance {
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_getters) = false;

// address is the address of the balance holder.
bytes address = 1 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress"];

// coins defines the different coins this balance holds.
repeated cosmos.base.v1beta1.Coin coins = 2 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.nullable) = false
];
repeated cosmos.base.v1beta1.Coin coins = 2
[(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", (gogoproto.nullable) = false];
}
2 changes: 1 addition & 1 deletion proto/cosmos/bank/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ message MsgSend {
message MsgMultiSend {
option (gogoproto.equal) = true;

repeated Input inputs = 1 [(gogoproto.nullable) = false];
repeated Input inputs = 1 [(gogoproto.nullable) = false];
repeated Output outputs = 2 [(gogoproto.nullable) = false];
}
2 changes: 1 addition & 1 deletion proto/cosmos/base/abci/v1beta1/abci.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ message ABCIMessageLog {
message StringEvent {
option (gogoproto.stringer) = true;

string type = 1;
string type = 1;
repeated Attribute attributes = 2 [(gogoproto.nullable) = false];
}

Expand Down
6 changes: 3 additions & 3 deletions proto/cosmos/base/crypto/v1beta1/crypto.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ message PublicKey {

// any_pubkey can be used for any pubkey that an app may use which is
// not explicitly defined in the oneof
google.protobuf.Any any_pubkey = 15; // 15 is largest field that occupies one byte
google.protobuf.Any any_pubkey = 15; // 15 is largest field that occupies one byte
}
}

// PubKeyMultisigThreshold specifies a public key type which nests multiple public
// keys and a threshold
message PubKeyMultisigThreshold {
uint32 threshold = 1 [(gogoproto.customname) = "K", (gogoproto.moretags) = "yaml:\"threshold\""];
uint32 threshold = 1 [(gogoproto.customname) = "K", (gogoproto.moretags) = "yaml:\"threshold\""];
repeated PublicKey public_keys = 2 [(gogoproto.customname) = "PubKeys", (gogoproto.moretags) = "yaml:\"pubkeys\""];
}

Expand All @@ -34,7 +34,7 @@ message PubKeyMultisigThreshold {
// with which modes.
message MultiSignature {
option (gogoproto.goproto_unrecognized) = true;
repeated bytes signatures = 1;
repeated bytes signatures = 1;
}

// CompactBitArray is an implementation of a space efficient bit array.
Expand Down
Loading

0 comments on commit a9547b5

Please sign in to comment.