Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add protovalidate lint rules #2473

Merged
merged 39 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
40e989e
basic
oliversun9 Sep 27, 2023
8bf543b
comment
oliversun9 Sep 27, 2023
2afea78
make protosource.File expose a protodescriptor.FileDescriptor
oliversun9 Sep 28, 2023
9de109d
fix type loading for field
oliversun9 Sep 29, 2023
0bfcf63
remove remote package, generate validate.pb.go locally
oliversun9 Sep 29, 2023
9833c7c
name
oliversun9 Sep 29, 2023
3698f50
pointer
oliversun9 Sep 29, 2023
aa2ef7d
style
oliversun9 Sep 29, 2023
c1aee25
test
oliversun9 Oct 2, 2023
abc0e8d
field name
oliversun9 Oct 2, 2023
5119bce
test
oliversun9 Oct 2, 2023
3dc3dbf
use celext
oliversun9 Oct 2, 2023
69f9cba
lint
oliversun9 Oct 2, 2023
f84b653
Merge branch 'main' into osun/buf-lint-cel
oliversun9 Oct 2, 2023
3d9d2e5
comment
oliversun9 Oct 2, 2023
242a97d
doc
oliversun9 Oct 2, 2023
662bbbc
use protovalidate-go v0.3.3
oliversun9 Oct 3, 2023
5e33b02
use DefaultResolver from protovalidate-go, which in turn requires mov…
oliversun9 Oct 3, 2023
7188999
small refactor
oliversun9 Oct 3, 2023
59e3caf
remove dynamic extension types as they are no longer needed
oliversun9 Oct 3, 2023
3437aaa
rename
oliversun9 Oct 3, 2023
1215364
commit
bufdev Oct 3, 2023
c1016d2
commit
bufdev Oct 3, 2023
54d2489
commit
bufdev Oct 3, 2023
c15c65a
Merge branch 'main' into osun/buf-lint-cel
bufdev Oct 3, 2023
e842c9a
commit
bufdev Oct 3, 2023
3b32cde
add test for parsing error texts from cel-go; comments
oliversun9 Oct 4, 2023
cc10191
lint
oliversun9 Oct 4, 2023
13c2ebd
Merge branch 'main' into osun/buf-lint-cel
oliversun9 Oct 4, 2023
30a07fc
rename sub-directory for testcase
oliversun9 Oct 5, 2023
05e46db
use new dir in test
oliversun9 Oct 5, 2023
0ce125c
dont allow cel expressions on fields of type google.protobuf.Any
oliversun9 Oct 18, 2023
c9bef9d
fix make upgrade
bufdev Oct 18, 2023
a66aaa7
merge
bufdev Oct 18, 2023
a33ac0d
Add support for linting protovalidate rules (#2505)
oliversun9 Oct 31, 2023
8b474dc
fix comment
oliversun9 Oct 31, 2023
da8f4b0
merge main
oliversun9 Oct 31, 2023
742558f
bump protovalidate to v0.5.1
oliversun9 Oct 31, 2023
8aa53b8
update links
oliversun9 Oct 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/bufbuild/buf
go 1.19

require (
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20231017183020-0de7443d03cf.2
buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.31.0-20231029173807-05fb659ddef2.2
connectrpc.com/connect v1.12.0
connectrpc.com/otelconnect v0.6.0
Expand All @@ -12,6 +13,7 @@ require (
github.com/go-chi/chi/v5 v5.0.10
github.com/gofrs/flock v0.8.1
github.com/gofrs/uuid/v5 v5.0.0
github.com/google/cel-go v0.18.1
github.com/google/go-cmp v0.6.0
github.com/google/go-containerregistry v0.16.1
github.com/jdx/go-netrc v1.0.0
Expand Down Expand Up @@ -43,7 +45,6 @@ require (
)

require (
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20231017183020-0de7443d03cf.2 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9 // indirect
Expand All @@ -61,7 +62,6 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/cel-go v0.18.1 // indirect
github.com/google/pprof v0.0.0-20231023181126-ff6d637d2a7b // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
Expand Down
20 changes: 18 additions & 2 deletions make/buf/all.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
GO_ALL_REPO_PKGS := ./cmd/... ./private/...
# Need to pin until https://github.com/google/cel-go/pull/724 is resolved
GO_GET_PKGS := $(GO_GET_PKGS) \
github.com/google/cel-go@v0.18.1 \
github.com/antlr/antlr4/runtime/Go/antlr/v4@v4.0.0-20230512164433-5d1fd1a340c9
GO_BINS := $(GO_BINS) \
cmd/buf \
cmd/protoc-gen-buf-breaking \
Expand Down Expand Up @@ -28,6 +32,7 @@ LICENSE_HEADER_LICENSE_TYPE := apache
LICENSE_HEADER_COPYRIGHT_HOLDER := Buf Technologies, Inc.
LICENSE_HEADER_YEAR_RANGE := 2020-2023
LICENSE_HEADER_IGNORES := \/testdata enterprise
PROTOVALIDATE_VERSION := v0.5.1
# Comment out to use released buf
BUF_GO_INSTALL_PATH := ./cmd/buf

Expand Down Expand Up @@ -99,7 +104,13 @@ bufgeneratedeps:: \
bufgeneratecleango:
rm -rf private/gen/proto

bufgenerateclean:: bufgeneratecleango
.PHONY: bufgeneratecleanbuflinttestdata
bufgeneratecleanbuflinttestdata:
rm -rf private/bufpkg/bufcheck/buflint/testdata/deps

bufgenerateclean:: \
bufgeneratecleango \
bufgeneratecleanbuflinttestdata

.PHONY: bufgenerateprotogo
bufgenerateprotogo:
Expand All @@ -110,9 +121,14 @@ bufgenerateprotogo:
bufgenerateprotogoclient:
$(BUF_BIN) generate proto --template data/template/buf.go-client.gen.yaml

.PHONY: bufgeneratebuflinttestdata
bufgeneratebuflinttestdata:
$(BUF_BIN) export buf.build/bufbuild/protovalidate:$(PROTOVALIDATE_VERSION) --output private/bufpkg/bufcheck/buflint/testdata/deps/protovalidate

bufgeneratesteps:: \
bufgenerateprotogo \
bufgenerateprotogoclient
bufgenerateprotogoclient \
bufgeneratebuflinttestdata

.PHONY: bufrelease
bufrelease: $(MINISIGN)
Expand Down
1 change: 1 addition & 0 deletions private/buf/cmd/buf/buf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ ENUM_VALUE_PREFIX DEFAULT Checks that enum valu
ENUM_ZERO_VALUE_SUFFIX DEFAULT Checks that enum zero values are suffixed with _UNSPECIFIED (suffix is configurable).
FILE_LOWER_SNAKE_CASE DEFAULT Checks that filenames are lower_snake_case.
PACKAGE_VERSION_SUFFIX DEFAULT Checks that the last component of all packages is a version of the form v\d+, v\d+test.*, v\d+(alpha|beta)\d+, or v\d+p\d+(alpha|beta)\d+, where numbers are >=1.
PROTOVALIDATE DEFAULT Checks that protovalidate rules are valid and all CEL expressions compile.
RPC_REQUEST_RESPONSE_UNIQUE DEFAULT Checks that RPC request and response types are only used in one RPC (configurable).
RPC_REQUEST_STANDARD_NAME DEFAULT Checks that RPC request type names are RPCNameRequest or ServiceNameRPCNameRequest (configurable).
RPC_RESPONSE_STANDARD_NAME DEFAULT Checks that RPC response type names are RPCNameResponse or ServiceNameRPCNameResponse (configurable).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func checkFieldSameCType(add addFunc, corpus *corpus, previousField protosource.
if previousField.CType() != field.CType() {
// otherwise prints as hex
numberString := strconv.FormatInt(int64(field.Number()), 10)
add(field, nil, withBackupLocation(field.CTypeLocation(), field.Location()), `Field %q with name %q on message %q changed option "ctype" from %q to %q.`, numberString, field.Name(), field.Message().Name(), previousField.CType().String(), field.CType().String())
add(field, nil, withBackupLocation(field.CTypeLocation(), field.Location()), `Field %q with name %q on message %q changed option "ctype" from %q to %q.`, numberString, field.Name(), field.ParentMessage().Name(), previousField.CType().String(), field.CType().String())
}
return nil
}
Expand All @@ -238,7 +238,7 @@ func checkFieldSameJSONName(add addFunc, corpus *corpus, previousField protosour
if previousField.JSONName() != field.JSONName() {
// otherwise prints as hex
numberString := strconv.FormatInt(int64(field.Number()), 10)
add(field, nil, withBackupLocation(field.JSONNameLocation(), field.Location()), `Field %q with name %q on message %q changed option "json_name" from %q to %q.`, numberString, field.Name(), field.Message().Name(), previousField.JSONName(), field.JSONName())
add(field, nil, withBackupLocation(field.JSONNameLocation(), field.Location()), `Field %q with name %q on message %q changed option "json_name" from %q to %q.`, numberString, field.Name(), field.ParentMessage().Name(), previousField.JSONName(), field.JSONName())
}
return nil
}
Expand All @@ -250,7 +250,7 @@ func checkFieldSameJSType(add addFunc, corpus *corpus, previousField protosource
if previousField.JSType() != field.JSType() {
// otherwise prints as hex
numberString := strconv.FormatInt(int64(field.Number()), 10)
add(field, nil, withBackupLocation(field.JSTypeLocation(), field.Location()), `Field %q with name %q on message %q changed option "jstype" from %q to %q.`, numberString, field.Name(), field.Message().Name(), previousField.JSType().String(), field.JSType().String())
add(field, nil, withBackupLocation(field.JSTypeLocation(), field.Location()), `Field %q with name %q on message %q changed option "jstype" from %q to %q.`, numberString, field.Name(), field.ParentMessage().Name(), previousField.JSType().String(), field.JSType().String())
}
return nil
}
Expand All @@ -263,7 +263,7 @@ func checkFieldSameLabel(add addFunc, corpus *corpus, previousField protosource.
// otherwise prints as hex
numberString := strconv.FormatInt(int64(field.Number()), 10)
// TODO: specific label location
add(field, nil, field.Location(), `Field %q on message %q changed label from %q to %q.`, numberString, field.Message().Name(), protodescriptor.FieldDescriptorProtoLabelPrettyString(previousField.Label()), protodescriptor.FieldDescriptorProtoLabelPrettyString(field.Label()))
add(field, nil, field.Location(), `Field %q on message %q changed label from %q to %q.`, numberString, field.ParentMessage().Name(), protodescriptor.FieldDescriptorProtoLabelPrettyString(previousField.Label()), protodescriptor.FieldDescriptorProtoLabelPrettyString(field.Label()))
}
return nil
}
Expand All @@ -275,7 +275,7 @@ func checkFieldSameName(add addFunc, corpus *corpus, previousField protosource.F
if previousField.Name() != field.Name() {
// otherwise prints as hex
numberString := strconv.FormatInt(int64(field.Number()), 10)
add(field, nil, field.NameLocation(), `Field %q on message %q changed name from %q to %q.`, numberString, field.Message().Name(), previousField.Name(), field.Name())
add(field, nil, field.NameLocation(), `Field %q on message %q changed name from %q to %q.`, numberString, field.ParentMessage().Name(), previousField.Name(), field.Name())
}
return nil
}
Expand All @@ -295,7 +295,7 @@ func checkFieldSameOneof(add addFunc, corpus *corpus, previousField protosource.
if previousOneof.Name() != oneof.Name() {
// otherwise prints as hex
numberString := strconv.FormatInt(int64(field.Number()), 10)
add(field, nil, field.Location(), `Field %q on message %q moved from oneof %q to oneof %q.`, numberString, field.Message().Name(), previousOneof.Name(), oneof.Name())
add(field, nil, field.Location(), `Field %q on message %q moved from oneof %q to oneof %q.`, numberString, field.ParentMessage().Name(), previousOneof.Name(), oneof.Name())
}
return nil
}
Expand All @@ -308,7 +308,7 @@ func checkFieldSameOneof(add addFunc, corpus *corpus, previousField protosource.
}
// otherwise prints as hex
numberString := strconv.FormatInt(int64(field.Number()), 10)
add(field, nil, field.Location(), `Field %q on message %q moved from %s to %s a oneof.`, numberString, field.Message().Name(), previous, current)
add(field, nil, field.Location(), `Field %q on message %q moved from %s to %s a oneof.`, numberString, field.ParentMessage().Name(), previous, current)
return nil
}

Expand Down Expand Up @@ -493,7 +493,7 @@ func addFieldChangedType(add addFunc, previousField protosource.Field, field pro
fieldLocation,
`Field %q on message %q changed type from %q to %q.%s`,
previousNumberString,
field.Message().Name(),
field.ParentMessage().Name(),
protodescriptor.FieldDescriptorProtoTypePrettyString(previousField.Type()),
protodescriptor.FieldDescriptorProtoTypePrettyString(field.Type()),
combinedExtraMessage,
Expand All @@ -509,7 +509,7 @@ func addEnumGroupMessageFieldChangedTypeName(add addFunc, previousField protosou
field.TypeNameLocation(),
`Field %q on message %q changed type from %q to %q.`,
numberString,
field.Message().Name(),
field.ParentMessage().Name(),
strings.TrimPrefix(previousField.TypeName(), "."),
strings.TrimPrefix(field.TypeName(), "."),
)
Expand Down
Loading