Skip to content

Commit 4f99246

Browse files
committed
Update golangci-lint to v2, migrate config, fix lint issues
1 parent 2a16557 commit 4f99246

File tree

7 files changed

+100
-122
lines changed

7 files changed

+100
-122
lines changed

.golangci.yml

+80-100
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,86 @@
1+
version: "2"
12
run:
2-
# Our CI expects a vendor directory, hence we have to use -mod=readonly here as well.
33
modules-download-mode: readonly
4-
# Timeout for analysis, e.g. 30s, 5m.
5-
# Default: 1m
6-
timeout: 15m
7-
8-
issues:
9-
# on default, golangci-lint excludes gosec. Hence, we have to
10-
# explicitly disable the exclude-use-default: https://github.com/golangci/golangci-lint/issues/1504
11-
exclude-use-default: false
12-
13-
# output configuration options
144
output:
15-
# colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
16-
# default is "colored-line-number"
17-
18-
# print lines of code with issue, default is true
19-
print-issued-lines: true
20-
21-
# print linter name in the end of issue text, default is true
22-
print-linter-name: true
23-
24-
# make issues output unique by line, default is true
25-
uniq-by-line: true
26-
27-
# add a prefix to the output file references; default is no prefix
285
path-prefix: ""
29-
30-
# sorts results by: filepath, line and column
31-
sort-results: false
32-
33-
# default linters are enabled `golangci-lint help linters`
346
linters:
35-
disable-all: true
7+
default: none
368
enable:
37-
## enabled by default
38-
- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
39-
- gosimple # specializes in simplifying a code
40-
- govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
41-
- ineffassign # detects when assignments to existing variables are not used
42-
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
43-
- typecheck # like the front-end of a Go compiler, parses and type-checks Go code
44-
- unused # checks for unused constants, variables, functions and types
45-
46-
## disabled by default
47-
- asasalint # Check for pass []any as any in variadic func(...any)
48-
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
49-
- bidichk # Checks for dangerous unicode character sequences
50-
- bodyclose # Checks whether HTTP response body is closed successfully
51-
- decorder # Check declaration order and count of types, constants, variables and functions
52-
- dupword # Checks for duplicate words in the source code
53-
- durationcheck # Check for two durations multiplied together
54-
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted.
55-
- errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error.
56-
- errorlint # Errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
57-
- exportloopref # Checks for pointers to enclosing loop variables
58-
- ginkgolinter # Enforces standards of using ginkgo and gomega
59-
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid.
60-
- goconst # Finds repeated strings that could be replaced by a constant
61-
- gocritic # Provides diagnostics that check for bugs, performance and style issues.
62-
- gocyclo # Computes and checks the cyclomatic complexity of functions
63-
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
64-
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
65-
- goheader # Checks is file header matches to pattern
66-
- goimports # Check import statements are formatted according to the 'goimport' command. Reformat imports in autofix mode.
67-
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
68-
- gosec # Inspects source code for security problems
69-
- grouper # An analyzer to analyze expression groups.
70-
- importas # Enforces consistent import aliases
71-
- loggercheck # Checks key value pairs for common logger libraries (kitlog,klog,logr,zap).
72-
- maintidx # Maintidx measures the maintainability index of each function.
73-
- makezero # Finds slice declarations with non-zero initial length
74-
- misspell # Finds commonly misspelled English words in comments
75-
- nestif # Reports deeply nested if statements
76-
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
77-
- nilnil # Checks that there is no simultaneous return of nil error and an invalid value.
78-
- noctx # Noctx finds sending http request without context.Context
79-
- nolintlint # Reports ill-formed or insufficient nolint directives
80-
- nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL.
81-
- prealloc # Finds slice declarations that could potentially be pre-allocated
82-
- predeclared # Find code that shadows one of Go's predeclared identifiers
83-
- promlinter # Check Prometheus metrics naming via promlint
84-
- reassign # Checks that package variables are not reassigned
85-
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
86-
- rowserrcheck # Checks whether Err of rows is checked successfully
87-
- tenv # Tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
88-
- thelper # Thelper detects Go test helpers without t.Helper() call and checks the consistency of test helpers
89-
- tparallel # Tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
90-
- unconvert # Remove unnecessary type conversions
91-
- usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library.
92-
- wastedassign # Finds wasted assignment statements.
93-
- whitespace # Tool for detection of leading and trailing whitespace
94-
95-
linters-settings:
96-
nestif:
97-
min-complexity: 10
98-
revive:
99-
rules:
100-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#dot-imports
101-
- name: dot-imports
102-
severity: warning
103-
disabled: false
104-
exclude: [""]
105-
arguments:
106-
- allowedPackages: [github.com/onsi/ginkgo/v2, github.com/onsi/gomega]
9+
- asasalint
10+
- asciicheck
11+
- bidichk
12+
- bodyclose
13+
- decorder
14+
- dupword
15+
- durationcheck
16+
- errcheck
17+
- errchkjson
18+
- errname
19+
- errorlint
20+
- ginkgolinter
21+
- gocheckcompilerdirectives
22+
- goconst
23+
- gocritic
24+
- gocyclo
25+
- goheader
26+
- gomodguard
27+
- gosec
28+
- govet
29+
- grouper
30+
- importas
31+
- ineffassign
32+
- loggercheck
33+
- maintidx
34+
- makezero
35+
- misspell
36+
- nestif
37+
- nilerr
38+
- nilnil
39+
- noctx
40+
- nolintlint
41+
- nosprintfhostport
42+
- prealloc
43+
- predeclared
44+
- promlinter
45+
- reassign
46+
- revive
47+
- rowserrcheck
48+
- staticcheck
49+
- thelper
50+
- tparallel
51+
- unconvert
52+
- unused
53+
- usestdlibvars
54+
- wastedassign
55+
- whitespace
56+
settings:
57+
nestif:
58+
min-complexity: 10
59+
revive:
60+
rules:
61+
- name: dot-imports
62+
arguments:
63+
- allowedPackages:
64+
- github.com/onsi/ginkgo/v2
65+
- github.com/onsi/gomega
66+
severity: warning
67+
disabled: false
68+
exclude:
69+
- ""
70+
exclusions:
71+
generated: lax
72+
paths:
73+
- third_party$
74+
- builtin$
75+
- examples$
76+
formatters:
77+
enable:
78+
- gofmt
79+
- gofumpt
80+
- goimports
81+
exclusions:
82+
generated: lax
83+
paths:
84+
- third_party$
85+
- builtin$
86+
- examples$

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ endef
88

99
include boilerplate/generated-includes.mk
1010

11-
GOLANGCI_LINT_VERSION=v1.59.1
11+
GOLANGCI_LINT_VERSION=v2.0.2
1212
MOCKGEN_VERSION=v0.5.0
1313

1414
.DEFAULT_GOAL := all

pkg/aws/aws.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ func (c *SdkClient) PollInstanceStopEventsFor(instances []ec2v2types.Instance, r
203203
idToCloudtrailEvent := make(map[string]cloudtrailv2types.Event)
204204

205205
var executionError error
206-
var stoppedInstanceEvents []cloudtrailv2types.Event = make([]cloudtrailv2types.Event, 0)
207-
var terminatedInstanceEvents []cloudtrailv2types.Event = make([]cloudtrailv2types.Event, 0)
206+
stoppedInstanceEvents := make([]cloudtrailv2types.Event, 0)
207+
terminatedInstanceEvents := make([]cloudtrailv2types.Event, 0)
208208
err = wait.ExponentialBackoff(backoffOptions, func() (bool, error) {
209209
executionError = nil
210210

@@ -483,7 +483,7 @@ func (c *SdkClient) listAllInstancesAttribute(att cloudtrailv2types.LookupAttrib
483483
// exhaust 90 days of events might take *very* long in big accounts
484484
// otherwise.
485485
maxNumberEvents := 1000
486-
var events []cloudtrailv2types.Event = make([]cloudtrailv2types.Event, 0)
486+
events := make([]cloudtrailv2types.Event, 0)
487487
in := &cloudtrailv2.LookupEventsInput{
488488
LookupAttributes: []cloudtrailv2types.LookupAttribute{att},
489489
StartTime: &since,
@@ -600,7 +600,7 @@ func eventContainsInstances(instances []ec2v2types.Instance, event cloudtrailv2t
600600

601601
func getTime(rawReason string) (time.Time, error) {
602602
subMatches := stopInstanceDateRegex.FindStringSubmatch(rawReason)
603-
if subMatches == nil || len(subMatches) < 2 {
603+
if len(subMatches) < 2 {
604604
return time.Time{}, fmt.Errorf("did not find matches: raw data %s", rawReason)
605605
}
606606
if len(subMatches) != 2 {

pkg/investigations/ccam/ccam.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (c *Investigation) Run(r *investigation.Resources) (investigation.Investiga
2828
pdClient := r.PdClient
2929
bpError, ok := r.AdditionalResources["error"].(error)
3030
if !ok {
31-
return result, fmt.Errorf("Missing required Investigation field 'error'")
31+
return result, fmt.Errorf("missing required Investigation field 'error'")
3232
}
3333
logging.Info("Investigating possible missing cloud credentials...")
3434

pkg/investigations/chgm/chgm_hibernation_check.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func createHibernationTimeLine(clusterStateUpdates []*servicelogsv1.LogEntry) []
6969
hibernationStartTime = date
7070
}
7171
if event == hibernationEndEvent {
72-
if (hibernationStartTime == time.Time{}) {
72+
if (time.Time.Equal(hibernationStartTime, time.Time{})) {
7373
// Cluster became ready after installation
7474
continue
7575
}

0 commit comments

Comments
 (0)