Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Enabled more golangci linters #1638

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 131 additions & 123 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
run:
deadline: 5m
skip-dirs:
- mock*
- mock*
skip-files:
- "zz_generated.*\\.go$"
- ".*conversion.*\\.go$"
- "zz_generated.*\\.go$"
- ".*conversion.*\\.go$"
linters:
disable-all: true
enable:
- asciicheck
- bodyclose
- dogsled
# - errcheck
# - errorlint
- exportloopref
# - goconst
# - gocritic
# - godot
# - gofmt
# - goimports
# - gosimple
# - govet
# - importas
# - gosec
# - ineffassign
# - misspell
# - nakedret
# - nilerr
# - noctx
# - nolintlint
# - prealloc
# - predeclared
# - revive
# - rowserrcheck
# - staticcheck
# - stylecheck
# - thelper
# - typecheck
# - unconvert
# - unused
# - whitespace
- asciicheck
- bodyclose
- dogsled
# - errcheck
# - errorlint
- exportloopref
- goconst
- gocritic
- godot
- gofmt
- goimports
- gosimple
- govet
- importas
- gosec
- ineffassign
- misspell
# - nakedret
# - nilerr
# - noctx
- nolintlint
- prealloc
- predeclared
- revive
- rowserrcheck
- staticcheck
- stylecheck
- thelper
- typecheck
- unconvert
- unused
- whitespace
# Run with --fast=false for more extensive checks
fast: true

Expand All @@ -52,25 +52,25 @@ linters-settings:
importas:
no-unaliased: true
alias:
# Kubernetes
- pkg: k8s.io/api/core/v1
alias: corev1
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
alias: apiextensionsv1
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1
- pkg: k8s.io/apimachinery/pkg/api/errors
alias: k8serrors
- pkg: k8s.io/apimachinery/pkg/util/errors
alias: kerrors
- pkg: k8s.io/component-base/logs/api/v1
alias: logsv1
# Controller Runtime
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
# BMO
- pkg: github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1
alias: metal3api
# Kubernetes
- pkg: k8s.io/api/core/v1
alias: corev1
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
alias: apiextensionsv1
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1
- pkg: k8s.io/apimachinery/pkg/api/errors
alias: k8serrors
- pkg: k8s.io/apimachinery/pkg/util/errors
alias: kerrors
- pkg: k8s.io/component-base/logs/api/v1
alias: logsv1
# Controller Runtime
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
# BMO
- pkg: github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1
alias: metal3api
nolintlint:
allow-unused: false
allow-leading-space: false
Expand All @@ -81,80 +81,88 @@ linters-settings:
go: "1.20"
gocritic:
enabled-tags:
- experimental
- experimental
disabled-checks:
- appendAssign
- dupImport # https://github.com/go-critic/go-critic/issues/845
- evalOrder
- ifElseChain
- octalLiteral
- regexpSimplify
- sloppyReassign
- truncateCmp
- typeDefFirst
- unnamedResult
- unnecessaryDefer
- whyNoLint
- wrapperFunc
- appendAssign
- dupImport # https://github.com/go-critic/go-critic/issues/845
- evalOrder
- ifElseChain
- octalLiteral
- regexpSimplify
- sloppyReassign
- truncateCmp
- typeDefFirst
- unnamedResult
- unnecessaryDefer
- whyNoLint
- wrapperFunc
unused:
go: "1.20"
issues:
exclude-rules:
- path: test/e2e
linters:
- gosec
- path: _test\.go
linters:
- unused
# Specific exclude rules for deprecated fields that are still part of the codebase.
# These should be removed as the referenced deprecated item is removed from the project.
- linters:
- staticcheck
text: "SA1019:"
# Disable linters for conversion
- linters:
- staticcheck
text: "SA1019:"
path: .*(api|types)\/.*\/conversion.*\.go$
# Dot imports for gomega or ginkgo are allowed
# within test files.
- path: _test\.go
text: should not use dot imports
- path: (test|e2e)/.*.go
text: should not use dot imports
- linters:
- revive
text: "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"
# Exclude some packages or code to require comments, for example test code, or fake clients.
- linters:
- revive
text: exported (method|function|type|const) (.+) should have comment or be unexported
source: (func|type).*Fake.*
- linters:
- revive
text: exported (method|function|type|const) (.+) should have comment or be unexported
path: fake_\.go
- linters:
- revive
text: exported (method|function|type|const) (.+) should have comment or be unexported
path: .*(api|types)\/.*\/conversion.*\.go$
- linters:
- revive
text: "var-naming: don't use underscores in Go names;"
path: .*(api|types)\/.*\/conversion.*\.go$
- linters:
- revive
text: "receiver-naming: receiver name"
path: .*(api|types)\/.*\/conversion.*\.go$
- linters:
- stylecheck
text: "ST1003: should not use underscores in Go names;"
path: .*(api|types)\/.*\/conversion.*\.go$
- linters:
- stylecheck
text: "ST1016: methods on the same type should have the same receiver name"
path: .*(api|types)\/.*\/conversion.*\.go$
- path: test/e2e
linters:
- gosec
- path: test/e2e
linters:
- goconst
- path: _test\.go
linters:
- goconst
- path: _test\.go
linters:
- unused
- revive
- stylecheck
# Specific exclude rules for deprecated fields that are still part of the codebase.
# These should be removed as the referenced deprecated item is removed from the project.
- linters:
- staticcheck
text: "SA1019:"
# Disable linters for conversion
- linters:
- staticcheck
text: "SA1019:"
path: .*(api|types)\/.*\/conversion.*\.go$
# Dot imports for gomega or ginkgo are allowed
# within test files.
- path: _test\.go
text: should not use dot imports
- path: (test|e2e)/.*.go
text: should not use dot imports
- linters:
- revive
text: "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"
# Exclude some packages or code to require comments, for example test code, or fake clients.
- linters:
- revive
text: exported (method|function|type|const) (.+) should have comment or be unexported
source: (func|type).*Fake.*
- linters:
- revive
text: exported (method|function|type|const) (.+) should have comment or be unexported
path: fake_\.go
- linters:
- revive
text: exported (method|function|type|const) (.+) should have comment or be unexported
path: .*(api|types)\/.*\/conversion.*\.go$
- linters:
- revive
text: "var-naming: don't use underscores in Go names;"
path: .*(api|types)\/.*\/conversion.*\.go$
- linters:
- revive
text: "receiver-naming: receiver name"
path: .*(api|types)\/.*\/conversion.*\.go$
- linters:
- stylecheck
text: "ST1003: should not use underscores in Go names;"
path: .*(api|types)\/.*\/conversion.*\.go$
- linters:
- stylecheck
text: "ST1016: methods on the same type should have the same receiver name"
path: .*(api|types)\/.*\/conversion.*\.go$
include:
- EXC0002 # include "missing comments" issues from golangci-lint
- EXC0002 # include "missing comments" issues from golangci-lint
max-issues-per-linter: 0
max-same-issues: 0
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ $(GOLANGCI_LINT_BIN): $(GOLANGCI_LINT) ## Build a local copy of golangci-lint.
.PHONY: lint
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run -v ./...
cd test; $(GOLANGCI_LINT) run -v
cd pkg/hardwareutils; $(GOLANGCI_LINT) run -v
cd apis; $(GOLANGCI_LINT) run -v ./...
cd test; $(GOLANGCI_LINT) run -v ./...
cd pkg/hardwareutils; $(GOLANGCI_LINT) run -v ./...

.PHONY: manifest-lint
manifest-lint: ## Run manifest validation
Expand Down
Loading
Loading