mirror of
https://github.com/containers/podman.git
synced 2025-05-17 23:26:08 +08:00
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 <kolyshkin@gmail.com>
This commit is contained in:
@ -1,8 +1,14 @@
|
||||
---
|
||||
version: "2"
|
||||
run:
|
||||
concurrency: 6
|
||||
timeout: 5m
|
||||
modules-download-mode: readonly
|
||||
|
||||
formatters:
|
||||
enable:
|
||||
- gofmt
|
||||
- goimports
|
||||
exclusions:
|
||||
generated: strict
|
||||
|
||||
linters:
|
||||
enable:
|
||||
- asasalint
|
||||
@ -13,7 +19,6 @@ linters:
|
||||
- decorder
|
||||
- dogsled
|
||||
- durationcheck
|
||||
- errcheck
|
||||
- errchkjson
|
||||
- exptostd
|
||||
- fatcontext
|
||||
@ -21,15 +26,10 @@ linters:
|
||||
- gocheckcompilerdirectives
|
||||
- gochecksumtype
|
||||
- gocritic
|
||||
- gofmt
|
||||
- goimports
|
||||
- goprintffuncname
|
||||
- gosimple
|
||||
- govet
|
||||
- grouper
|
||||
- iface
|
||||
- inamedparam
|
||||
- ineffassign
|
||||
- interfacebloat
|
||||
- makezero
|
||||
- mirror
|
||||
@ -49,32 +49,34 @@ linters:
|
||||
- testableexamples
|
||||
- unconvert
|
||||
- unparam
|
||||
- unused
|
||||
- usestdlibvars
|
||||
- usetesting
|
||||
- wastedassign
|
||||
- whitespace
|
||||
linters-settings:
|
||||
errcheck:
|
||||
check-blank: false
|
||||
nolintlint:
|
||||
require-specific: true
|
||||
revive:
|
||||
settings:
|
||||
staticcheck:
|
||||
checks:
|
||||
- all
|
||||
- -ST1003 # https://staticcheck.dev/docs/checks/#ST1003 Poorly chosen identifier.
|
||||
- -QF1008 # https://staticcheck.dev/docs/checks/#QF1008 Omit embedded fields from selector expression.
|
||||
nolintlint:
|
||||
require-specific: true
|
||||
revive:
|
||||
rules:
|
||||
- name: unused-parameter
|
||||
disabled: true
|
||||
exclusions:
|
||||
generated: strict
|
||||
presets:
|
||||
- comments
|
||||
- common-false-positives
|
||||
- legacy
|
||||
- std-error-handling
|
||||
rules:
|
||||
- name: unused-parameter
|
||||
disabled: true
|
||||
- linters:
|
||||
- recvcheck
|
||||
path: pkg/k8s.io/
|
||||
|
||||
issues:
|
||||
# Maximum issues count per one linter.
|
||||
# Set to 0 to disable.
|
||||
# Default: 50
|
||||
max-issues-per-linter: 0
|
||||
# Maximum count of issues with the same text.
|
||||
# Set to 0 to disable.
|
||||
# Default: 3
|
||||
max-same-issues: 0
|
||||
exclude-rules:
|
||||
# Exclude recvcheck from running on the imported k8s files, to much failures
|
||||
- path: pkg/k8s.io/
|
||||
linters:
|
||||
- recvcheck
|
||||
|
4
Makefile
4
Makefile
@ -61,7 +61,7 @@ BUILDTAGS += ${EXTRA_BUILDTAGS}
|
||||
# N/B: This value is managed by Renovate, manual changes are
|
||||
# possible, as long as they don't disturb the formatting
|
||||
# (i.e. DO NOT ADD A 'v' prefix!)
|
||||
GOLANGCI_LINT_VERSION := 1.64.4
|
||||
GOLANGCI_LINT_VERSION := 2.0.2
|
||||
PYTHON ?= $(shell command -v python3 python|head -n1)
|
||||
PKG_MANAGER ?= $(shell command -v dnf yum|head -n1)
|
||||
# ~/.local/bin is not in PATH on all systems
|
||||
@ -282,7 +282,7 @@ endif
|
||||
|
||||
.PHONY: golangci-lint
|
||||
golangci-lint: .install.golangci-lint
|
||||
hack/golangci-lint.sh run
|
||||
hack/golangci-lint.sh
|
||||
|
||||
.PHONY: test/checkseccomp/checkseccomp
|
||||
test/checkseccomp/checkseccomp: $(wildcard test/checkseccomp/*.go)
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Need to run linter twice to cover all the build tags code paths
|
||||
# Run golangci-lint with different sets of build tags.
|
||||
set -e
|
||||
|
||||
# WARNING: This script executes on multiple operating systems that
|
||||
@ -8,38 +8,23 @@ set -e
|
||||
# a very old version, where modern features (like `declare -A`) are
|
||||
# absent.
|
||||
|
||||
# Makefile calls script with the 'run' argument, but developers may not.
|
||||
# Handle both cases transparently.
|
||||
[[ $1 == run ]] && shift
|
||||
|
||||
BUILD_TAGS_DEFAULT="apparmor,seccomp,selinux"
|
||||
BUILD_TAGS_ABI="$BUILD_TAGS_DEFAULT,systemd"
|
||||
BUILD_TAGS_TUNNEL="$BUILD_TAGS_DEFAULT,remote"
|
||||
BUILD_TAGS_REMOTE="remote,containers_image_openpgp"
|
||||
|
||||
SKIP_DIRS_ABI=""
|
||||
SKIP_DIRS_TUNNEL=""
|
||||
SKIP_DIRS_REMOTE="libpod/events,pkg/machine/qemu,pkg/machine/wsl,test"
|
||||
|
||||
declare -a to_lint
|
||||
to_lint=(ABI TUNNEL)
|
||||
|
||||
# Special-case, for Darwin and Windows only "remote" linting is possible and required.
|
||||
if [[ "$GOOS" == "windows" ]] || [[ "$GOOS" == "darwin" ]]; then
|
||||
to_lint=(REMOTE)
|
||||
echo "Linting for GOOS=$GOOS"
|
||||
# Special case: for Darwin and Windows only "remote" linting is possible and required.
|
||||
if [[ "$GOOS" == "windows" || "$GOOS" == "darwin" ]]; then
|
||||
(
|
||||
set -x
|
||||
./bin/golangci-lint run --build-tags="remote,containers_image_openpgp" "$@"
|
||||
)
|
||||
exit 0
|
||||
fi
|
||||
|
||||
for to_lint in "${to_lint[@]}"; do
|
||||
tags_var="BUILD_TAGS_${to_lint}"
|
||||
skip_var="SKIP_DIRS_${to_lint}"
|
||||
echo ""
|
||||
echo Running golangci-lint for "$to_lint"
|
||||
echo Build Tags "$to_lint": ${!tags_var}
|
||||
echo Skipped directories "$to_lint": ${!skip_var}
|
||||
# Normal case (Linux): run linter for various sets of build tags.
|
||||
TAGS="apparmor,seccomp,selinux"
|
||||
for EXTRA_TAGS in "" ",systemd" ",remote"; do
|
||||
(
|
||||
# Make it really easy for a developer to copy-paste the command-line
|
||||
# to focus or debug a single, specific linting category.
|
||||
set -x
|
||||
./bin/golangci-lint run --timeout=10m --build-tags="${!tags_var}" --exclude-dirs="${!skip_var}" "$@"
|
||||
./bin/golangci-lint run --build-tags="${TAGS}${EXTRA_TAGS}" "$@"
|
||||
)
|
||||
done
|
||||
|
Reference in New Issue
Block a user