Skip to content

Commit

Permalink
refactor: drop all unused code and fix linter warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Stewart <[email protected]>
  • Loading branch information
paralin committed Apr 10, 2024
1 parent 5a9caf4 commit a1bcbc9
Show file tree
Hide file tree
Showing 129 changed files with 590 additions and 15,391 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ issues:

exclude:
- G601
- G306
- G204
8 changes: 4 additions & 4 deletions cmd/protoc-gen-go/annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ package main

import (
"bytes"
"io/ioutil"
"os"
"testing"

"github.com/aperturerobotics/protobuf-go-lite/internal/genid"
"github.com/google/go-cmp/cmp"
"google.golang.org/protobuf/encoding/prototext"
"github.com/aperturerobotics/protobuf-go-lite/internal/genid"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protocmp"

"google.golang.org/protobuf/types/descriptorpb"
)

func TestAnnotations(t *testing.T) {
sourceFile, err := ioutil.ReadFile("testdata/annotations/annotations.pb.go")
sourceFile, err := os.ReadFile("testdata/annotations/annotations.pb.go")
if err != nil {
t.Fatal(err)
}
metaFile, err := ioutil.ReadFile("testdata/annotations/annotations.pb.go.meta")
metaFile, err := os.ReadFile("testdata/annotations/annotations.pb.go.meta")
if err != nil {
t.Fatal(err)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/protoc-gen-go/internal_gengo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ import (
// SupportedFeatures reports the set of supported protobuf language features.
var SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL | pluginpb.CodeGeneratorResponse_FEATURE_SUPPORTS_EDITIONS)

var SupportedEditionsMinimum = editionssupport.Minimum
var SupportedEditionsMaximum = editionssupport.Maximum
var (
SupportedEditionsMinimum = editionssupport.Minimum
SupportedEditionsMaximum = editionssupport.Maximum
)

// GenerateVersionMarkers specifies whether to generate version markers.
var GenerateVersionMarkers = true
Expand All @@ -56,7 +58,6 @@ const (
// on the dependencies of generated source code.
var (
protoPackage goImportPath = protogen.GoImportPath("google.golang.org/protobuf/proto")
protoifacePackage goImportPath = protogen.GoImportPath("google.golang.org/protobuf/runtime/protoiface")
protoimplPackage goImportPath = protogen.GoImportPath("google.golang.org/protobuf/runtime/protoimpl")
protojsonPackage goImportPath = protogen.GoImportPath("google.golang.org/protobuf/encoding/protojson")
protoreflectPackage goImportPath = protogen.GoImportPath("google.golang.org/protobuf/reflect/protoreflect")
Expand Down
49 changes: 7 additions & 42 deletions cmd/protoc-gen-go/internal_gengo/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,72 +301,37 @@ func genFileDescriptor(gen *protogen.Plugin, g *protogen.GeneratedFile, f *fileI
}
}

func genEnumReflectMethods(g *protogen.GeneratedFile, f *fileInfo, e *enumInfo) {
idx := f.allEnumsByPtr[e]
typesVar := enumTypesVarName(f)

// Descriptor method.
g.P("func (", e.GoIdent, ") Descriptor() ", protoreflectPackage.Ident("EnumDescriptor"), " {")
g.P("return ", typesVar, "[", idx, "].Descriptor()")
g.P("}")
g.P()

// Type method.
g.P("func (", e.GoIdent, ") Type() ", protoreflectPackage.Ident("EnumType"), " {")
g.P("return &", typesVar, "[", idx, "]")
g.P("}")
g.P()

// Number method.
g.P("func (x ", e.GoIdent, ") Number() ", protoreflectPackage.Ident("EnumNumber"), " {")
g.P("return ", protoreflectPackage.Ident("EnumNumber"), "(x)")
g.P("}")
g.P()
}

func genMessageReflectMethods(g *protogen.GeneratedFile, f *fileInfo, m *messageInfo) {
idx := f.allMessagesByPtr[m]
typesVar := messageTypesVarName(f)

// ProtoReflect method.
g.P("func (x *", m.GoIdent, ") ProtoReflect() ", protoreflectPackage.Ident("Message"), " {")
g.P("mi := &", typesVar, "[", idx, "]")
g.P("if ", protoimplPackage.Ident("UnsafeEnabled"), " && x != nil {")
g.P("ms := ", protoimplPackage.Ident("X"), ".MessageStateOf(", protoimplPackage.Ident("Pointer"), "(x))")
g.P("if ms.LoadMessageInfo() == nil {")
g.P("ms.StoreMessageInfo(mi)")
g.P("}")
g.P("return ms")
g.P("}")
g.P("return mi.MessageOf(x)")
g.P("}")
g.P()
}

func fileVarName(f *protogen.File, suffix string) string {
prefix := f.GoDescriptorIdent.GoName
_, n := utf8.DecodeRuneInString(prefix)
prefix = strings.ToLower(prefix[:n]) + prefix[n:]
return prefix + "_" + suffix
}

func rawDescVarName(f *fileInfo) string {
return fileVarName(f.File, "rawDesc")
}

func goTypesVarName(f *fileInfo) string {
return fileVarName(f.File, "goTypes")
}

func depIdxsVarName(f *fileInfo) string {
return fileVarName(f.File, "depIdxs")
}

func enumTypesVarName(f *fileInfo) string {
return fileVarName(f.File, "enumTypes")
}

func messageTypesVarName(f *fileInfo) string {
return fileVarName(f.File, "msgTypes")
}

func extensionTypesVarName(f *fileInfo) string {
return fileVarName(f.File, "extTypes")
}

func initFuncName(f *protogen.File) string {
return fileVarName(f, "init")
}
6 changes: 4 additions & 2 deletions cmd/protoc-gen-go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (
"github.com/aperturerobotics/protobuf-go-lite/internal/version"
)

const genGoDocURL = "https://protobuf.dev/reference/go/go-generated"
const grpcDocURL = "https://grpc.io/docs/languages/go/quickstart/#regenerate-grpc-code"
const (
genGoDocURL = "https://protobuf.dev/reference/go/go-generated"
grpcDocURL = "https://grpc.io/docs/languages/go/quickstart/#regenerate-grpc-code"
)

func main() {
if len(os.Args) == 2 && os.Args[1] == "--version" {
Expand Down
5 changes: 3 additions & 2 deletions cmd/protoc-gen-go/testdata/annotations/annotations.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/protoc-gen-go/testdata/comments/comments.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/protoc-gen-go/testdata/comments/deprecated.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/protoc-gen-go/testdata/extensions/base/base.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/protoc-gen-go/testdata/extensions/ext/ext.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/protoc-gen-go/testdata/extensions/extra/extra.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/protoc-gen-go/testdata/extensions/proto3/ext3.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/protoc-gen-go/testdata/fieldnames/fieldnames.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/protoc-gen-go/testdata/import_public/a.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/protoc-gen-go/testdata/import_public/b.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/protoc-gen-go/testdata/import_public/c.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions cmd/protoc-gen-go/testdata/import_public/sub/a.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/protoc-gen-go/testdata/import_public/sub/b.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/protoc-gen-go/testdata/import_public/sub2/a.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/protoc-gen-go/testdata/imports/fmt/m.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/protoc-gen-go/testdata/imports/test_a_1/m1.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions cmd/protoc-gen-go/testdata/imports/test_a_1/m2.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a1bcbc9

Please sign in to comment.