chore: bump golangci-lint to v2

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL 2025-04-21 21:10:33 +00:00
parent 61c6818f0b
commit ef0a5eb694
3 changed files with 136 additions and 150 deletions

View File

@ -1,3 +1,29 @@
version: "2"
run:
# prevent golangci-lint from deducting the go version to lint for through go.mod,
# which causes it to fallback to go1.17 semantics.
#
# TODO(thaJeztah): update "usetesting" settings to enable go1.24 features once our minimum version is go1.24
go: "1.23.8"
timeout: 5m
issues:
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-issues-per-linter: 0
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0
formatters:
enable:
- gofumpt # Detects whether code was gofumpt-ed.
- goimports
exclusions:
generated: strict
linters: linters:
enable: enable:
- bodyclose - bodyclose
@ -6,14 +32,12 @@ linters:
- dogsled - dogsled
- dupword # Detects duplicate words. - dupword # Detects duplicate words.
- durationcheck - durationcheck
- errcheck
- errchkjson - errchkjson
- forbidigo - forbidigo
- gocritic # Metalinter; detects bugs, performance, and styling issues. - gocritic # Metalinter; detects bugs, performance, and styling issues.
- gocyclo - gocyclo
- gofumpt # Detects whether code was gofumpt-ed.
- goimports
- gosec # Detects security problems. - gosec # Detects security problems.
- gosimple
- govet - govet
- ineffassign - ineffassign
- misspell # Detects commonly misspelled English words in comments. - misspell # Detects commonly misspelled English words in comments.
@ -26,10 +50,8 @@ linters:
- reassign - reassign
- revive # Metalinter; drop-in replacement for golint. - revive # Metalinter; drop-in replacement for golint.
- staticcheck - staticcheck
- stylecheck # Replacement for golint
- thelper # Detects test helpers without t.Helper(). - thelper # Detects test helpers without t.Helper().
- tparallel # Detects inappropriate usage of t.Parallel(). - tparallel # Detects inappropriate usage of t.Parallel().
- typecheck
- unconvert # Detects unnecessary type conversions. - unconvert # Detects unnecessary type conversions.
- unparam - unparam
- unused - unused
@ -40,15 +62,7 @@ linters:
disable: disable:
- errcheck - errcheck
run: settings:
# prevent golangci-lint from deducting the go version to lint for through go.mod,
# which causes it to fallback to go1.17 semantics.
#
# TODO(thaJeztah): update "usetesting" settings to enable go1.24 features once our minimum version is go1.24
go: "1.23.8"
timeout: 5m
linters-settings:
depguard: depguard:
rules: rules:
main: main:
@ -67,86 +81,63 @@ linters-settings:
desc: Use github.com/google/uuid instead. desc: Use github.com/google/uuid instead.
- pkg: "io/ioutil" - pkg: "io/ioutil"
desc: The io/ioutil package has been deprecated, see https://go.dev/doc/go1.16#ioutil desc: The io/ioutil package has been deprecated, see https://go.dev/doc/go1.16#ioutil
forbidigo: forbidigo:
forbid: forbid:
- pkg: ^regexp$ - pkg: ^regexp$
p: ^regexp\.MustCompile pattern: ^regexp\.MustCompile
msg: Use internal/lazyregexp.New instead. msg: Use internal/lazyregexp.New instead.
gocyclo: gocyclo:
min-complexity: 16 min-complexity: 16
gosec: gosec:
excludes: excludes:
- G104 # G104: Errors unhandled; (TODO: reduce unhandled errors, or explicitly ignore) - G104 # G104: Errors unhandled; (TODO: reduce unhandled errors, or explicitly ignore)
- G113 # G113: Potential uncontrolled memory consumption in Rat.SetString (CVE-2022-23772); (only affects go < 1.16.14. and go < 1.17.7)
- G115 # G115: integer overflow conversion; (TODO: verify these: https://github.com/docker/cli/issues/5584) - G115 # G115: integer overflow conversion; (TODO: verify these: https://github.com/docker/cli/issues/5584)
- G306 # G306: Expect WriteFile permissions to be 0600 or less (too restrictive; also flags "0o644" permissions) - G306 # G306: Expect WriteFile permissions to be 0600 or less (too restrictive; also flags "0o644" permissions)
- G307 # G307: Deferring unsafe method "*os.File" on type "Close" (also EXC0008); (TODO: evaluate these and fix where needed: G307: Deferring unsafe method "*os.File" on type "Close") - G307 # G307: Deferring unsafe method "*os.File" on type "Close" (also EXC0008); (TODO: evaluate these and fix where needed: G307: Deferring unsafe method "*os.File" on type "Close")
govet: govet:
enable: enable:
- shadow - shadow
settings: settings:
shadow: shadow:
strict: true strict: true
lll: lll:
line-length: 200 line-length: 200
nakedret: nakedret:
# Disallow naked returns if func has more lines of code than this setting. # Disallow naked returns if func has more lines of code than this setting.
# Default: 30 # Default: 30
max-func-lines: 0 max-func-lines: 0
staticcheck:
checks:
- all
- -QF1003 # FIXME Convert if/else-if chain to tagged switch
- -QF1008 # FIXME Omit embedded fields from selector expression
- -ST1020 # FIXME The documentation of an exported function should start with the functions name
- -ST1022 # FIXME The documentation of an exported variable or constant should start with variables name
revive: revive:
rules: rules:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-block - name: empty-block # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-block
- name: empty-block - name: empty-lines # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines
severity: warning - name: import-shadowing # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#import-shadowing
disabled: false - name: line-length-limit # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#line-length-limit
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines
- name: empty-lines
severity: warning
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#import-shadowing
- name: import-shadowing
severity: warning
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#line-length-limit
- name: line-length-limit
severity: warning
disabled: false
arguments: [200] arguments: [200]
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-receiver - name: unused-receiver # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-receiver
- name: unused-receiver - name: use-any # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#use-any
severity: warning
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#use-any
- name: use-any
severity: warning
disabled: false
usetesting: usetesting:
# FIXME(thaJeztah): Disable `os.Chdir()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478 os-chdir: false # FIXME(thaJeztah): Disable `os.Chdir()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
os-chdir: false context-background: false # FIXME(thaJeztah): Disable `context.Background()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
# FIXME(thaJeztah): Disable `context.Background()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478 context-todo: false # FIXME(thaJeztah): Disable `context.TODO()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
context-background: false
# FIXME(thaJeztah): Disable `context.TODO()` detections; should be automatically disabled on Go < 1.24; see https://github.com/docker/cli/pull/5835#issuecomment-2665302478
context-todo: false
issues: exclusions:
# The default exclusion rules are a bit too permissive, so copying the relevant ones below # We prefer to use an "linters.exclusions.rules" so that new "default" exclusions are not
exclude-use-default: false
# This option has been defined when Go modules was not existed and when the
# golangci-lint core was different, this is not something we still recommend.
exclude-dirs-use-default: false
exclude:
- parameter .* always receives
exclude-files:
- cli/compose/schema/bindata.go
- .*generated.*
exclude-rules:
# We prefer to use an "exclude-list" so that new "default" exclusions are not
# automatically inherited. We can decide whether or not to follow upstream # automatically inherited. We can decide whether or not to follow upstream
# defaults when updating golang-ci-lint versions. # defaults when updating golang-ci-lint versions.
# Unfortunately, this means we have to copy the whole exclusion pattern, as # Unfortunately, this means we have to copy the whole exclusion pattern, as
@ -158,27 +149,24 @@ issues:
# #
# The default list of exclusions can be found at: # The default list of exclusions can be found at:
# https://golangci-lint.run/usage/false-positives/#default-exclusions # https://golangci-lint.run/usage/false-positives/#default-exclusions
generated: strict
# EXC0001 rules:
- text: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*print(f|ln)?|os\\.(Un)?Setenv). is not checked"
linters:
- errcheck
# EXC0003 # EXC0003
- text: "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this" - text: "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this"
linters: linters:
- revive - revive
# EXC0006
- text: "Use of unsafe calls should be audited"
linters:
- gosec
# EXC0007 # EXC0007
- text: "Subprocess launch(ed with variable|ing should be audited)" - text: "Subprocess launch(ed with variable|ing should be audited)"
linters: linters:
- gosec - gosec
# EXC0009 # EXC0009
- text: "(Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)" - text: "(Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)"
linters: linters:
- gosec - gosec
# EXC0010 # EXC0010
- text: "Potential file inclusion via variable" - text: "Potential file inclusion via variable"
linters: linters:
@ -194,18 +182,16 @@ issues:
linters: linters:
- errcheck - errcheck
- gosec - gosec
- text: "ST1000: at least one file in a package should have a package comment" - text: "ST1000: at least one file in a package should have a package comment"
linters: linters:
- stylecheck - staticcheck
# Allow "err" and "ok" vars to shadow existing declarations, otherwise we get too many false positives. # Allow "err" and "ok" vars to shadow existing declarations, otherwise we get too many false positives.
- text: '^shadow: declaration of "(err|ok)" shadows declaration' - text: '^shadow: declaration of "(err|ok)" shadows declaration'
linters: linters:
- govet - govet
# Log a warning if an exclusion rule is unused.
# Maximum issues count per one linter. Set to 0 to disable. Default is 50. # Default: false
max-issues-per-linter: 0 warn-unused: true
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0

View File

@ -12,7 +12,7 @@
// based on https://github.com/golang/go/blob/master/src/text/tabwriter/tabwriter.go Last modified 690ac40 on 31 Jan // based on https://github.com/golang/go/blob/master/src/text/tabwriter/tabwriter.go Last modified 690ac40 on 31 Jan
//nolint:gocyclo,nakedret,stylecheck,unused // ignore linting errors, so that we can stick close to upstream //nolint:gocyclo,nakedret,unused // ignore linting errors, so that we can stick close to upstream
package tabwriter package tabwriter
import ( import (

View File

@ -2,7 +2,7 @@
ARG GO_VERSION=1.23.8 ARG GO_VERSION=1.23.8
ARG ALPINE_VERSION=3.21 ARG ALPINE_VERSION=3.21
ARG GOLANGCI_LINT_VERSION=v1.64.5 ARG GOLANGCI_LINT_VERSION=v2.1.2
FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint