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

Update golangci-lint linters #125

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.17'
go-version: '1.20'
- uses: pre-commit/[email protected]
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:
working-directory: ${{ env.GOPATH }}/src/github.com/lyft/protoc-gen-star
name: protoc version 3.17.0
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 1
path: ${{ env.GOPATH }}/src/github.com/lyft/protoc-gen-star
- name: Set Up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: '1.17'
go-version: '1.20'
- run: mkdir -p $GOPATH/bin
- run: wget "https://github.com/protocolbuffers/protobuf/releases/download/v3.17.0/protoc-3.17.0-linux-x86_64.zip" -O /tmp/protoc.zip
- run: unzip /tmp/protoc.zip -d /tmp
Expand Down
18 changes: 13 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
linters:
disable-all: true
enable:
- deadcode
- goconst
- gocyclo
- errcheck
- errorlint
- gofmt
- goimports
- gosec
- gosimple
- govet
- ineffassign
- misspell
- nakedret
- revive
- structcheck
- staticcheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
linters-settings:
gosec:
excludes:
- G306
revive:
rules:
- name: unused-parameter
disabled: true
issues:
max-per-linter: 0
max-same-issues: 0
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
default_language_version:
python: python3.8
python: python3.10
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.42.1
rev: v1.55.0
hooks:
- id: golangci-lint
4 changes: 2 additions & 2 deletions debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,10 @@ func TestPrefixedDebugger_Assert(t *testing.T) {
}

d := rootDebugger{fail: fail}.Push("FIZZ")
d.Assert(1 == 1, "fizz")
d.Assert(true, "fizz")
Copy link

@mmorel-35 mmorel-35 Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be interested in adding testifylint to golangci linters .

assert.False(t, failed)

d.Assert(1 == 0, "foo")
d.Assert(false, "foo")
assert.True(t, failed)
}

Expand Down
2 changes: 1 addition & 1 deletion enum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestEnum_Extension(t *testing.T) {
// cannot be parallel

e := &enum{desc: &descriptor.EnumDescriptorProto{}}
assert.NotPanics(t, func() { e.Extension(nil, nil) })
assert.NotPanics(t, func() { e.Extension(nil, nil) }) //nolint:errcheck

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's usually a best practice to exclude in golangci lint config file. You can ensure there is no nolint with nolintlint

}

func TestEnum_Accept(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion enum_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestEnumVal_Extension(t *testing.T) {
// cannot be parallel

ev := &enumVal{desc: &descriptor.EnumValueDescriptorProto{}}
assert.NotPanics(t, func() { ev.Extension(nil, nil) })
assert.NotPanics(t, func() { ev.Extension(nil, nil) }) //nolint:errcheck
}

func TestEnumVal_Accept(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestField_Extension(t *testing.T) {
// cannot be parallel

f := &field{desc: &descriptor.FieldDescriptorProto{}}
assert.NotPanics(t, func() { f.Extension(nil, nil) })
assert.NotPanics(t, func() { f.Extension(nil, nil) }) //nolint:errcheck
}

func TestField_Accept(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,34 +195,34 @@ func (f *file) accept(v Visitor) (err error) {
}

if v, err = v.VisitFile(f); err != nil || v == nil {
return
return err
}

for _, e := range f.enums {
if err = e.accept(v); err != nil {
return
return err
}
}

for _, m := range f.msgs {
if err = m.accept(v); err != nil {
return
return err
}
}

for _, s := range f.srvs {
if err = s.accept(v); err != nil {
return
return err
}
}

for _, ext := range f.defExts {
if err = ext.accept(v); err != nil {
return
return err
}
}

return
return err
}

func (f *file) addDefExtension(ext Extension) {
Expand Down
2 changes: 1 addition & 1 deletion file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func TestFile_Extension(t *testing.T) {
assert.NotPanics(t, func() {
(&file{
desc: &descriptor.FileDescriptorProto{},
}).Extension(nil, nil)
}).Extension(nil, nil) //nolint:errcheck
})
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/lyft/protoc-gen-star/v2

go 1.17
go 1.20

require (
github.com/spf13/afero v1.3.3
Expand Down
2 changes: 1 addition & 1 deletion init_option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestDebugEnv(t *testing.T) {
g := &Generator{}
assert.False(t, g.debug)

e := strconv.Itoa(rand.Int())
e := strconv.Itoa(rand.Int()) //nolint:gosec

DebugEnv(e)(g)
assert.False(t, g.debug)
Expand Down
10 changes: 5 additions & 5 deletions lang/go/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (c context) optionPackage(e pgs.Entity) (path, pkg string) {
if idx := strings.LastIndex(pkg, "/"); idx > -1 {
pkg = pkg[idx+1:]
}
return
return path, pkg
}

// check if there's a go_package option specified
Expand All @@ -82,26 +82,26 @@ func (c context) optionPackage(e pgs.Entity) (path, pkg string) {
} else { // no other info, then replace all non-alphanumerics from the input file name
pkg = nonAlphaNumPattern.ReplaceAllString(e.File().InputPath().BaseName(), "_")
}
return
return path, pkg
}

// go_package="example.com/foo/bar;baz" should have a package name of `baz`
if idx := strings.LastIndex(pkg, ";"); idx > -1 {
path = pkg[:idx]
pkg = nonAlphaNumPattern.ReplaceAllString(pkg[idx+1:], "_")
return
return path, pkg
}

// go_package="example.com/foo/bar" should have a package name of `bar`
if idx := strings.LastIndex(pkg, "/"); idx > -1 {
path = pkg
pkg = nonAlphaNumPattern.ReplaceAllString(pkg[idx+1:], "_")
return
return path, pkg
}

pkg = nonAlphaNumPattern.ReplaceAllString(pkg, "_")

return
return path, pkg
}

func (c context) resolveGoPackageOption(e pgs.Entity) string {
Expand Down
14 changes: 7 additions & 7 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,40 +225,40 @@ func (m *msg) accept(v Visitor) (err error) {
}

if v, err = v.VisitMessage(m); err != nil || v == nil {
return
return err
}

for _, e := range m.enums {
if err = e.accept(v); err != nil {
return
return err
}
}

for _, sm := range m.msgs {
if err = sm.accept(v); err != nil {
return
return err
}
}

for _, f := range m.fields {
if err = f.accept(v); err != nil {
return
return err
}
}

for _, o := range m.oneofs {
if err = o.accept(v); err != nil {
return
return err
}
}

for _, ext := range m.defExts {
if err = ext.accept(v); err != nil {
return
return err
}
}

return
return nil
}

func (m *msg) addExtension(ext Extension) {
Expand Down
2 changes: 1 addition & 1 deletion message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func TestMsg_SyntheticOneOfFields_And_RealOneOfs(t *testing.T) {
func TestMsg_Extension(t *testing.T) {
// cannot be parallel
m := &msg{desc: &descriptor.DescriptorProto{}}
assert.NotPanics(t, func() { m.Extension(nil, nil) })
assert.NotPanics(t, func() { m.Extension(nil, nil) }) //nolint:errcheck
}

func TestMsg_Extensions(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestMethod_Extension(t *testing.T) {
// cannot be parallel

m := &method{desc: &descriptor.MethodDescriptorProto{}}
assert.NotPanics(t, func() { m.Extension(nil, nil) })
assert.NotPanics(t, func() { m.Extension(nil, nil) }) //nolint:errcheck
}

func TestMethod_Accept(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions name.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (n Name) Split() (parts []string) {
parts[1] = "_" + parts[1]
return parts[1:]
}
return
return parts
default: // camelCase
buf := &bytes.Buffer{}
var capt, lodash, num bool
Expand Down Expand Up @@ -104,7 +104,7 @@ func (n Name) Split() (parts []string) {
buf.WriteRune(r)
}
parts = append(parts, buf.String())
return
return parts
}
}

Expand Down
2 changes: 1 addition & 1 deletion oneof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestOneof_Extension(t *testing.T) {
// cannot be parallel

o := &oneof{desc: &descriptor.OneofDescriptorProto{}}
assert.NotPanics(t, func() { o.Extension(nil, nil) })
assert.NotPanics(t, func() { o.Extension(nil, nil) }) //nolint:errcheck
}

func TestOneof_Fields(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion persister_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func TestPersister_Persist_GeneratorTemplateAppend(t *testing.T) {
assert.Equal(t, "", resp.File[3].GetName())
assert.Equal(t, "quux", resp.File[3].GetContent())

resp = p.Persist(GeneratorTemplateAppend{
_ = p.Persist(GeneratorTemplateAppend{
FileName: "doesNotExist",
TemplateArtifact: TemplateArtifact{
Template: genTpl,
Expand Down
2 changes: 1 addition & 1 deletion protoc-gen-debug/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func main() {
log.Fatal("unable to create output dir: ", err)
}

err = ioutil.WriteFile(filepath.Join(path, "code_generator_request.pb.bin"), data, 0644)
err = os.WriteFile(filepath.Join(path, "code_generator_request.pb.bin"), data, 0644)
if err != nil {
log.Fatal("unable to write request to disk: ", err)
}
Expand Down
2 changes: 1 addition & 1 deletion service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestService_Extension(t *testing.T) {
// cannot be parallel

s := &service{desc: &descriptor.ServiceDescriptorProto{}}
assert.NotPanics(t, func() { s.Extension(nil, nil) })
assert.NotPanics(t, func() { s.Extension(nil, nil) }) //nolint:errcheck
}

func TestService_Imports(t *testing.T) {
Expand Down
Loading