Skip to content

Commit

Permalink
Update linter
Browse files Browse the repository at this point in the history
  • Loading branch information
ronenh committed Oct 13, 2023
1 parent 296cc87 commit d0a68c1
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 92 deletions.
22 changes: 8 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,17 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install Tools
run: |
mkdir -p $HOME/.ssh
umask 0077 && echo -e "${SSH_PRIVATE_KEY}" > $HOME/.ssh/id_rsa
ssh-keyscan github.com >> $HOME/.ssh/known_hosts
git config --global url."git@github.com:".insteadOf https://github.com/
git config --global user.email "github-bot@aserto.com"
git config --global user.name "Aserto Bot"
eval `ssh-agent`
ssh-add $HOME/.ssh/id_rsa
go run mage.go deps
- name: Lint
run: |
go run mage.go lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.53.2
- name: Test Setup
uses: autero1/action-gotestsum@v2.0.0
with:
gotestsum_version: 1.10.0
- name: Test
run: |
go run mage.go test
gotestsum --format short-verbose -- -count=1 -v -timeout=240s -coverprofile=cover.out -coverpkg=./... ./...
- name: Upload code coverage
uses: shogo82148/actions-goveralls@v1
continue-on-error: true
Expand Down
14 changes: 5 additions & 9 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

linters-settings:
depguard:
list-type: blacklist
packages:
# logging is allowed only by zerolog
- github.com/sirupsen/logrus
packages-with-error-message:
- github.com/sirupsen/logrus: "logging is allowed only by zerolog"
rules:
Main:
deny:
- pkg: github.com/sirupsen/logrus
desc: "logging is allowed only by zerolog"
dupl:
threshold: 100
funlen:
Expand Down Expand Up @@ -69,7 +68,6 @@ linters:
enable:
- asciicheck
- bodyclose
- deadcode
- depguard
- dogsled
- dupl
Expand Down Expand Up @@ -104,14 +102,12 @@ linters:
- revive
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- testpackage
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
- wsl

Expand Down
6 changes: 3 additions & 3 deletions Depfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ bin:
linux-arm64: "e57e719e1eec9bce9057751e2583907210d3ac99c0a01897479506fbb2af828d"
darwin-amd64: "b398481bf33ebf9563cf69d7639014f0d652a2d5e26c0a9a424e2a39bb853354"
darwin-arm64: "20aead134ef8e77cb70efcfe047fc2e381793004fba103e7692b7dab00fe5131"

go:
gotestsum:
importPath: "gotest.tools/gotestsum"
version: "v1.7.0"
version: "v1.10.1"
golangci-lint:
importPath: "github.com/golangci/golangci-lint/cmd/golangci-lint"
version: "v1.46.2"
version: "v1.53.2"
2 changes: 1 addition & 1 deletion authorizer/http/authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (a *authorizer) ListPolicies(

func (a *authorizer) Info(
ctx context.Context,
in *authz.InfoRequest,
_ *authz.InfoRequest,
opts ...grpc.CallOption,
) (*authz.InfoResponse, error) {
var paths []string
Expand Down
36 changes: 17 additions & 19 deletions client/connection_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package client // nolint:testpackage
package client //nolint: testpackage

import (
"bytes"
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestWithAddr(t *testing.T) {
options, err := NewConnectionOptions(WithAddr("address"))
assert.NoError(t, err)

newConnection(context.TODO(), recorder.DialContext, options) // nolint:errcheck
newConnection(context.TODO(), recorder.DialContext, options) //nolint: errcheck

assert.Equal(t, "address", recorder.address)
}
Expand All @@ -73,7 +73,7 @@ func TestWithURL(t *testing.T) {

options, err := NewConnectionOptions(WithURL(svcURL))
assert.NoError(t, err)
newConnection(context.TODO(), recorder.DialContext, options) // nolint:errcheck
newConnection(context.TODO(), recorder.DialContext, options) //nolint: errcheck

assert.Equal(t, URL, recorder.address)
}
Expand All @@ -90,7 +90,7 @@ func TestWithInsecure(t *testing.T) {
recorder := &dialRecorder{}
options, err := NewConnectionOptions(WithInsecure(true))
assert.NoError(t, err)
newConnection(context.TODO(), recorder.DialContext, options) // nolint:errcheck
newConnection(context.TODO(), recorder.DialContext, options) //nolint: errcheck

assert.True(t, recorder.tlsConf.InsecureSkipVerify)
}
Expand All @@ -99,7 +99,7 @@ func TestWithTokenAuth(t *testing.T) {
recorder := &dialRecorder{}
options, err := NewConnectionOptions(WithTokenAuth("<token>"))
assert.NoError(t, err)
newConnection(context.TODO(), recorder.DialContext, options) // nolint:errcheck
newConnection(context.TODO(), recorder.DialContext, options) //nolint: errcheck

md, err := recorder.callerCreds.GetRequestMetadata(context.TODO())
assert.NoError(t, err)
Expand All @@ -113,7 +113,7 @@ func TestWithBearerTokenAuth(t *testing.T) {
recorder := &dialRecorder{}
options, err := NewConnectionOptions(WithTokenAuth("bearer <token>"))
assert.NoError(t, err)
newConnection(context.TODO(), recorder.DialContext, options) // nolint:errcheck
newConnection(context.TODO(), recorder.DialContext, options) //nolint: errcheck

md, err := recorder.callerCreds.GetRequestMetadata(context.TODO())
assert.NoError(t, err)
Expand All @@ -127,7 +127,7 @@ func TestWithAPIKey(t *testing.T) {
recorder := &dialRecorder{}
options, err := NewConnectionOptions(WithAPIKeyAuth("<apikey>"))
assert.NoError(t, err)
newConnection(context.TODO(), recorder.DialContext, options) // nolint:errcheck
newConnection(context.TODO(), recorder.DialContext, options) //nolint: errcheck

md, err := recorder.callerCreds.GetRequestMetadata(context.TODO())
assert.NoError(t, err)
Expand All @@ -142,17 +142,16 @@ func TestTokenAndAPIKey(t *testing.T) {
assert.Error(t, err)
}

// nolint: dupl
func TestWithTenantID(t *testing.T) {
recorder := &dialRecorder{}
options, err := NewConnectionOptions(WithTenantID("<tenantid>"))
assert.NoError(t, err)
newConnection(context.TODO(), recorder.DialContext, options) // nolint:errcheck
newConnection(context.TODO(), recorder.DialContext, options) //nolint: errcheck

assert.Equal(t, "<tenantid>", recorder.connection.TenantID)

ctx := context.TODO()
recorder.connection.unary( // nolint:errcheck
recorder.connection.unary( //nolint: errcheck, dupl
ctx,
"method",
"request",
Expand All @@ -174,7 +173,7 @@ func TestWithTenantID(t *testing.T) {
return nil
})

recorder.connection.stream( // nolint:errcheck
recorder.connection.stream( //nolint: errcheck
ctx,
nil,
recorder.connection.Conn.(*grpc.ClientConn),
Expand All @@ -201,17 +200,16 @@ func TestWithTenantID(t *testing.T) {
)
}

// nolint: dupl
func TestWithSessionID(t *testing.T) {
recorder := &dialRecorder{}
options, err := NewConnectionOptions(WithSessionID("<sessionid>"))
assert.NoError(t, err)
newConnection(context.TODO(), recorder.DialContext, options) // nolint:errcheck
newConnection(context.TODO(), recorder.DialContext, options) //nolint: errcheck

assert.Equal(t, "<sessionid>", recorder.connection.SessionID)

ctx := context.TODO()
recorder.connection.unary( // nolint:errcheck
recorder.connection.unary( //nolint: errcheck, dupl
ctx,
"method",
"request",
Expand All @@ -233,7 +231,7 @@ func TestWithSessionID(t *testing.T) {
return nil
})

recorder.connection.stream( // nolint:errcheck
recorder.connection.stream( //nolint: errcheck
ctx,
nil,
recorder.connection.Conn.(*grpc.ClientConn),
Expand Down Expand Up @@ -280,7 +278,7 @@ func TestWithCACertPath(t *testing.T) {
recorder := &dialRecorder{}
options, err := NewConnectionOptions(WithCACertPath(caPath))
assert.NoError(t, err)
newConnection(context.TODO(), recorder.DialContext, options) // nolint:errcheck
newConnection(context.TODO(), recorder.DialContext, options) //nolint: errcheck

inPool, err := subjectInCertPool(recorder.tlsConf.RootCAs, CertSubjectName)
if err != nil {
Expand Down Expand Up @@ -308,7 +306,7 @@ func TestWithCACertPathAndInsecure(t *testing.T) {
recorder := &dialRecorder{}
options, err := NewConnectionOptions(WithCACertPath(caPath), WithInsecure(true))
assert.NoError(t, err)
newConnection(context.TODO(), recorder.DialContext, options) // nolint:errcheck
newConnection(context.TODO(), recorder.DialContext, options) //nolint: errcheck

assert.Nil(t, recorder.tlsConf.RootCAs, "Aserto cert should be nil")
assert.True(t, recorder.tlsConf.InsecureSkipVerify)
Expand All @@ -320,7 +318,7 @@ func TestWithDialOptions(t *testing.T) {

options, err := NewConnectionOptions(WithDialOptions(creds))
assert.NoError(t, err)
newConnection(context.TODO(), recorder.DialContext, options) // nolint:errcheck
newConnection(context.TODO(), recorder.DialContext, options) //nolint: errcheck
assert.Contains(t, recorder.dialOptions, creds)
}

Expand Down Expand Up @@ -369,7 +367,7 @@ func publicKey(priv interface{}) interface{} {
}

func subjectInCertPool(pool *x509.CertPool, name string) (bool, error) {
for _, subject := range pool.Subjects() {
for _, subject := range pool.Subjects() { //nolint: staticcheck
var rdns pkix.RDNSequence

_, err := asn1.Unmarshal(subject, &rdns)
Expand Down
2 changes: 1 addition & 1 deletion client/directory/internal/connections_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal // nolint:testpackage
package internal //nolint: testpackage

import (
"context"
Expand Down
6 changes: 3 additions & 3 deletions client/directory/v2/config_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package directory // nolint:testpackage
package directory //nolint: testpackage

import (
"context"
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestUnmarshalConfig(t *testing.T) {
func TestConnect(t *testing.T) {
ctx := context.Background()

t.Run("base only", func(t *testing.T) { // nolint:dupl
t.Run("base only", func(t *testing.T) { //nolint: dupl
assert := asserts.New(t)

conns, counter := mockConns()
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestConnect(t *testing.T) {
assert.Equal(2, counter.Count)
})

t.Run("no base", func(t *testing.T) { // nolint:dupl
t.Run("no base", func(t *testing.T) { //nolint: dupl
assert := asserts.New(t)

conns, counter := mockConns()
Expand Down
4 changes: 2 additions & 2 deletions client/internal/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewTokenAuth(token string) *TokenAuth {
}
}

func (t TokenAuth) GetRequestMetadata(ctx context.Context, in ...string) (map[string]string, error) {
func (t TokenAuth) GetRequestMetadata(_ context.Context, _ ...string) (map[string]string, error) {
return map[string]string{
Authorization: t.token,
}, nil
Expand All @@ -48,7 +48,7 @@ func NewAPIKeyAuth(key string) *APIKeyAuth {
}
}

func (k *APIKeyAuth) GetRequestMetadata(ctx context.Context, in ...string) (map[string]string, error) {
func (k *APIKeyAuth) GetRequestMetadata(_ context.Context, _ ...string) (map[string]string, error) {
return map[string]string{
Authorization: Basic + " " + k.key,
}, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/tlsconf/tls_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TLSConfig(insecure bool, caCertPath string) (*tls.Config, error) {
)

if insecure {
tlsConf.InsecureSkipVerify = true
tlsConf.InsecureSkipVerify = true //nolint: gosec
return &tlsConf, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/tlsconf/tls_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TLSConfig(insecure bool, caCertPath string) (*tls.Config, error) {
)

if insecure {
tlsConf.InsecureSkipVerify = true
tlsConf.InsecureSkipVerify = true //nolint: gosec
return &tlsConf, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/tlsconf/tls_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TLSConfig(insecure bool, caCertPath string) (*tls.Config, error) {
var tlsConf tls.Config

if insecure {
tlsConf.InsecureSkipVerify = true
tlsConf.InsecureSkipVerify = true //nolint: gosec
return &tlsConf, nil
}

Expand Down
10 changes: 1 addition & 9 deletions middleware/grpc/identity_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package grpc // nolint:testpackage // Testing unexported method .build()
package grpc //nolint: testpackage // Testing unexported method .build()

import (
"context"
Expand All @@ -7,7 +7,6 @@ import (
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/metadata"

"github.com/aserto-dev/go-aserto/middleware"
"github.com/aserto-dev/go-authorizer/aserto/authorizer/v2/api"
)

Expand Down Expand Up @@ -133,10 +132,3 @@ func TestMissingContextValue(t *testing.T) {
"Missing context value should result in anonymous identity",
)
}

func TestIdentityMapper(t *testing.T) {
builder := &IdentityBuilder{}
builder.None().Mapper(func(ctx context.Context, _ interface{}, id middleware.Identity) {
id.Subject().ID("george")
})
}
4 changes: 2 additions & 2 deletions middleware/http/ginz/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (m *Middleware) Handler(c *gin.Context) {

resource, err := m.resourceContext(c)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err) // nolint:errcheck
c.AbortWithError(http.StatusInternalServerError, err) //nolint: errcheck
return
}

Expand All @@ -100,7 +100,7 @@ func (m *Middleware) Handler(c *gin.Context) {
c.AbortWithStatus(http.StatusForbidden)
}
} else {
c.AbortWithError(http.StatusInternalServerError, err) // nolint:errcheck
c.AbortWithError(http.StatusInternalServerError, err) //nolint: errcheck
}
}

Expand Down
2 changes: 1 addition & 1 deletion middleware/http/identity_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package http // nolint:testpackage // testing unexported logic
package http //nolint: testpackage // testing unexported logic

import (
"testing"
Expand Down
Loading

0 comments on commit d0a68c1

Please sign in to comment.