Skip to content

Commit

Permalink
Refactor lint errors exhaustive, noglobals (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
p53 authored Feb 8, 2025
1 parent f762116 commit 0936ad6
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 10 deletions.
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ linters:
- nlreturn
- noctx
- paralleltest
- exhaustive
- exhaustruct
- tagliatelle
- err113
- gochecknoglobals
- dupl
- wsl
# TODO: Revisit after the refactor
Expand Down
4 changes: 1 addition & 3 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"crypto/rand"
"fmt"
"math/big"
"net"
"net/http"
Expand Down Expand Up @@ -71,10 +70,9 @@ const (
postLoginRedirectPath = "/post/login/path"
pkceCookieName = "TESTPKCECOOKIE"
umaCookieName = "TESTUMACOOKIE"
idpRealmURI = idpURI + "/realms/" + testRealm
)

var idpRealmURI = fmt.Sprintf("%s/realms/%s", idpURI, testRealm)

func generateRandomPort() (string, error) {
var minPort int64 = 1024
var maxPort int64 = 65000
Expand Down
4 changes: 2 additions & 2 deletions pkg/authorization/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,10 @@ func TestIsValid(t *testing.T) {
}
}

var expectedRoles = []string{"1", "2", "3"}

const rolesList = "1,2,3"

func TestResourceString(t *testing.T) {
expectedRoles := []string{"1", "2", "3"}
resource := &authorization.Resource{
Roles: expectedRoles,
}
Expand All @@ -239,6 +238,7 @@ func TestResourceString(t *testing.T) {
}

func TestGetRoles(t *testing.T) {
expectedRoles := []string{"1", "2", "3"}
resource := &authorization.Resource{
Roles: expectedRoles,
}
Expand Down
1 change: 1 addition & 0 deletions pkg/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,5 @@ const (
TLS12 = "tlsv1.2"
)

//nolint:gochecknoglobals
var SignatureAlgs = [3]jose.SignatureAlgorithm{jose.RS256, jose.HS256, jose.HS512}
1 change: 1 addition & 0 deletions pkg/encryption/text_encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/require"
)

//nolint:gochecknoglobals
var (
fakePlainText = []byte(`nFlhnhwRzC9uJ9mjhR0PQezUpIiDlU9ASLqH1KIKFhBZZrMZfnAAdHdgKs2OJoni8cTSQ
JxkaNpboZ6hnrMytlw5kf0biF7dLTU885uHIGkUIRy75hx6BaTEEhbN36qVTxediEHd6xeBPS3qpJ7riO6J
Expand Down
2 changes: 1 addition & 1 deletion pkg/keycloak/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/gogatekeeper/gatekeeper/pkg/constant"
)

var (
const (
fakeAdminRoleURL = "/admin*"
fakeAdminRole = "role:admin"
fakeTestAdminRolesURL = "/test_admin_roles"
Expand Down
2 changes: 2 additions & 0 deletions pkg/proxy/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func getCommandLineOptions(cfg core.Configs) []cli.Flag {

optName := field.Tag.Get("yaml")

//nolint:exhaustive
switch fType := field.Type; fType.Kind() {
case reflect.Bool:
dv := reflect.ValueOf(cfg).Elem().FieldByName(field.Name).Bool()
Expand Down Expand Up @@ -214,6 +215,7 @@ func parseCLIOptions(cliCtx *cli.Context, config core.Configs) error {
}

if cliCtx.IsSet(name) {
//nolint:exhaustive
switch field.Type.Kind() {
case reflect.Bool:
reflect.ValueOf(config).Elem().FieldByName(field.Name).SetBool(cliCtx.Bool(name))
Expand Down
1 change: 1 addition & 0 deletions pkg/proxy/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type (
GoogleProvider string
)

//nolint:gochecknoglobals
var (
release = ""
gitsha = "no gitsha provided"
Expand Down
1 change: 1 addition & 0 deletions pkg/proxy/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metrics

import "github.com/prometheus/client_golang/prometheus"

//nolint:gochecknoglobals
var (
CertificateRotationMetric = prometheus.NewCounter(
prometheus.CounterOpts{
Expand Down
4 changes: 2 additions & 2 deletions pkg/testsuite/fake_authserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type DefaultTestTokenClaims struct {
Authorization models.Permissions `json:"authorization"`
}

//nolint:gochecknoglobals
var defTestTokenClaims = DefaultTestTokenClaims{
Aud: "test",
Azp: "clientid",
Expand Down Expand Up @@ -281,8 +282,6 @@ type fakeOidcDiscoveryResponse struct {
Algorithms []string `json:"id_token_signing_alg_values_supported"`
}

var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

type fakeAuthConfig struct {
DiscoveryURLPrefix string
Expiration time.Duration
Expand Down Expand Up @@ -734,6 +733,7 @@ func (r *fakeAuthServer) PermissionTicketHandler(wrt http.ResponseWriter, _ *htt
}

func getRandomString(n int) (string, error) {
letterRunes := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
runes := make([]rune, n)
for idx := range runes {
num, err := rand.Int(rand.Reader, big.NewInt(int64(n)))
Expand Down
1 change: 1 addition & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/urfave/cli/v2"
)

//nolint:gochecknoglobals
var (
AllHTTPMethods = []string{
http.MethodDelete,
Expand Down

0 comments on commit 0936ad6

Please sign in to comment.