Skip to content

Commit

Permalink
Updates for golangci-lint
Browse files Browse the repository at this point in the history
Switch config to be more consistent with other O-F repos.

Fix lint issues.

Signed-off-by: Andy Goldstein <andy.goldstein@redhat.com>
  • Loading branch information
ncdc committed Jan 9, 2024
1 parent b51f67c commit 6b6c098
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 152 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
Loading

0 comments on commit 6b6c098

Please sign in to comment.