Enable more golangci-lint rules (#227)

* WIP

* Enable `paralleltest` linter

* Enable `perfsprint` linter
This commit is contained in:
Joshua Spence
2024-11-22 17:37:44 +11:00
committed by GitHub
parent 53b7fc278f
commit 7ebc6da3f8
8 changed files with 27 additions and 9 deletions

View File

@@ -3,6 +3,8 @@ linters:
enable-all: true
disable:
- 'depguard'
- 'mnd'
- 'nlreturn'
- 'tagliatelle'
# Temporary
@@ -21,11 +23,7 @@ linters:
- 'gosec'
- 'lll'
- 'maintidx'
- 'mnd'
- 'nestif'
- 'nlreturn'
- 'paralleltest'
- 'perfsprint'
- 'revive'
- 'stylecheck'
- 'varnamelen'

View File

@@ -54,7 +54,7 @@ func downloadJar(url *url.URL, outputDir string) (string, error) {
}
}
if uncompressedReader == nil {
return "", fmt.Errorf("unable to find .deb data file")
return "", errors.New("unable to find .deb data file")
}
tarReader := tar.NewReader(uncompressedReader)
@@ -86,7 +86,7 @@ func downloadJar(url *url.URL, outputDir string) (string, error) {
}
if aceJar == nil {
return "", fmt.Errorf("unable to find ace.jar")
return "", errors.New("unable to find ace.jar")
}
defer aceJar.Close()

View File

@@ -9,6 +9,8 @@ import (
)
func TestFieldInfoFromValidation(t *testing.T) {
t.Parallel()
for i, c := range []struct {
expectedType string
expectedComment string
@@ -32,6 +34,8 @@ func TestFieldInfoFromValidation(t *testing.T) {
{"bool", "", false, "true|false"},
} {
t.Run(fmt.Sprintf("%d %s %s", i, c.expectedType, c.validation), func(t *testing.T) {
t.Parallel()
resource := &Resource{
StructName: "TestType",
Types: make(map[string]*FieldInfo),
@@ -57,6 +61,8 @@ func TestFieldInfoFromValidation(t *testing.T) {
}
func TestResourceTypes(t *testing.T) {
t.Parallel()
testData := `
{
"note": ".{0,1024}",
@@ -147,6 +153,8 @@ func TestResourceTypes(t *testing.T) {
}
t.Run("structural test", func(t *testing.T) {
t.Parallel()
resource := NewResource("Struct", "path")
resource.FieldProcessor = expectation.FieldProcessor

View File

@@ -13,6 +13,8 @@ import (
)
func TestLatestUnifiVersion(t *testing.T) {
t.Parallel()
assert := assert.New(t)
require := require.New(t)

View File

@@ -9,6 +9,8 @@ import (
)
func TestAccountMarshalJSON(t *testing.T) {
t.Parallel()
for n, c := range map[string]struct {
expectedJSON string
acc unifi.Account
@@ -27,6 +29,8 @@ func TestAccountMarshalJSON(t *testing.T) {
},
} {
t.Run(n, func(t *testing.T) {
t.Parallel()
actual, err := json.Marshal(&c.acc)
if err != nil {
t.Fatal(err)

View File

@@ -9,6 +9,8 @@ import (
)
func TestNetworkUnmarshalJSON(t *testing.T) {
t.Parallel()
for n, c := range map[string]struct {
expected func(n *unifi.Network)
json string
@@ -66,6 +68,8 @@ func TestNetworkUnmarshalJSON(t *testing.T) {
},
} {
t.Run(n, func(t *testing.T) {
t.Parallel()
// set some non-zero value defaults
expected := unifi.Network{
InternetAccessEnabled: true,

View File

@@ -1,9 +1,10 @@
package unifi //
package unifi
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
@@ -183,7 +184,7 @@ func (c *Client) Login(ctx context.Context, user, pass string) error {
c.version = si.Version
if c.version == "" {
return fmt.Errorf("unable to determine controller version")
return errors.New("unable to determine controller version")
}
return nil

View File

@@ -2,6 +2,7 @@ package unifi
import (
"context"
"errors"
"fmt"
)
@@ -54,7 +55,7 @@ func (c *Client) CreateUser(ctx context.Context, site string, d *User) (*User, e
}
if len(respBody.Data) != 1 {
return nil, fmt.Errorf("malformed group response")
return nil, errors.New("malformed group response")
}
if err := respBody.Data[0].Meta.error(); err != nil {