Skip to content

Commit

Permalink
Add more golangci linters and fix warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrt committed Apr 3, 2022
1 parent e21807f commit 16b9e23
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
5 changes: 4 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ linters:
enable:
- deadcode
- errcheck
- errname
- errorlint
- gocritic
- gofmt
- golint
- gosec
- gosimple
- govet
- ineffassign
- misspell
- revive
- staticcheck
- structcheck
- unconvert
- unused
- varcheck
3 changes: 2 additions & 1 deletion cmd/gmailctl/cmd/edit_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ func spawnEditor(path string) error {
if err == nil {
return nil
}
if _, ok := err.(*exec.ExitError); ok {
var exitErr *exec.ExitError
if errors.As(err, exitErr) {
return errAbort
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type FetchAPI interface {
func FromAPI(api FetchAPI) (GmailConfig, error) {
l, err := api.ListLabels()
if err != nil {
return GmailConfig{}, fmt.Errorf("listing labels from Gmail: %v", err)
return GmailConfig{}, fmt.Errorf("listing labels from Gmail: %w", err)
}
f, err := api.ListFilters()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/export/xml/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewWithTime(now func() time.Time) Exporter {
return Exporter{now}
}

var defaultNow func() time.Time = time.Now
var defaultNow = time.Now

type xmlDoc struct {
XMLName xml.Name `xml:"feed"`
Expand Down
3 changes: 2 additions & 1 deletion internal/engine/rimport/jsonnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"encoding/json"
"errors"
"io"
"regexp"
)
Expand Down Expand Up @@ -54,7 +55,7 @@ func MarshalJsonnet(v interface{}, w io.Writer, header string) error {
line, _, err = reader.ReadLine()
}

if err == io.EOF {
if errors.Is(err, io.EOF) {
return writer.Flush()
}
return err
Expand Down
10 changes: 5 additions & 5 deletions internal/errors/err_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ import (
"github.com/stretchr/testify/assert"
)

type errType struct {
type someError struct {
a int
}

func (errType) Error() string { return "errType" }
func (someError) Error() string { return "someError" }

func TestAnnotated(t *testing.T) {
err1 := errors.New("error1")
err2 := errType{3}
err2 := someError{3}
wrapped := WithCause(err2, err1)

// The error is both err1 and err2
assert.Equal(t, "error1: errType", wrapped.Error())
assert.Equal(t, "error1: someError", wrapped.Error())
assert.True(t, errors.Is(wrapped, err1))
assert.True(t, errors.Is(wrapped, err2))

// Contents are preserved.
var et errType
var et someError
assert.True(t, errors.As(wrapped, &et))
assert.Equal(t, err2, et)

Expand Down

0 comments on commit 16b9e23

Please sign in to comment.