Skip to content

Commit c9b108d

Browse files
committed
Bump golangci-lint to v2.0.2
This ended up slightly more complicated than anticipated, tin part because golangci-lint v2 dropped support for --exclude-dirs, so linter issues with GOOS=windows and GOOS=darwin which were previously ignored had to be fixed now. This is also the reason why the ./hack/golangci-lint was simplified. In addition, it now runs linters on Linux without systemd tag set. Tested locally with: for OS in linux windows darwin; do GOOS=$OS ./hack/golangci-lint.sh; done Linting for GOOS=linux + ./bin/golangci-lint run --build-tags=apparmor,seccomp,selinux 0 issues. + ./bin/golangci-lint run --build-tags=apparmor,seccomp,selinux,systemd 0 issues. + ./bin/golangci-lint run --build-tags=apparmor,seccomp,selinux,remote 0 issues. Linting for GOOS=windows + ./bin/golangci-lint run --build-tags=remote,containers_image_openpgp 0 issues. Linting for GOOS=darwin + ./bin/golangci-lint run --build-tags=remote,containers_image_openpgp 0 issues. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 8bd73b7 commit c9b108d

File tree

3 files changed

+46
-59
lines changed

3 files changed

+46
-59
lines changed

.golangci.yml

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
---
1+
version: "2"
22
run:
3-
concurrency: 6
4-
timeout: 5m
53
modules-download-mode: readonly
4+
5+
formatters:
6+
enable:
7+
- gofmt
8+
- goimports
9+
exclusions:
10+
generated: strict
11+
612
linters:
713
enable:
814
- asasalint
@@ -13,23 +19,17 @@ linters:
1319
- decorder
1420
- dogsled
1521
- durationcheck
16-
- errcheck
1722
- errchkjson
1823
- exptostd
1924
- fatcontext
2025
- ginkgolinter
2126
- gocheckcompilerdirectives
2227
- gochecksumtype
2328
- gocritic
24-
- gofmt
25-
- goimports
2629
- goprintffuncname
27-
- gosimple
28-
- govet
2930
- grouper
3031
- iface
3132
- inamedparam
32-
- ineffassign
3333
- interfacebloat
3434
- makezero
3535
- mirror
@@ -49,32 +49,34 @@ linters:
4949
- testableexamples
5050
- unconvert
5151
- unparam
52-
- unused
5352
- usestdlibvars
5453
- usetesting
5554
- wastedassign
5655
- whitespace
57-
linters-settings:
58-
errcheck:
59-
check-blank: false
60-
nolintlint:
61-
require-specific: true
62-
revive:
56+
settings:
57+
staticcheck:
58+
checks:
59+
- all
60+
- -ST1003 # https://staticcheck.dev/docs/checks/#ST1003 Poorly chosen identifier.
61+
- -QF1008 # https://staticcheck.dev/docs/checks/#QF1008 Omit embedded fields from selector expression.
62+
nolintlint:
63+
require-specific: true
64+
revive:
65+
rules:
66+
- name: unused-parameter
67+
disabled: true
68+
exclusions:
69+
generated: strict
70+
presets:
71+
- comments
72+
- common-false-positives
73+
- legacy
74+
- std-error-handling
6375
rules:
64-
- name: unused-parameter
65-
disabled: true
76+
- linters:
77+
- recvcheck
78+
path: pkg/k8s.io/
6679

6780
issues:
68-
# Maximum issues count per one linter.
69-
# Set to 0 to disable.
70-
# Default: 50
7181
max-issues-per-linter: 0
72-
# Maximum count of issues with the same text.
73-
# Set to 0 to disable.
74-
# Default: 3
7582
max-same-issues: 0
76-
exclude-rules:
77-
# Exclude recvcheck from running on the imported k8s files, to much failures
78-
- path: pkg/k8s.io/
79-
linters:
80-
- recvcheck

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ BUILDTAGS += ${EXTRA_BUILDTAGS}
6161
# N/B: This value is managed by Renovate, manual changes are
6262
# possible, as long as they don't disturb the formatting
6363
# (i.e. DO NOT ADD A 'v' prefix!)
64-
GOLANGCI_LINT_VERSION := 1.64.4
64+
GOLANGCI_LINT_VERSION := 2.0.2
6565
PYTHON ?= $(shell command -v python3 python|head -n1)
6666
PKG_MANAGER ?= $(shell command -v dnf yum|head -n1)
6767
# ~/.local/bin is not in PATH on all systems
@@ -282,7 +282,7 @@ endif
282282

283283
.PHONY: golangci-lint
284284
golangci-lint: .install.golangci-lint
285-
hack/golangci-lint.sh run
285+
hack/golangci-lint.sh
286286

287287
.PHONY: test/checkseccomp/checkseccomp
288288
test/checkseccomp/checkseccomp: $(wildcard test/checkseccomp/*.go)

hack/golangci-lint.sh

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,30 @@
11
#!/bin/bash
22

3-
# Need to run linter twice to cover all the build tags code paths
3+
# Run golangci-lint with different sets of build tags.
44
set -e
55

66
# WARNING: This script executes on multiple operating systems that
77
# do not have the same version of Bash. Specifically, Darwin uses
88
# a very old version, where modern features (like `declare -A`) are
99
# absent.
1010

11-
# Makefile calls script with the 'run' argument, but developers may not.
12-
# Handle both cases transparently.
13-
[[ $1 == run ]] && shift
14-
15-
BUILD_TAGS_DEFAULT="apparmor,seccomp,selinux"
16-
BUILD_TAGS_ABI="$BUILD_TAGS_DEFAULT,systemd"
17-
BUILD_TAGS_TUNNEL="$BUILD_TAGS_DEFAULT,remote"
18-
BUILD_TAGS_REMOTE="remote,containers_image_openpgp"
19-
20-
SKIP_DIRS_ABI=""
21-
SKIP_DIRS_TUNNEL=""
22-
SKIP_DIRS_REMOTE="libpod/events,pkg/machine/qemu,pkg/machine/wsl,test"
23-
24-
declare -a to_lint
25-
to_lint=(ABI TUNNEL)
26-
27-
# Special-case, for Darwin and Windows only "remote" linting is possible and required.
28-
if [[ "$GOOS" == "windows" ]] || [[ "$GOOS" == "darwin" ]]; then
29-
to_lint=(REMOTE)
11+
echo "Linting for GOOS=$GOOS"
12+
# Special case: for Darwin and Windows only "remote" linting is possible and required.
13+
if [[ "$GOOS" == "windows" || "$GOOS" == "darwin" ]]; then
14+
(
15+
set -x
16+
./bin/golangci-lint run --build-tags="remote,containers_image_openpgp" "$@"
17+
)
18+
exit 0
3019
fi
3120

32-
for to_lint in "${to_lint[@]}"; do
33-
tags_var="BUILD_TAGS_${to_lint}"
34-
skip_var="SKIP_DIRS_${to_lint}"
35-
echo ""
36-
echo Running golangci-lint for "$to_lint"
37-
echo Build Tags "$to_lint": ${!tags_var}
38-
echo Skipped directories "$to_lint": ${!skip_var}
21+
# Normal case (Linux): run linter for various sets of build tags.
22+
TAGS="apparmor,seccomp,selinux"
23+
for EXTRA_TAGS in "" ",systemd" ",remote"; do
3924
(
4025
# Make it really easy for a developer to copy-paste the command-line
4126
# to focus or debug a single, specific linting category.
4227
set -x
43-
./bin/golangci-lint run --timeout=10m --build-tags="${!tags_var}" --exclude-dirs="${!skip_var}" "$@"
28+
./bin/golangci-lint run --build-tags="${TAGS}${EXTRA_TAGS}" "$@"
4429
)
4530
done

0 commit comments

Comments
 (0)