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

chore(linter): enable errorlint #1235

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions .golangci.yml
Expand Up @@ -17,6 +17,7 @@ linters:
- dogsled
- dupl
- durationcheck
- errorlint
- exhaustive
- exportloopref
- gci
Expand Down
5 changes: 3 additions & 2 deletions internal/encoding/decoder_test.go
@@ -1,6 +1,7 @@
package encoding

import (
"errors"
"testing"
)

Expand Down Expand Up @@ -34,7 +35,7 @@ func TestDecoderRegistry_RegisterDecoder(t *testing.T) {
}

err = registry.RegisterDecoder("myformat", decoder{})
if err != ErrDecoderFormatAlreadyRegistered {
if !errors.Is(err, ErrDecoderFormatAlreadyRegistered) {
t.Fatalf("expected ErrDecoderFormatAlreadyRegistered, got: %v", err)
}
})
Expand Down Expand Up @@ -70,7 +71,7 @@ func TestDecoderRegistry_Decode(t *testing.T) {
var v string

err := registry.Decode("myformat", []byte("some value"), &v)
if err != ErrDecoderNotFound {
if !errors.Is(err, ErrDecoderNotFound) {
t.Fatalf("expected ErrDecoderNotFound, got: %v", err)
}
})
Expand Down
5 changes: 3 additions & 2 deletions internal/encoding/encoder_test.go
@@ -1,6 +1,7 @@
package encoding

import (
"errors"
"testing"
)

Expand Down Expand Up @@ -31,7 +32,7 @@ func TestEncoderRegistry_RegisterEncoder(t *testing.T) {
}

err = registry.RegisterEncoder("myformat", encoder{})
if err != ErrEncoderFormatAlreadyRegistered {
if !errors.Is(err, ErrEncoderFormatAlreadyRegistered) {
t.Fatalf("expected ErrEncoderFormatAlreadyRegistered, got: %v", err)
}
})
Expand Down Expand Up @@ -63,7 +64,7 @@ func TestEncoderRegistry_Decode(t *testing.T) {
registry := NewEncoderRegistry()

_, err := registry.Encode("myformat", "some value")
if err != ErrEncoderNotFound {
if !errors.Is(err, ErrEncoderNotFound) {
t.Fatalf("expected ErrEncoderNotFound, got: %v", err)
}
})
Expand Down
7 changes: 5 additions & 2 deletions viper_test.go
Expand Up @@ -8,6 +8,7 @@ package viper
import (
"bytes"
"encoding/json"
"errors"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -1840,7 +1841,8 @@ func TestSafeWriteConfigWithExistingFile(t *testing.T) {
v.SetConfigType("yaml")
err := v.SafeWriteConfig()
require.Error(t, err)
_, ok := err.(ConfigFileAlreadyExistsError)
var cfaeErr ConfigFileAlreadyExistsError
ok := errors.As(err, &cfaeErr)
assert.True(t, ok, "Expected ConfigFileAlreadyExistsError")
}

Expand All @@ -1865,7 +1867,8 @@ func TestSafeWriteConfigAsWithExistingFile(t *testing.T) {
v.SetFs(fs)
err := v.SafeWriteConfigAs("/test/c.yaml")
require.Error(t, err)
_, ok := err.(ConfigFileAlreadyExistsError)
var cfaeErr ConfigFileAlreadyExistsError
ok := errors.As(err, &cfaeErr)
assert.True(t, ok, "Expected ConfigFileAlreadyExistsError")
}

Expand Down