Skip to content

Commit 53edbde

Browse files
committed
refactor: migrate to golangci-lint v2 and fix all lint issues
Adapt config to v2 format, fix indent-error-flow/superfluous-else, add package comments, remove unused code, fix deprecated API usage, and correct error string capitalization.
1 parent 8b12dde commit 53edbde

21 files changed

Lines changed: 331 additions & 358 deletions

.golangci.yml

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,45 @@
1+
version: "2"
2+
13
run:
24
timeout: 5m
35
allow-parallel-runners: true
6+
tests: false
47

5-
issues:
6-
# don't skip warning about doc comments
7-
# don't exclude the default set of lint
8-
exclude-use-default: false
9-
# restore some of the defaults
10-
# (fill in the rest as needed)
11-
exclude-rules:
12-
- path: "api/*"
13-
linters:
14-
- lll
15-
- path: "internal/*"
16-
linters:
17-
- dupl
18-
- lll
19-
- path: "cmd/*"
20-
linters:
21-
- lll
228
linters:
23-
disable-all: true
9+
default: none
2410
enable:
25-
- dupl
2611
- errcheck
27-
- exportloopref
2812
- ginkgolinter
2913
- goconst
30-
- gocyclo
31-
- gofmt
32-
- goimports
33-
- gosimple
3414
- govet
3515
- ineffassign
36-
- lll
3716
- misspell
3817
- nakedret
39-
- prealloc
4018
- revive
4119
- staticcheck
42-
- typecheck
4320
- unconvert
4421
- unparam
4522
- unused
46-
47-
linters-settings:
48-
revive:
23+
settings:
24+
revive:
25+
rules:
26+
- name: comment-spacings
27+
- name: indent-error-flow
28+
- name: superfluous-else
29+
- name: package-comments
30+
- name: exported
31+
disabled: true
32+
- name: unused-parameter
33+
disabled: true
34+
- name: var-naming
35+
disabled: true
36+
exclusions:
4937
rules:
50-
- name: comment-spacings
38+
- linters:
39+
- staticcheck
40+
text: "SA1019"
41+
42+
formatters:
43+
enable:
44+
- gofmt
45+
- goimports

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ RUN go mod download
1414
# Copy the go source
1515
COPY cmd/main.go cmd/main.go
1616
COPY api/ api/
17-
COPY internal// internal//
17+
COPY internal/ internal/
1818
COPY pkg/ pkg/
1919

2020
# Build

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ test-e2e:
128128

129129
.PHONY: lint
130130
lint: golangci-lint ## Run golangci-lint linter
131-
$(GOLANGCI_LINT) --tests=false --config=.golangci.yml --exclude=type run
131+
$(GOLANGCI_LINT) run --config=.golangci.yml
132132

133133
.PHONY: lint-fix
134134
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
135-
$(GOLANGCI_LINT) --tests=false --config=.golangci.yml --exclude=type run --fix
135+
$(GOLANGCI_LINT) run --config=.golangci.yml --fix
136136

137137
##@ Build
138138

@@ -219,7 +219,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
219219
KUSTOMIZE_VERSION ?= v5.4.3
220220
CONTROLLER_TOOLS_VERSION ?= v0.17.2
221221
ENVTEST_VERSION ?= release-0.19
222-
GOLANGCI_LINT_VERSION ?= v1.59.1
222+
GOLANGCI_LINT_VERSION ?= v2.11.4
223223

224224
.PHONY: kustomize
225225
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -239,7 +239,7 @@ $(ENVTEST): $(LOCALBIN)
239239
.PHONY: golangci-lint
240240
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
241241
$(GOLANGCI_LINT): $(LOCALBIN)
242-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
242+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
243243

244244
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
245245
# $1 - target path with name of binary

api/v1alphav1/groupversion_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// SPDX-License-Identifier: Apache-2.0
55

6-
// Package v1 contains API Schema definitions for the overcommit v1 API group
6+
// Package v1alphav1 contains API Schema definitions for the overcommit v1alphav1 API group
77
// +kubebuilder:object:generate=true
88
// +groupName=overcommit.inditex.dev
99
package v1alphav1

api/v1alphav1/webhook_validations.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import (
1717

1818
func validateSpecOvercommit(class OvercommitClass) error {
1919
if class.Spec.CpuOvercommit <= 0 || class.Spec.CpuOvercommit > 1 {
20-
return errors.New("Error: cpuOvercommit must be greater than 0 and equal or lower than 1, failed creating " + class.ObjectMeta.Name + " class ")
20+
return errors.New("Error: cpuOvercommit must be greater than 0 and equal or lower than 1, failed creating " + class.Name + " class ")
2121
}
2222
if class.Spec.MemoryOvercommit <= 0 || class.Spec.MemoryOvercommit > 1 {
23-
return errors.New("Error: memoryOvercommit must be greater than 0 and equal or lower than 1, failed creating " + class.ObjectMeta.Name + " class ")
23+
return errors.New("Error: memoryOvercommit must be greater than 0 and equal or lower than 1, failed creating " + class.Name + " class ")
2424
}
2525
return nil
2626
}
@@ -32,12 +32,12 @@ func checkDecimals(class OvercommitClass) error {
3232
roundedCpu := math.Round(cpu*precision) / precision
3333

3434
if math.Abs(cpu-roundedCpu) > 1e-9 {
35-
return errors.New("Error: the CPU value must have 4 decimals max")
35+
return errors.New("the CPU value must have 4 decimals max")
3636
}
3737

3838
roundedMemory := math.Round(memory*precision) / precision
3939
if math.Abs(memory-roundedMemory) > 1e-9 {
40-
return errors.New("Error: the memory value must have 4 decimals max")
40+
return errors.New("the memory value must have 4 decimals max")
4141
}
4242
return nil
4343
}
@@ -63,7 +63,7 @@ func isClassDefault(class OvercommitClass, client client.Client) error {
6363
}
6464

6565
if existsDefault {
66-
return fmt.Errorf("error: only one OvercommitClass can be default, failed creating %s class", class.ObjectMeta.Name)
66+
return fmt.Errorf("error: only one OvercommitClass can be default, failed creating %s class", class.Name)
6767
}
6868

6969
return nil

cmd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//
44
// SPDX-License-Identifier: Apache-2.0
55

6+
// Package main is the entrypoint for the k8s-overcommit-operator.
67
package main
78

89
import (

0 commit comments

Comments
 (0)