Skip to content

Commit

Permalink
Updates for golangci-lint (#125)
Browse files Browse the repository at this point in the history
* Updates for golangci-lint

Switch config to be more consistent with other O-F repos.

Fix lint issues.

Signed-off-by: Andy Goldstein <andy.goldstein@redhat.com>

* Make operator-lib imports last

Signed-off-by: Andy Goldstein <andy.goldstein@redhat.com>

---------

Signed-off-by: Andy Goldstein <andy.goldstein@redhat.com>
  • Loading branch information
ncdc committed Jan 10, 2024
1 parent b51f67c commit 2bc11dc
Show file tree
Hide file tree
Showing 17 changed files with 210 additions and 160 deletions.
107 changes: 74 additions & 33 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,77 @@
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:
- linters: [errcheck]
text: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked"
run:
# Default timeout is 1m, up to give more room
timeout: 4m

linters:
disable-all: true
enable:
- nakedret
- interfacer
- varcheck
- deadcode
- structcheck
- misspell
- maligned
- ineffassign
- goconst
- goimports
- errcheck
- unparam
- golint
- staticcheck
- gosimple
- unused
- govet
- typecheck
- gocyclo
- gofmt
- dupl
- asciicheck
- bodyclose
- errorlint
- gofmt
- goimports
- gosec
- importas
- misspell
- nestif
- nonamedreturns
- prealloc
- revive
- stylecheck
- tparallel
- unconvert
- unparam
- unused
- whitespace

run:
deadline: 5m
linters-settings:
errorlint:
errorf: false

importas:
alias:
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1
- pkg: k8s.io/apimachinery/pkg/api/errors
alias: apierrors
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
alias: apiextensionsv1
- pkg: k8s.io/apimachinery/pkg/util/runtime
alias: utilruntime
- pkg: "^k8s\\.io/api/([^/]+)/(v[^/]+)$"
alias: $1$2
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl

goimports:
local-prefixes: github.com/operator-framework/operator-lib

revive:
ignore-generated-header: false
severity: warning
confidence: 0.8
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id

output:
format: tab
2 changes: 1 addition & 1 deletion handler/enqueue_annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func SetOwnerAnnotations(owner, object client.Object) error {
ownerGK := owner.GetObjectKind().GroupVersionKind().GroupKind()

if ownerGK.Kind == "" {
return fmt.Errorf("Owner %s Kind not found, cannot call SetOwnerAnnotations", owner.GetName())
return fmt.Errorf("owner %s Kind not found, cannot call SetOwnerAnnotations", owner.GetName())
}

annotations := object.GetAnnotations()
Expand Down
7 changes: 4 additions & 3 deletions handler/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import (
"context"
"os"

"github.com/operator-framework/operator-lib/handler"
v1 "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

"github.com/operator-framework/operator-lib/handler"
)

// This example applies the Pause handler to all incoming Pod events on a Pod controller.
Expand Down Expand Up @@ -54,7 +55,7 @@ func ExampleNewPause() {
if err != nil {
os.Exit(1)
}
if err := c.Watch(source.Kind(mgr.GetCache(), &v1.Pod{}), pause); err != nil {
if err := c.Watch(source.Kind(mgr.GetCache(), &corev1.Pod{}), pause); err != nil {
os.Exit(1)
}

Expand Down
4 changes: 2 additions & 2 deletions handler/instrumented_enqueue_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package handler
import (
"context"

"github.com/operator-framework/operator-lib/handler/internal/metrics"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -30,6 +28,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllertest"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/operator-framework/operator-lib/handler/internal/metrics"
)

var _ = Describe("InstrumentedEnqueueRequestForObject", func() {
Expand Down
4 changes: 2 additions & 2 deletions handler/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
package handler

import (
"github.com/operator-framework/operator-lib/internal/annotation"

"sigs.k8s.io/controller-runtime/pkg/handler"

"github.com/operator-framework/operator-lib/internal/annotation"
)

// NewPause returns an event handler that filters out objects with a truthy "paused" annotation.
Expand Down
Loading

0 comments on commit 2bc11dc

Please sign in to comment.