Skip to content

Commit

Permalink
Enable stylecheck lint rule
Browse files Browse the repository at this point in the history
This lint rule has some pretty good checks - for example the "error
strings shouldn't be capitalized", so we can always log errors
properly, or "duplicate imports" that make the code look more complex
than it is.

However, to enable it required me to search replace all sorts of
things to capitalize them: Url with URL, Uri with URI, Http with HTTP,
Json with JSON, etc.
  • Loading branch information
Robin Sonefors committed Sep 14, 2022
1 parent a3a7ef8 commit fe7aac4
Show file tree
Hide file tree
Showing 66 changed files with 544 additions and 553 deletions.
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ run:
linters:
enable:
- wsl
- stylecheck

linters-settings: {}
6 changes: 3 additions & 3 deletions cmd/gitops-server/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func runCmd(cmd *cobra.Command, args []string) error {

namespace, _, err := kubeConfig.Namespace()
if err != nil {
return fmt.Errorf("Couldn't get current namespace")
return fmt.Errorf("couldn't get current namespace")
}

authServer, err := auth.InitAuthServer(cmd.Context(), log, rawClient, options.OIDC, options.OIDCSecret, namespace, options.AuthMethods)
Expand Down Expand Up @@ -269,12 +269,12 @@ func runCmd(cmd *cobra.Command, args []string) error {
}()

if err := srv.Shutdown(ctx); err != nil {
return fmt.Errorf("Server shutdown failed: %w", err)
return fmt.Errorf("server shutdown failed: %w", err)
}

if options.EnableMetrics {
if err := metricsServer.Shutdown(ctx); err != nil {
return fmt.Errorf("Metrics server shutdown failed: %w", err)
return fmt.Errorf("metrics server shutdown failed: %w", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/gitops/version/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
)

// The current wego version
// Version is the current wego version
var Version = "v0.0.0"
var GitCommit = ""
var Branch = ""
Expand Down
21 changes: 10 additions & 11 deletions core/clustersmngr/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/rand"

Expand Down Expand Up @@ -42,7 +41,7 @@ func TestClientGet(t *testing.T) {
clustersClient := clustersmngr.NewClient(clientsPool, nsMap)

kust := &kustomizev1.Kustomization{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: appName,
Namespace: ns.Name,
},
Expand Down Expand Up @@ -78,7 +77,7 @@ func TestClientClusteredList(t *testing.T) {
clustersClient := clustersmngr.NewClient(clientsPool, nsMap)

kust := &kustomizev1.Kustomization{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: appName,
Namespace: ns.Name,
},
Expand All @@ -103,7 +102,7 @@ func TestClientClusteredList(t *testing.T) {
g.Expect(klist.Items[0].Name).To(Equal(appName))

gitRepo := &sourcev1.GitRepository{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: appName,
Namespace: ns.Name,
},
Expand Down Expand Up @@ -139,7 +138,7 @@ func TestClientClusteredListPagination(t *testing.T) {

createKust := func(name string, nsName string) {
kust := &kustomizev1.Kustomization{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: nsName,
},
Expand Down Expand Up @@ -215,7 +214,7 @@ func TestClientClusteredListClusterScoped(t *testing.T) {

clustersClient := clustersmngr.NewClient(clientsPool, nsMap)
clusterRole := rbacv1.ClusterRole{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: appName,
},
Rules: []rbacv1.PolicyRule{
Expand Down Expand Up @@ -289,7 +288,7 @@ func TestClientList(t *testing.T) {
clustersClient := clustersmngr.NewClient(clientsPool, nsMap)

kust := &kustomizev1.Kustomization{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: appName,
Namespace: ns.Name,
},
Expand Down Expand Up @@ -326,7 +325,7 @@ func TestClientCreate(t *testing.T) {
clustersClient := clustersmngr.NewClient(clientsPool, nsMap)

kust := &kustomizev1.Kustomization{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: appName,
Namespace: ns.Name,
},
Expand Down Expand Up @@ -361,7 +360,7 @@ func TestClientDelete(t *testing.T) {
clustersClient := clustersmngr.NewClient(clientsPool, nsMap)

kust := &kustomizev1.Kustomization{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: appName,
Namespace: ns.Name,
},
Expand Down Expand Up @@ -394,7 +393,7 @@ func TestClientUpdate(t *testing.T) {
clustersClient := clustersmngr.NewClient(clientsPool, nsMap)

kust := &kustomizev1.Kustomization{
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: appName,
Namespace: ns.Name,
},
Expand Down Expand Up @@ -436,7 +435,7 @@ func TestClientPatch(t *testing.T) {
Kind: kustomizev1.KustomizationKind,
APIVersion: kustomizev1.GroupVersion.String(),
},
ObjectMeta: v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: appName,
Namespace: ns.Name,
},
Expand Down
2 changes: 1 addition & 1 deletion core/clustersmngr/clustersmngr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestClientConfigWithUser(t *testing.T) {
{
name: "No token or user Id should error",
principal: &auth.UserPrincipal{},
expectedErr: fmt.Errorf("No user ID or Token found in UserPrincipal."),
expectedErr: fmt.Errorf("no user ID or Token found in UserPrincipal"),
expectedToken: "",
expectedImpersonation: nil,
},
Expand Down
2 changes: 1 addition & 1 deletion core/clustersmngr/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func ClientConfigWithUser(user *auth.UserPrincipal, options ...KubeConfigOption)
config := restConfigFromCluster(cluster)

if !user.Valid() {
return nil, fmt.Errorf("No user ID or Token found in UserPrincipal.")
return nil, fmt.Errorf("no user ID or Token found in UserPrincipal")
} else if tok := user.Token(); tok != "" {
config.BearerToken = tok
} else {
Expand Down
2 changes: 1 addition & 1 deletion core/clustersmngr/factory_caches.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,6 @@ func (un *UsersNamespaces) Clear() {
un.Cache.Clear()
}

func (u UsersNamespaces) cacheKey(user *auth.UserPrincipal, cluster string) uint64 {
func (un UsersNamespaces) cacheKey(user *auth.UserPrincipal, cluster string) uint64 {
return ttlcache.StringKey(fmt.Sprintf("%s:%s", user.ID, cluster))
}
10 changes: 4 additions & 6 deletions core/server/fluxruntime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import (
. "github.com/onsi/gomega"
"github.com/weaveworks/weave-gitops/core/clustersmngr"
"github.com/weaveworks/weave-gitops/core/server"
coretypes "github.com/weaveworks/weave-gitops/core/server/types"
stypes "github.com/weaveworks/weave-gitops/core/server/types"
pb "github.com/weaveworks/weave-gitops/pkg/api/core"
"github.com/weaveworks/weave-gitops/pkg/kube"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -182,7 +180,7 @@ func TestListFluxRuntimeObjects(t *testing.T) {
k, err := kube.NewKubeHTTPClientWithConfig(k8sEnv.Rest, "")
g.Expect(err).NotTo(HaveOccurred())

nss := &v1.Namespace{}
nss := &corev1.Namespace{}
nss.Name = "ns1"
g.Expect(k.Create(ctx, nss)).To(Succeed())

Expand All @@ -193,7 +191,7 @@ func TestListFluxRuntimeObjects(t *testing.T) {
g.Expect(res.Errors[0].Namespace).To(BeEmpty())
g.Expect(res.Errors[0].ClusterName).To(Equal(clustersmngr.DefaultCluster))

fluxNs := &v1.Namespace{}
fluxNs := &corev1.Namespace{}
fluxNs.Name = "flux-ns"
fluxNs.Labels = map[string]string{
stypes.PartOfLabel: server.FluxNamespacePartOf,
Expand Down Expand Up @@ -256,15 +254,15 @@ func TestListFluxCrds(t *testing.T) {

crd1 := &apiextensions.CustomResourceDefinition{ObjectMeta: metav1.ObjectMeta{
Name: "crd1",
Labels: map[string]string{coretypes.PartOfLabel: "flux"},
Labels: map[string]string{stypes.PartOfLabel: "flux"},
}, Spec: apiextensions.CustomResourceDefinitionSpec{
Group: "group",
Names: apiextensions.CustomResourceDefinitionNames{Plural: "plural", Kind: "kind"},
Versions: []apiextensions.CustomResourceDefinitionVersion{},
}}
crd2 := &apiextensions.CustomResourceDefinition{ObjectMeta: metav1.ObjectMeta{
Name: "crd2",
Labels: map[string]string{coretypes.PartOfLabel: "flux"},
Labels: map[string]string{stypes.PartOfLabel: "flux"},
}, Spec: apiextensions.CustomResourceDefinitionSpec{
Group: "group",
Versions: []apiextensions.CustomResourceDefinitionVersion{{Name: "0"}},
Expand Down
3 changes: 1 addition & 2 deletions core/server/helm_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"io"
"strings"

"github.com/fluxcd/helm-controller/api/v2beta1"
helmv2 "github.com/fluxcd/helm-controller/api/v2beta1"
"github.com/fluxcd/pkg/ssa"
"github.com/hashicorp/go-multierror"
Expand Down Expand Up @@ -110,7 +109,7 @@ func (cs *coreServer) GetHelmRelease(ctx context.Context, msg *pb.GetHelmRelease
}, err
}

func getHelmReleaseInventory(ctx context.Context, helmRelease v2beta1.HelmRelease, c clustersmngr.Client, cluster string) ([]*pb.GroupVersionKind, error) {
func getHelmReleaseInventory(ctx context.Context, helmRelease helmv2.HelmRelease, c clustersmngr.Client, cluster string) ([]*pb.GroupVersionKind, error) {
storageNamespace := helmRelease.GetStorageNamespace()

storageName := helmRelease.GetReleaseName()
Expand Down
Loading

0 comments on commit fe7aac4

Please sign in to comment.