Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ clean: ## Delete intermediate build artifacts
.PHONY: test
test: build ## Run unit tests
go test -vet=off -race -cover ./...
@# Also run against the Go Opaque API, which the protoopaque build tag selects
@# for the hybrid-generated Protobuf packages we depend on.
go test -vet=off -race -cover -tags protoopaque ./...

.PHONY: build
build: generate ## Build all packages
Expand Down
4 changes: 2 additions & 2 deletions check/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ func (a *annotation) toProto() *checkv1.Annotation {
if a.againstFileLocation != nil {
protoAgainstFileLocation = a.againstFileLocation.ToProto()
}
return &checkv1.Annotation{
return checkv1.Annotation_builder{
RuleId: a.RuleID(),
Message: a.Message(),
FileLocation: protoFileLocation,
AgainstFileLocation: protoAgainstFileLocation,
}
}.Build()
}

func (*annotation) isAnnotation() {}
Expand Down
4 changes: 2 additions & 2 deletions check/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ func (r *category) toProto() *checkv1.Category {
if r == nil {
return nil
}
return &checkv1.Category{
return checkv1.Category_builder{
Id: r.id,
Purpose: r.purpose,
Deprecated: r.deprecated,
ReplacementIds: r.replacementIDs,
}
}.Build()
}

func (*category) isCategory() {}
Expand Down
8 changes: 4 additions & 4 deletions check/check_service_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ func (c *checkServiceHandler) ListRules(_ context.Context, listRulesRequest *che
if err != nil {
return nil, err
}
listRulesResponse := &checkv1.ListRulesResponse{
listRulesResponse := checkv1.ListRulesResponse_builder{
NextPageToken: nextPageToken,
Rules: xslices.Map(rules, Rule.toProto),
}
}.Build()
if err := c.validator.Validate(listRulesResponse); err != nil {
return nil, err
}
Expand All @@ -242,10 +242,10 @@ func (c *checkServiceHandler) ListCategories(_ context.Context, listCategoriesRe
if err != nil {
return nil, err
}
listCategoriesResponse := &checkv1.ListCategoriesResponse{
listCategoriesResponse := checkv1.ListCategoriesResponse_builder{
NextPageToken: nextPageToken,
Categories: xslices.Map(categories, Category.toProto),
}
}.Build()
if err := c.validator.Validate(listCategoriesResponse); err != nil {
return nil, err
}
Expand Down
52 changes: 26 additions & 26 deletions check/check_service_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,76 +39,76 @@ func TestCheckServiceHandlerUniqueFiles(t *testing.T) {

_, err = checkServiceHandler.Check(
t.Context(),
&checkv1.CheckRequest{
checkv1.CheckRequest_builder{
FileDescriptors: []*descriptorv1.FileDescriptor{
{
descriptorv1.FileDescriptor_builder{
FileDescriptorProto: &descriptorpb.FileDescriptorProto{
Name: proto.String("foo.proto"),
SourceCodeInfo: &descriptorpb.SourceCodeInfo{},
},
},
}.Build(),
},
AgainstFileDescriptors: []*descriptorv1.FileDescriptor{
{
descriptorv1.FileDescriptor_builder{
FileDescriptorProto: &descriptorpb.FileDescriptorProto{
Name: proto.String("foo.proto"),
SourceCodeInfo: &descriptorpb.SourceCodeInfo{},
},
},
}.Build(),
},
},
}.Build(),
)
require.NoError(t, err)

_, err = checkServiceHandler.Check(
t.Context(),
&checkv1.CheckRequest{
checkv1.CheckRequest_builder{
FileDescriptors: []*descriptorv1.FileDescriptor{
{
descriptorv1.FileDescriptor_builder{
FileDescriptorProto: &descriptorpb.FileDescriptorProto{
Name: proto.String("foo.proto"),
SourceCodeInfo: &descriptorpb.SourceCodeInfo{},
},
},
{
}.Build(),
descriptorv1.FileDescriptor_builder{
FileDescriptorProto: &descriptorpb.FileDescriptorProto{
Name: proto.String("foo.proto"),
SourceCodeInfo: &descriptorpb.SourceCodeInfo{},
},
},
}.Build(),
},
},
}.Build(),
)
pluginrpcError := &pluginrpc.Error{}
require.ErrorAs(t, err, &pluginrpcError)
require.Equal(t, pluginrpc.CodeInvalidArgument, pluginrpcError.Code())

_, err = checkServiceHandler.Check(
t.Context(),
&checkv1.CheckRequest{
checkv1.CheckRequest_builder{
FileDescriptors: []*descriptorv1.FileDescriptor{
{
descriptorv1.FileDescriptor_builder{
FileDescriptorProto: &descriptorpb.FileDescriptorProto{
Name: proto.String("foo.proto"),
SourceCodeInfo: &descriptorpb.SourceCodeInfo{},
},
},
}.Build(),
},
AgainstFileDescriptors: []*descriptorv1.FileDescriptor{
{
descriptorv1.FileDescriptor_builder{
FileDescriptorProto: &descriptorpb.FileDescriptorProto{
Name: proto.String("bar.proto"),
SourceCodeInfo: &descriptorpb.SourceCodeInfo{},
},
},
{
}.Build(),
descriptorv1.FileDescriptor_builder{
FileDescriptorProto: &descriptorpb.FileDescriptorProto{
Name: proto.String("bar.proto"),
SourceCodeInfo: &descriptorpb.SourceCodeInfo{},
},
},
}.Build(),
},
},
}.Build(),
)
pluginrpcError = &pluginrpc.Error{}
require.ErrorAs(t, err, &pluginrpcError)
Expand All @@ -129,22 +129,22 @@ func TestCheckServiceHandlerNoSourceCodeInfo(t *testing.T) {

_, err = checkServiceHandler.Check(
t.Context(),
&checkv1.CheckRequest{
checkv1.CheckRequest_builder{
FileDescriptors: []*descriptorv1.FileDescriptor{
{
descriptorv1.FileDescriptor_builder{
FileDescriptorProto: &descriptorpb.FileDescriptorProto{
Name: proto.String("foo.proto"),
},
},
}.Build(),
},
AgainstFileDescriptors: []*descriptorv1.FileDescriptor{
{
descriptorv1.FileDescriptor_builder{
FileDescriptorProto: &descriptorpb.FileDescriptorProto{
Name: proto.String("foo.proto"),
},
},
}.Build(),
},
},
}.Build(),
)
require.NoError(t, err)
}
4 changes: 2 additions & 2 deletions check/checktest/checktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,12 @@ func compile(ctx context.Context, dirPaths []string, filePaths []string) ([]desc
fileDescriptorProto,
filePathToUnusedDependencyFilePaths[fileDescriptorProto.GetName()],
)
protoFileDescriptors[i] = &descriptorv1.FileDescriptor{
protoFileDescriptors[i] = descriptorv1.FileDescriptor_builder{
FileDescriptorProto: fileDescriptorProto,
IsImport: !isNotImport,
IsSyntaxUnspecified: isSyntaxUnspecified,
UnusedDependency: unusedDependencyIndexes,
}
}.Build()
}
return descriptor.FileDescriptorsForProtoFileDescriptors(protoFileDescriptors)
}
Expand Down
8 changes: 4 additions & 4 deletions check/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ func (c *client) listRulesUncached(ctx context.Context) ([]Rule, error) {
for {
response, err := checkServiceClient.ListRules(
ctx,
&checkv1.ListRulesRequest{
checkv1.ListRulesRequest_builder{
PageSize: listRulesPageSize,
PageToken: pageToken,
},
}.Build(),
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -259,10 +259,10 @@ func (c *client) listCategoriesUncached(ctx context.Context) ([]Category, error)
for {
response, err := checkServiceClient.ListCategories(
ctx,
&checkv1.ListCategoriesRequest{
checkv1.ListCategoriesRequest_builder{
PageSize: listCategoriesPageSize,
PageToken: pageToken,
},
}.Build(),
)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions check/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ func (r *request) toProtos() ([]*checkv1.CheckRequest, error) {
}
if len(r.ruleIDs) == 0 {
return []*checkv1.CheckRequest{
{
checkv1.CheckRequest_builder{
FileDescriptors: protoFileDescriptors,
AgainstFileDescriptors: protoAgainstFileDescriptors,
Options: protoOptions,
},
}.Build(),
}, nil
}
var checkRequests []*checkv1.CheckRequest
Expand All @@ -207,12 +207,12 @@ func (r *request) toProtos() ([]*checkv1.CheckRequest, error) {
end := min(start+checkRuleIDPageSize, len(r.ruleIDs))
checkRequests = append(
checkRequests,
&checkv1.CheckRequest{
checkv1.CheckRequest_builder{
FileDescriptors: protoFileDescriptors,
AgainstFileDescriptors: protoAgainstFileDescriptors,
Options: protoOptions,
RuleIds: r.ruleIDs[start:end],
},
}.Build(),
)
}
return checkRequests, nil
Expand Down
4 changes: 2 additions & 2 deletions check/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ func (r *response) Annotations() []Annotation {
}

func (r *response) toProto() *checkv1.CheckResponse {
return &checkv1.CheckResponse{
return checkv1.CheckResponse_builder{
Annotations: xslices.Map(r.annotations, Annotation.toProto),
}
}.Build()
}

func (*response) isResponse() {}
4 changes: 2 additions & 2 deletions check/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ func (r *rule) toProto() *checkv1.Rule {
return nil
}
protoRuleType := ruleTypeToProtoRuleType[r.ruleType]
return &checkv1.Rule{
return checkv1.Rule_builder{
Id: r.id,
CategoryIds: xslices.Map(r.categories, Category.ID),
Default: r.isDefault,
Purpose: r.purpose,
Type: protoRuleType,
Deprecated: r.deprecated,
ReplacementIds: r.replacementIDs,
}
}.Build()
}

func (*rule) isRule() {}
Expand Down
4 changes: 2 additions & 2 deletions descriptor/file_descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ func (f *fileDescriptor) ToProto() *descriptorv1.FileDescriptor {
if f == nil {
return nil
}
return &descriptorv1.FileDescriptor{
return descriptorv1.FileDescriptor_builder{
FileDescriptorProto: f.fileDescriptorProto,
IsImport: f.isImport,
IsSyntaxUnspecified: f.isSyntaxUnspecified,
UnusedDependency: f.unusedDependencyIndexes,
}
}.Build()
}

func (*fileDescriptor) isFileDescriptor() {}
4 changes: 2 additions & 2 deletions descriptor/file_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ func (l *fileLocation) ToProto() *descriptorv1.FileLocation {
if l == nil {
return nil
}
return &descriptorv1.FileLocation{
return descriptorv1.FileLocation_builder{
FileName: l.fileDescriptor.ProtoreflectFileDescriptor().Path(),
SourcePath: l.sourceLocation.Path,
}
}.Build()
}

func (l *fileLocation) unclonedSourcePath() protoreflect.SourcePath {
Expand Down
12 changes: 4 additions & 8 deletions info/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,13 @@ func (l *license) toProto() *infov1.License {
if l == nil {
return nil
}
protoLicense := &infov1.License{
protoLicense := infov1.License_builder{
SpdxLicenseId: l.SPDXLicenseID(),
}
}.Build()
if l.text != "" {
protoLicense.Source = &infov1.License_Text{
Text: l.text,
}
protoLicense.SetText(l.text)
} else if l.url != nil {
protoLicense.Source = &infov1.License_Url{
Url: l.url.String(),
}
protoLicense.SetUrl(l.url.String())
}
return protoLicense
}
Expand Down
4 changes: 2 additions & 2 deletions info/plugin_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ func (p *pluginInfo) License() License {
}

func (p *pluginInfo) toProto() *infov1.PluginInfo {
return &infov1.PluginInfo{
return infov1.PluginInfo_builder{
Documentation: p.documentation,
License: p.license.toProto(),
}
}.Build()
}

func (*pluginInfo) isPluginInfo() {}
Expand Down
4 changes: 2 additions & 2 deletions info/plugin_info_service_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func newPluginInfoServiceHandler(spec *Spec, options ...PluginInfoServiceHandler
return nil, err
}
protoPluginInfo := pluginInfo.toProto()
getPluginInfoResponse := &infov1.GetPluginInfoResponse{
getPluginInfoResponse := infov1.GetPluginInfoResponse_builder{
PluginInfo: protoPluginInfo,
}
}.Build()
validator := opts.validator
if validator == nil {
validator = protovalidate.GlobalValidator
Expand Down
Loading
Loading