Skip to content

Commit

Permalink
fix: Enable more linters
Browse files Browse the repository at this point in the history
Signed-off-by: Mateus Oliveira <[email protected]>
  • Loading branch information
mateusoliveira43 committed Mar 1, 2024
1 parent 065eed6 commit 32722ec
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 45 deletions.
121 changes: 99 additions & 22 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,117 @@
# Documentation reference https://github.com/golangci/golangci-lint/blob/v1.56.2/.golangci.reference.yml
run:
deadline: 5m
allow-parallel-runners: true
skip-dirs-use-default: false
modules-download-mode: readonly
allow-parallel-runners: false

output:
format: colored-line-number
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
sort-results: true

linters-settings:
dogsled:
max-blank-identifiers: 2
errcheck:
check-type-assertions: true
check-blank: true
gci:
sections:
- standard
- default
- prefix(github.com/migtools/oadp-non-admin)
goconst:
min-len: 3
min-occurrences: 5
gofmt:
simplify: true
goheader:
# copy from ./hack/boilerplate.go.txt
template: |-
Copyright 2024.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
govet:
enable-all: true
misspell:
locale: US
nakedret:
max-func-lines: 30
nolintlint:
allow-unused: false
allow-no-explanation: []
require-explanation: true
require-specific: true
revive:
enable-all-rules: true
rules:
- name: line-length-limit
disabled: true
unparam:
check-exported: true

issues:
# don't skip warning about doc comments
# don't exclude the default set of lint
exclude-use-default: false
# restore some of the defaults
# (fill in the rest as needed)
exclude-rules:
- path: "api/*"
linters:
- lll
- path: "internal/*"
linters:
- dupl
- lll
linters:
disable-all: true
enable:
- dupl
- asasalint
- asciicheck
- bidichk
- bodyclose
- dogsled
- dupword
- durationcheck
- errcheck
- errchkjson
- exportloopref
- gci
- ginkgolinter
- goconst
- gocyclo
- gofmt
- goimports
- goheader
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- prealloc
- nilerr
- noctx
- nolintlint
- nosprintfhostport
- revive
- staticcheck
- typecheck
- stylecheck
- unconvert
- unparam
- unused
- usestdlibvars
fast: false

issues:
exclude-use-default: false
exclude-rules:
- linters:
- revive
text: "^struct-tag: unknown option 'inline' in JSON tag$"
- linters:
- stylecheck
text: "ST1000:|ST1020:|ST1021:|ST1022:"
max-issues-per-linter: 0
max-same-issues: 0

severity:
default-severity: error
case-sensitive: false
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
KUSTOMIZE_VERSION ?= v5.3.0
CONTROLLER_TOOLS_VERSION ?= v0.14.0
ENVTEST_VERSION ?= latest
GOLANGCI_LINT_VERSION ?= v1.54.2
GOLANGCI_LINT_VERSION ?= v1.56.2

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
Expand Down
9 changes: 3 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ import (
"os"

velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"

"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
Expand All @@ -38,7 +36,6 @@ import (

nacv1alpha1 "github.com/migtools/oadp-non-admin/api/v1alpha1"
"github.com/migtools/oadp-non-admin/internal/controller"
//+kubebuilder:scaffold:imports
)

var (
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/common_nab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"testing"

nacv1alpha1 "github.com/migtools/oadp-non-admin/api/v1alpha1"
"github.com/stretchr/testify/assert"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"

nacv1alpha1 "github.com/migtools/oadp-non-admin/api/v1alpha1"
)

func TestGetVeleroBackupSpecFromNonAdminBackup(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/common_velero.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"fmt"

velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

nacv1alpha1 "github.com/migtools/oadp-non-admin/api/v1alpha1"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
)

func HasRequiredLabel(backup *velerov1api.Backup) bool {
Expand Down
5 changes: 2 additions & 3 deletions internal/controller/common_velero_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import (
"testing"

"github.com/stretchr/testify/assert"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

nacv1alpha1 "github.com/migtools/oadp-non-admin/api/v1alpha1"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
)

func TestGetNonAdminFromBackup(t *testing.T) {
Expand Down
7 changes: 3 additions & 4 deletions internal/controller/nonadminbackup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ import (
"context"

"github.com/go-logr/logr"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/log"

nacv1alpha1 "github.com/migtools/oadp-non-admin/api/v1alpha1"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NonAdminBackupReconciler reconciles a NonAdminBackup object
Expand Down
3 changes: 1 addition & 2 deletions internal/controller/nonadminbackup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

nacv1alpha1 "github.com/migtools/oadp-non-admin/api/v1alpha1"
)

Expand Down
2 changes: 0 additions & 2 deletions internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -33,7 +32,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"

nacv1alpha1 "github.com/migtools/oadp-non-admin/api/v1alpha1"
//+kubebuilder:scaffold:imports
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
Expand Down
3 changes: 1 addition & 2 deletions internal/controller/velerobackup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ import (
"context"

"github.com/go-logr/logr"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
)

// VeleroBackupReconciler reconciles a VeleroBackup object
Expand Down
2 changes: 1 addition & 1 deletion test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"os/exec"
"strings"

. "github.com/onsi/ginkgo/v2" //nolint:golint,revive
. "github.com/onsi/ginkgo/v2"
)

const (
Expand Down

0 comments on commit 32722ec

Please sign in to comment.