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

Bump Go to 1.17, use golangci-lint instead of make lint #112

Merged
merged 8 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/pre-commit.yml
@@ -0,0 +1,17 @@
name: pre-commit
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.17'
- uses: pre-commit/action@v3.0.0
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Expand Up @@ -26,13 +26,14 @@ jobs:
- name: Set Up Go
uses: actions/setup-go@v2
with:
go-version: '1.14.6'
go-version: '1.17'
- run: mkdir -p $GOPATH/bin
- run: wget "https://github.com/protocolbuffers/protobuf/releases/download/v${{ matrix.protoc-version }}/protoc-${{ matrix.protoc-version }}-linux-x86_64.zip" -O /tmp/protoc.zip
- run: unzip /tmp/protoc.zip -d /tmp
- run: sudo mv /tmp/bin/protoc /usr/local/bin/protoc
- run: sudo mv /tmp/include/google /usr/local/include/google
- name: Generate Testdata
run: make testdata
- name: Lint
run: make lint tests
- name: Run Tests
run: make tests

26 changes: 26 additions & 0 deletions .golangci.yml
@@ -0,0 +1,26 @@
linters:
disable-all: true
enable:
- deadcode
- goconst
- gocyclo
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- misspell
- revive
- structcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
issues:
max-per-linter: 0
max-same-issues: 0
run:
build-tags:
- integration
deadline: 5m
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,7 @@
default_language_version:
python: python3.8
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.42.1
hooks:
- id: golangci-lint
14 changes: 2 additions & 12 deletions Makefile
Expand Up @@ -5,16 +5,6 @@ PROTOC_VER := $(shell protoc --version | cut -d' ' -f2)
.PHONY: bootstrap
bootstrap: testdata # set up the project for development

.PHONY: lint
lint: # lints the package for common code smells
set -e; for f in `find . -name "*.go" -not -name "*.pb.go"`; do \
out=`gofmt -s -d $$f`; \
test -z "$$out" || (echo $$out && exit 1); \
done
which golint || go get -u golang.org/x/lint/golint
golint -set_exit_status ./...
go vet -all

.PHONY: quick
quick: testdata # runs all tests without the race detector or coverage
ifeq ($(PROTOC_VER), 3.17.0)
Expand Down Expand Up @@ -59,7 +49,7 @@ testdata-graph: bin/protoc-gen-debug # parses the proto file sets in testdata/gr
done

testdata/generated: protoc-gen-go bin/protoc-gen-example
which protoc-gen-go || (go install github.com/golang/protobuf/protoc-gen-go)
go install google.golang.org/protobuf/cmd/protoc-gen-go
rm -rf ./testdata/generated && mkdir -p ./testdata/generated
# generate the official go code, must be one directory at a time
set -e; for subdir in `find ./testdata/protos -mindepth 1 -type d`; do \
Expand Down Expand Up @@ -100,7 +90,7 @@ vendor: # install project dependencies

.PHONY: protoc-gen-go
protoc-gen-go:
which protoc-gen-go || (go install github.com/golang/protobuf/protoc-gen-go)
go install google.golang.org/protobuf/cmd/protoc-gen-go

bin/protoc-gen-example: # creates the demo protoc plugin for demonstrating uses of PG*
go build -o ./bin/protoc-gen-example ./testdata/protoc-gen-example
Expand Down
14 changes: 8 additions & 6 deletions artifact_test.go
Expand Up @@ -13,6 +13,8 @@ var (
artifactTpl = template.Must(template.New("foo").Parse("{{ . }}"))
)

const fName = "foo"

func TestGeneratorFile_ProtoFile(t *testing.T) {
t.Parallel()

Expand All @@ -25,7 +27,7 @@ func TestGeneratorFile_ProtoFile(t *testing.T) {
assert.Error(t, err)
assert.Nil(t, pb)

f.Name = "foo"
f.Name = fName
pb, err = f.ProtoFile()
assert.NoError(t, err)
assert.Equal(t, f.Name, pb.GetName())
Expand All @@ -47,7 +49,7 @@ func TestGeneratorTemplateFile_ProtoFile(t *testing.T) {
assert.Error(t, err)
assert.Nil(t, pb)

f.Name = "foo"
f.Name = fName
pb, err = f.ProtoFile()
assert.Error(t, err)
assert.Nil(t, pb)
Expand All @@ -71,7 +73,7 @@ func TestGeneratorAppend_ProtoFile(t *testing.T) {
assert.Error(t, err)
assert.Nil(t, pb)

f.FileName = "foo"
f.FileName = fName
pb, err = f.ProtoFile()
assert.NoError(t, err)
assert.Empty(t, pb.GetName())
Expand All @@ -93,7 +95,7 @@ func TestGeneratorTemplateAppend_ProtoFile(t *testing.T) {
assert.Error(t, err)
assert.Nil(t, pb)

f.FileName = "foo"
f.FileName = fName
pb, err = f.ProtoFile()
assert.Error(t, err)
assert.Nil(t, pb)
Expand All @@ -118,7 +120,7 @@ func TestGeneratorInjection_ProtoFile(t *testing.T) {
assert.Error(t, err)
assert.Nil(t, pb)

f.FileName = "foo"
f.FileName = fName
pb, err = f.ProtoFile()
assert.NoError(t, err)
assert.Equal(t, f.FileName, pb.GetName())
Expand All @@ -142,7 +144,7 @@ func TestGeneratorTemplateInjection_ProtoFile(t *testing.T) {
assert.Error(t, err)
assert.Nil(t, pb)

f.FileName = "foo"
f.FileName = fName
pb, err = f.ProtoFile()
assert.Error(t, err)
assert.Nil(t, pb)
Expand Down
3 changes: 1 addition & 2 deletions field_test.go
Expand Up @@ -251,8 +251,7 @@ func dummyOneOfField(synthetic bool) *field {
m := dummyMsg()
o := dummyOneof()
str := descriptor.FieldDescriptorProto_TYPE_STRING
var oIndex int32
oIndex = 1
var oIndex int32 = 1
f := &field{desc: &descriptor.FieldDescriptorProto{
Name: proto.String("field"),
Type: &str,
Expand Down
5 changes: 2 additions & 3 deletions field_type_test.go
Expand Up @@ -304,9 +304,8 @@ func TestMapT_Key(t *testing.T) {

type mockT struct {
FieldType
i []File
f Field
err error
i []File
f Field
}

func (t *mockT) Imports() []File { return t.i }
Expand Down
8 changes: 4 additions & 4 deletions lang/go/name.go
Expand Up @@ -22,7 +22,7 @@ func (c context) Name(node pgs.Node) pgs.Name {
return c.PackageName(en)
case ChildEntity: // Message or Enum types, which may be nested
if p, ok := en.Parent().(pgs.Message); ok {
return pgs.Name(joinChild(c.Name(p), en.Name()))
return joinChild(c.Name(p), en.Name())
}
return PGGUpperCamelCase(en.Name())
case pgs.Field: // field names cannot conflict with other generated methods
Expand All @@ -31,9 +31,9 @@ func (c context) Name(node pgs.Node) pgs.Name {
return replaceProtected(PGGUpperCamelCase(en.Name()))
case pgs.EnumValue: // EnumValue are prefixed with the enum name
if _, ok := en.Enum().Parent().(pgs.File); ok {
return pgs.Name(joinNames(c.Name(en.Enum()), en.Name()))
return joinNames(c.Name(en.Enum()), en.Name())
}
return pgs.Name(joinNames(c.Name(en.Enum().Parent()), en.Name()))
return joinNames(c.Name(en.Enum().Parent()), en.Name())
case pgs.Service: // always return the server name
return c.ServerName(en)
case pgs.Entity: // any other entity should be just upper-camel-cased
Expand All @@ -44,7 +44,7 @@ func (c context) Name(node pgs.Node) pgs.Name {
}

func (c context) OneofOption(field pgs.Field) pgs.Name {
n := pgs.Name(joinNames(c.Name(field.Message()), c.Name(field)))
n := joinNames(c.Name(field.Message()), c.Name(field))

for _, msg := range field.Message().Messages() {
if c.Name(msg) == n {
Expand Down
8 changes: 0 additions & 8 deletions lang/go/package_test.go
Expand Up @@ -62,12 +62,6 @@ func TestImportPath(t *testing.T) {
"example.com/fizz/buzz",
"example.com/quux",
},
{ // import_prefix param prefixes everything...pretty much doesn't work since it also prefixes the proto package
"import_prefix",
"foo.bar/example.com/packages/targets/fully_qualified",
"foo.bar/targets/unqualified",
"foo.bar/fizz/buzz",
},
}

for _, test := range tests {
Expand Down Expand Up @@ -109,8 +103,6 @@ func TestOutputPath(t *testing.T) {
{"unqualified_srcrel", "unqualified.proto", "unqualified.pb.go"},
{"qualified", "qualified.proto", "example.com/qualified/qualified.pb.go"},
{"qualified_srcrel", "qualified.proto", "qualified.pb.go"},
{"import_prefix", "prefix.proto", "example.com/import_prefix/prefix.pb.go"},
{"import_prefix_srcrel", "prefix.proto", "prefix.pb.go"},
{"mapped", "mapped.proto", "mapped.pb.go"},
{"mapped_srcrel", "mapped.proto", "mapped.pb.go"},
}
Expand Down
1 change: 0 additions & 1 deletion lang/go/testdata/outputs/import_prefix/params

This file was deleted.

4 changes: 0 additions & 4 deletions lang/go/testdata/outputs/import_prefix/prefix.proto

This file was deleted.

2 changes: 0 additions & 2 deletions lang/go/testdata/outputs/import_prefix_srcrel/params

This file was deleted.

4 changes: 0 additions & 4 deletions lang/go/testdata/outputs/import_prefix_srcrel/prefix.proto

This file was deleted.

13 changes: 0 additions & 13 deletions lang/go/testdata/packages/import_prefix/import_prefix.proto

This file was deleted.

1 change: 0 additions & 1 deletion lang/go/testdata/packages/import_prefix/params

This file was deleted.

1 change: 1 addition & 0 deletions lang/go/type_name_p2_presence_test.go
@@ -1,3 +1,4 @@
//go:build !proto3_presence
// +build !proto3_presence

package pgsgo
Expand Down
2 changes: 1 addition & 1 deletion method.go
Expand Up @@ -93,4 +93,4 @@ func (m *method) childAtPath(path []int32) Entity {

func (m *method) addSourceCodeInfo(info SourceCodeInfo) { m.info = info }

var m Method = (*method)(nil)
var _ Method = (*method)(nil)