Skip to content

Commit

Permalink
Bump Go to 1.17, use golangci-lint instead of make lint, develop v2 m…
Browse files Browse the repository at this point in the history
…odule (#106)

* Bump Go to 1.17
* Create v2 module
* use golangci-lint + pre-commit (GH Action) instead of make lint
  • Loading branch information
pdecks committed Aug 16, 2022
1 parent 1635a6b commit bd08ed9
Show file tree
Hide file tree
Showing 146 changed files with 12,967 additions and 29 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
10 changes: 0 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
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
14 changes: 8 additions & 6 deletions artifact_test.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions lang/go/type_name_p2_presence_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !proto3_presence
// +build !proto3_presence

package pgsgo
Expand Down
2 changes: 1 addition & 1 deletion method.go
Original file line number Diff line number Diff line change
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)
Loading

0 comments on commit bd08ed9

Please sign in to comment.