Skip to content

Commit 182b72d

Browse files
authored
Bump Go to 1.17, use golangci-lint instead of make lint (#112)
1 parent aeaff44 commit 182b72d

18 files changed

+73
-64
lines changed

Diff for: .github/workflows/pre-commit.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: pre-commit
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
jobs:
10+
pre-commit:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-go@v2
15+
with:
16+
go-version: '1.17'
17+
- uses: pre-commit/[email protected]

Diff for: .github/workflows/test.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ jobs:
2626
- name: Set Up Go
2727
uses: actions/setup-go@v2
2828
with:
29-
go-version: '1.14.6'
29+
go-version: '1.17'
3030
- run: mkdir -p $GOPATH/bin
3131
- 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
3232
- run: unzip /tmp/protoc.zip -d /tmp
3333
- run: sudo mv /tmp/bin/protoc /usr/local/bin/protoc
3434
- run: sudo mv /tmp/include/google /usr/local/include/google
3535
- name: Generate Testdata
3636
run: make testdata
37-
- name: Lint
38-
run: make lint tests
37+
- name: Run Tests
38+
run: make tests
39+

Diff for: .golangci.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
linters:
2+
disable-all: true
3+
enable:
4+
- deadcode
5+
- goconst
6+
- gocyclo
7+
- gofmt
8+
- goimports
9+
- gosimple
10+
- govet
11+
- ineffassign
12+
- misspell
13+
- revive
14+
- structcheck
15+
- typecheck
16+
- unconvert
17+
- unparam
18+
- unused
19+
- varcheck
20+
issues:
21+
max-per-linter: 0
22+
max-same-issues: 0
23+
run:
24+
build-tags:
25+
- integration
26+
deadline: 5m

Diff for: .pre-commit-config.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
default_language_version:
2+
python: python3.8
3+
repos:
4+
- repo: https://github.com/golangci/golangci-lint
5+
rev: v1.42.1
6+
hooks:
7+
- id: golangci-lint

Diff for: Makefile

+2-12
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ PROTOC_VER := $(shell protoc --version | cut -d' ' -f2)
55
.PHONY: bootstrap
66
bootstrap: testdata # set up the project for development
77

8-
.PHONY: lint
9-
lint: # lints the package for common code smells
10-
set -e; for f in `find . -name "*.go" -not -name "*.pb.go"`; do \
11-
out=`gofmt -s -d $$f`; \
12-
test -z "$$out" || (echo $$out && exit 1); \
13-
done
14-
which golint || go get -u golang.org/x/lint/golint
15-
golint -set_exit_status ./...
16-
go vet -all
17-
188
.PHONY: quick
199
quick: testdata # runs all tests without the race detector or coverage
2010
ifeq ($(PROTOC_VER), 3.17.0)
@@ -59,7 +49,7 @@ testdata-graph: bin/protoc-gen-debug # parses the proto file sets in testdata/gr
5949
done
6050

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

10191
.PHONY: protoc-gen-go
10292
protoc-gen-go:
103-
which protoc-gen-go || (go install github.com/golang/protobuf/protoc-gen-go)
93+
go install google.golang.org/protobuf/cmd/protoc-gen-go
10494

10595
bin/protoc-gen-example: # creates the demo protoc plugin for demonstrating uses of PG*
10696
go build -o ./bin/protoc-gen-example ./testdata/protoc-gen-example

Diff for: artifact_test.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ var (
1313
artifactTpl = template.Must(template.New("foo").Parse("{{ . }}"))
1414
)
1515

16+
const fName = "foo"
17+
1618
func TestGeneratorFile_ProtoFile(t *testing.T) {
1719
t.Parallel()
1820

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

28-
f.Name = "foo"
30+
f.Name = fName
2931
pb, err = f.ProtoFile()
3032
assert.NoError(t, err)
3133
assert.Equal(t, f.Name, pb.GetName())
@@ -47,7 +49,7 @@ func TestGeneratorTemplateFile_ProtoFile(t *testing.T) {
4749
assert.Error(t, err)
4850
assert.Nil(t, pb)
4951

50-
f.Name = "foo"
52+
f.Name = fName
5153
pb, err = f.ProtoFile()
5254
assert.Error(t, err)
5355
assert.Nil(t, pb)
@@ -71,7 +73,7 @@ func TestGeneratorAppend_ProtoFile(t *testing.T) {
7173
assert.Error(t, err)
7274
assert.Nil(t, pb)
7375

74-
f.FileName = "foo"
76+
f.FileName = fName
7577
pb, err = f.ProtoFile()
7678
assert.NoError(t, err)
7779
assert.Empty(t, pb.GetName())
@@ -93,7 +95,7 @@ func TestGeneratorTemplateAppend_ProtoFile(t *testing.T) {
9395
assert.Error(t, err)
9496
assert.Nil(t, pb)
9597

96-
f.FileName = "foo"
98+
f.FileName = fName
9799
pb, err = f.ProtoFile()
98100
assert.Error(t, err)
99101
assert.Nil(t, pb)
@@ -118,7 +120,7 @@ func TestGeneratorInjection_ProtoFile(t *testing.T) {
118120
assert.Error(t, err)
119121
assert.Nil(t, pb)
120122

121-
f.FileName = "foo"
123+
f.FileName = fName
122124
pb, err = f.ProtoFile()
123125
assert.NoError(t, err)
124126
assert.Equal(t, f.FileName, pb.GetName())
@@ -142,7 +144,7 @@ func TestGeneratorTemplateInjection_ProtoFile(t *testing.T) {
142144
assert.Error(t, err)
143145
assert.Nil(t, pb)
144146

145-
f.FileName = "foo"
147+
f.FileName = fName
146148
pb, err = f.ProtoFile()
147149
assert.Error(t, err)
148150
assert.Nil(t, pb)

Diff for: field_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,7 @@ func dummyOneOfField(synthetic bool) *field {
251251
m := dummyMsg()
252252
o := dummyOneof()
253253
str := descriptor.FieldDescriptorProto_TYPE_STRING
254-
var oIndex int32
255-
oIndex = 1
254+
var oIndex int32 = 1
256255
f := &field{desc: &descriptor.FieldDescriptorProto{
257256
Name: proto.String("field"),
258257
Type: &str,

Diff for: field_type_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,8 @@ func TestMapT_Key(t *testing.T) {
304304

305305
type mockT struct {
306306
FieldType
307-
i []File
308-
f Field
309-
err error
307+
i []File
308+
f Field
310309
}
311310

312311
func (t *mockT) Imports() []File { return t.i }

Diff for: lang/go/name.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (c context) Name(node pgs.Node) pgs.Name {
2222
return c.PackageName(en)
2323
case ChildEntity: // Message or Enum types, which may be nested
2424
if p, ok := en.Parent().(pgs.Message); ok {
25-
return pgs.Name(joinChild(c.Name(p), en.Name()))
25+
return joinChild(c.Name(p), en.Name())
2626
}
2727
return PGGUpperCamelCase(en.Name())
2828
case pgs.Field: // field names cannot conflict with other generated methods
@@ -31,9 +31,9 @@ func (c context) Name(node pgs.Node) pgs.Name {
3131
return replaceProtected(PGGUpperCamelCase(en.Name()))
3232
case pgs.EnumValue: // EnumValue are prefixed with the enum name
3333
if _, ok := en.Enum().Parent().(pgs.File); ok {
34-
return pgs.Name(joinNames(c.Name(en.Enum()), en.Name()))
34+
return joinNames(c.Name(en.Enum()), en.Name())
3535
}
36-
return pgs.Name(joinNames(c.Name(en.Enum().Parent()), en.Name()))
36+
return joinNames(c.Name(en.Enum().Parent()), en.Name())
3737
case pgs.Service: // always return the server name
3838
return c.ServerName(en)
3939
case pgs.Entity: // any other entity should be just upper-camel-cased
@@ -44,7 +44,7 @@ func (c context) Name(node pgs.Node) pgs.Name {
4444
}
4545

4646
func (c context) OneofOption(field pgs.Field) pgs.Name {
47-
n := pgs.Name(joinNames(c.Name(field.Message()), c.Name(field)))
47+
n := joinNames(c.Name(field.Message()), c.Name(field))
4848

4949
for _, msg := range field.Message().Messages() {
5050
if c.Name(msg) == n {

Diff for: lang/go/package_test.go

-8
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ func TestImportPath(t *testing.T) {
6262
"example.com/fizz/buzz",
6363
"example.com/quux",
6464
},
65-
{ // import_prefix param prefixes everything...pretty much doesn't work since it also prefixes the proto package
66-
"import_prefix",
67-
"foo.bar/example.com/packages/targets/fully_qualified",
68-
"foo.bar/targets/unqualified",
69-
"foo.bar/fizz/buzz",
70-
},
7165
}
7266

7367
for _, test := range tests {
@@ -109,8 +103,6 @@ func TestOutputPath(t *testing.T) {
109103
{"unqualified_srcrel", "unqualified.proto", "unqualified.pb.go"},
110104
{"qualified", "qualified.proto", "example.com/qualified/qualified.pb.go"},
111105
{"qualified_srcrel", "qualified.proto", "qualified.pb.go"},
112-
{"import_prefix", "prefix.proto", "example.com/import_prefix/prefix.pb.go"},
113-
{"import_prefix_srcrel", "prefix.proto", "prefix.pb.go"},
114106
{"mapped", "mapped.proto", "mapped.pb.go"},
115107
{"mapped_srcrel", "mapped.proto", "mapped.pb.go"},
116108
}

Diff for: lang/go/testdata/outputs/import_prefix/params

-1
This file was deleted.

Diff for: lang/go/testdata/outputs/import_prefix/prefix.proto

-4
This file was deleted.

Diff for: lang/go/testdata/outputs/import_prefix_srcrel/params

-2
This file was deleted.

Diff for: lang/go/testdata/outputs/import_prefix_srcrel/prefix.proto

-4
This file was deleted.

Diff for: lang/go/testdata/packages/import_prefix/import_prefix.proto

-13
This file was deleted.

Diff for: lang/go/testdata/packages/import_prefix/params

-1
This file was deleted.

Diff for: lang/go/type_name_p2_presence_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !proto3_presence
12
// +build !proto3_presence
23

34
package pgsgo

Diff for: method.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,4 @@ func (m *method) childAtPath(path []int32) Entity {
9393

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

96-
var m Method = (*method)(nil)
96+
var _ Method = (*method)(nil)

0 commit comments

Comments
 (0)