bump golangci-lint to version v2.0.2

and apply migration script

Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
Guillaume Lours 2025-03-31 17:22:58 +02:00 committed by Nicolas De loof
parent f9cd4d0b1d
commit 7bedb5a02c
15 changed files with 86 additions and 89 deletions

View File

@ -1,9 +1,8 @@
version: "2"
run: run:
concurrency: 2 concurrency: 2
timeout: 10m
linters: linters:
enable-all: false default: none
disable-all: true
enable: enable:
- copyloopvar - copyloopvar
- depguard - depguard
@ -11,73 +10,74 @@ linters:
- errorlint - errorlint
- gocritic - gocritic
- gocyclo - gocyclo
- gofumpt
- goimports
- gomodguard - gomodguard
- revive
- gosimple
- govet - govet
- ineffassign - ineffassign
- lll - lll
- misspell - misspell
- nakedret - nakedret
- nolintlint - nolintlint
- revive
- staticcheck - staticcheck
- testifylint - testifylint
- typecheck
- unconvert - unconvert
- unparam - unparam
- unused - unused
linters-settings: settings:
revive: depguard:
rules: rules:
- name: package-comments all:
disabled: true deny:
depguard: - pkg: io/ioutil
rules: desc: io/ioutil package has been deprecated
all: - pkg: gopkg.in/yaml.v2
deny: desc: compose-go uses yaml.v3
- pkg: io/ioutil gocritic:
desc: 'io/ioutil package has been deprecated' disabled-checks:
- pkg: gopkg.in/yaml.v2 - paramTypeCombine
desc: 'compose-go uses yaml.v3' - unnamedResult
gomodguard: - whyNoLint
blocked: enabled-tags:
modules: - diagnostic
- github.com/pkg/errors: - opinionated
recommendations: - style
- errors gocyclo:
- fmt min-complexity: 16
versions: gomodguard:
- github.com/distribution/distribution: blocked:
reason: "use distribution/reference" modules:
- gotest.tools: - github.com/pkg/errors:
version: "< 3.0.0" recommendations:
reason: "deprecated, pre-modules version" - errors
gocritic: - fmt
# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks. versions:
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags". - github.com/distribution/distribution:
enabled-tags: reason: use distribution/reference
- diagnostic - gotest.tools:
- opinionated version: < 3.0.0
- style reason: deprecated, pre-modules version
disabled-checks: lll:
- paramTypeCombine line-length: 200
- unnamedResult revive:
- whyNoLint rules:
gocyclo: - name: package-comments
min-complexity: 16 disabled: true
lll: exclusions:
line-length: 200 generated: lax
paths:
- third_party$
- builtin$
- examples$
issues: issues:
# golangci hides some golint warnings (the warning about exported things
# without documentation for example), this will make it show them anyway.
exclude-use-default: false
# Maximum issues count per one linter.
# Set to 0 to disable.
# Default: 50
max-issues-per-linter: 0 max-issues-per-linter: 0
# Maximum count of issues with the same text.
# Set to 0 to disable.
# Default: 3
max-same-issues: 0 max-same-issues: 0
formatters:
enable:
- gofumpt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$

View File

@ -17,7 +17,7 @@
ARG GO_VERSION=1.23.6 ARG GO_VERSION=1.23.6
ARG XX_VERSION=1.6.1 ARG XX_VERSION=1.6.1
ARG GOLANGCI_LINT_VERSION=v1.63.4 ARG GOLANGCI_LINT_VERSION=v2.0.2
ARG ADDLICENSE_VERSION=v1.0.0 ARG ADDLICENSE_VERSION=v1.0.0
ARG BUILD_TAGS="e2e" ARG BUILD_TAGS="e2e"

View File

@ -550,10 +550,7 @@ func RootCommand(dockerCli command.Cli, backend Backend) *cobra.Command { //noli
} }
composeCmd := cmd composeCmd := cmd
for { for composeCmd.Name() != PluginName {
if composeCmd.Name() == PluginName {
break
}
if !composeCmd.HasParent() { if !composeCmd.HasParent() {
return fmt.Errorf("error parsing command line, expected %q", PluginName) return fmt.Errorf("error parsing command line, expected %q", PluginName)
} }

View File

@ -86,7 +86,7 @@ func runExec(ctx context.Context, dockerCli command.Cli, backend api.Service, op
if err != nil { if err != nil {
return err return err
} }
projectOptions, err := opts.composeOptions.toProjectOptions() projectOptions, err := opts.composeOptions.toProjectOptions() //nolint:staticcheck
if err != nil { if err != nil {
return err return err
} }

View File

@ -246,7 +246,7 @@ func displayInterpolationVariables(writer io.Writer, varsInfo []varInfo) {
} }
func displayLocationRemoteStack(dockerCli command.Cli, project *types.Project, options buildOptions) { func displayLocationRemoteStack(dockerCli command.Cli, project *types.Project, options buildOptions) {
mainComposeFile := options.ProjectOptions.ConfigPaths[0] mainComposeFile := options.ProjectOptions.ConfigPaths[0] //nolint:staticcheck
if ui.Mode != ui.ModeQuiet && ui.Mode != ui.ModeJSON { if ui.Mode != ui.ModeQuiet && ui.Mode != ui.ModeJSON {
_, _ = fmt.Fprintf(dockerCli.Out(), "Your compose stack %q is stored in %q\n", mainComposeFile, project.WorkingDir) _, _ = fmt.Fprintf(dockerCli.Out(), "Your compose stack %q is stored in %q\n", mainComposeFile, project.WorkingDir)
} }
@ -258,8 +258,8 @@ func confirmRemoteIncludes(dockerCli command.Cli, options buildOptions, assumeYe
} }
var remoteIncludes []string var remoteIncludes []string
remoteLoaders := options.ProjectOptions.remoteLoaders(dockerCli) remoteLoaders := options.ProjectOptions.remoteLoaders(dockerCli) //nolint:staticcheck
for _, cf := range options.ProjectOptions.ConfigPaths { for _, cf := range options.ProjectOptions.ConfigPaths { //nolint:staticcheck
for _, loader := range remoteLoaders { for _, loader := range remoteLoaders {
if loader.Accept(cf) { if loader.Accept(cf) {
remoteIncludes = append(remoteIncludes, cf) remoteIncludes = append(remoteIncludes, cf)

View File

@ -220,8 +220,8 @@ func TestRunTopCore(t *testing.T) {
t.Run(tc.name, func(t *testing.T) { t.Run(tc.name, func(t *testing.T) {
header, entries := collectTop([]api.ContainerProcSummary{summary}) header, entries := collectTop([]api.ContainerProcSummary{summary})
assert.EqualValues(t, tc.header, header) assert.Equal(t, tc.header, header)
assert.EqualValues(t, tc.entries, entries) assert.Equal(t, tc.entries, entries)
var buf bytes.Buffer var buf bytes.Buffer
err := topPrint(&buf, header, entries) err := topPrint(&buf, header, entries)
@ -233,7 +233,7 @@ func TestRunTopCore(t *testing.T) {
t.Run("all", func(t *testing.T) { t.Run("all", func(t *testing.T) {
header, entries := collectTop(all) header, entries := collectTop(all)
assert.EqualValues(t, topHeader{ assert.Equal(t, topHeader{
"SERVICE": 0, "SERVICE": 0,
"#": 1, "#": 1,
"UID": 2, "UID": 2,
@ -246,7 +246,7 @@ func TestRunTopCore(t *testing.T) {
"GID": 9, "GID": 9,
"CMD": 10, "CMD": 10,
}, header) }, header)
assert.EqualValues(t, []topEntries{ assert.Equal(t, []topEntries{
{ {
"SERVICE": "simple", "SERVICE": "simple",
"#": "1", "#": "1",

View File

@ -238,7 +238,7 @@ func (lk *LogKeyboard) openDockerDesktop(ctx context.Context, project *types.Pro
link := fmt.Sprintf("docker-desktop://dashboard/apps/%s", project.Name) link := fmt.Sprintf("docker-desktop://dashboard/apps/%s", project.Name)
err := open.Run(link) err := open.Run(link)
if err != nil { if err != nil {
err = fmt.Errorf("Could not open Docker Desktop") err = fmt.Errorf("could not open Docker Desktop")
lk.keyboardError("View", err) lk.keyboardError("View", err)
} }
return err return err
@ -255,7 +255,7 @@ func (lk *LogKeyboard) openDDComposeUI(ctx context.Context, project *types.Proje
link := fmt.Sprintf("docker-desktop://dashboard/docker-compose/%s", project.Name) link := fmt.Sprintf("docker-desktop://dashboard/docker-compose/%s", project.Name)
err := open.Run(link) err := open.Run(link)
if err != nil { if err != nil {
err = fmt.Errorf("Could not open Docker Desktop Compose UI") err = fmt.Errorf("could not open Docker Desktop Compose UI")
lk.keyboardError("View Config", err) lk.keyboardError("View Config", err)
} }
return err return err
@ -269,7 +269,7 @@ func (lk *LogKeyboard) openDDWatchDocs(ctx context.Context, project *types.Proje
link := fmt.Sprintf("docker-desktop://dashboard/docker-compose/%s/watch", project.Name) link := fmt.Sprintf("docker-desktop://dashboard/docker-compose/%s/watch", project.Name)
err := open.Run(link) err := open.Run(link)
if err != nil { if err != nil {
err = fmt.Errorf("Could not open Docker Desktop Compose UI") err = fmt.Errorf("could not open Docker Desktop Compose UI")
lk.keyboardError("Watch Docs", err) lk.keyboardError("Watch Docs", err)
} }
return err return err
@ -299,7 +299,7 @@ func (lk *LogKeyboard) StartWatch(ctx context.Context, doneCh chan bool, project
eg.Go(tracing.EventWrapFuncForErrGroup(ctx, "menu/watch", tracing.SpanOptions{}, eg.Go(tracing.EventWrapFuncForErrGroup(ctx, "menu/watch", tracing.SpanOptions{},
func(ctx context.Context) error { func(ctx context.Context) error {
if options.Create.Build == nil { if options.Create.Build == nil {
err := fmt.Errorf("Cannot run watch mode with flag --no-build") err := fmt.Errorf("cannot run watch mode with flag --no-build")
lk.keyboardError("Watch", err) lk.keyboardError("Watch", err)
return err return err
} }

View File

@ -47,7 +47,7 @@ import (
const ( const (
doubledContainerNameWarning = "WARNING: The %q service is using the custom container name %q. " + doubledContainerNameWarning = "WARNING: The %q service is using the custom container name %q. " +
"Docker requires each container to have a unique name. " + "Docker requires each container to have a unique name. " +
"Remove the custom name to scale the service.\n" "Remove the custom name to scale the service"
) )
// convergence manages service's container lifecycle. // convergence manages service's container lifecycle.

View File

@ -486,7 +486,7 @@ func parseSecurityOpts(p *types.Project, securityOpts []string) ([]string, bool,
if strings.Contains(opt, ":") { if strings.Contains(opt, ":") {
con = strings.SplitN(opt, ":", 2) con = strings.SplitN(opt, ":", 2)
} else { } else {
return securityOpts, false, fmt.Errorf("Invalid security-opt: %q", opt) return securityOpts, false, fmt.Errorf("invalid security-opt: %q", opt)
} }
} }
if con[0] == "seccomp" && con[1] != "unconfined" && con[1] != "builtin" { if con[0] == "seccomp" && con[1] != "unconfined" && con[1] != "builtin" {
@ -997,10 +997,10 @@ func buildContainerConfigMounts(p types.Project, s types.ServiceConfig) ([]mount
} }
if definedConfig.Driver != "" { if definedConfig.Driver != "" {
return nil, errors.New("Docker Compose does not support configs.*.driver") return nil, errors.New("Docker Compose does not support configs.*.driver") //nolint:staticcheck
} }
if definedConfig.TemplateDriver != "" { if definedConfig.TemplateDriver != "" {
return nil, errors.New("Docker Compose does not support configs.*.template_driver") return nil, errors.New("Docker Compose does not support configs.*.template_driver") //nolint:staticcheck
} }
if definedConfig.Environment != "" || definedConfig.Content != "" { if definedConfig.Environment != "" || definedConfig.Content != "" {
@ -1047,10 +1047,10 @@ func buildContainerSecretMounts(p types.Project, s types.ServiceConfig) ([]mount
} }
if definedSecret.Driver != "" { if definedSecret.Driver != "" {
return nil, errors.New("Docker Compose does not support secrets.*.driver") return nil, errors.New("Docker Compose does not support secrets.*.driver") //nolint:staticcheck
} }
if definedSecret.TemplateDriver != "" { if definedSecret.TemplateDriver != "" {
return nil, errors.New("Docker Compose does not support secrets.*.template_driver") return nil, errors.New("Docker Compose does not support secrets.*.template_driver") //nolint:staticcheck
} }
if definedSecret.Environment != "" { if definedSecret.Environment != "" {

View File

@ -70,7 +70,7 @@ func combinedConfigFiles(containers []container.Summary) (string, error) {
for _, c := range containers { for _, c := range containers {
files, ok := c.Labels[api.ConfigFilesLabel] files, ok := c.Labels[api.ConfigFilesLabel]
if !ok { if !ok {
return "", fmt.Errorf("No label %q set on container %q of compose project", api.ConfigFilesLabel, c.ID) return "", fmt.Errorf("no label %q set on container %q of compose project", api.ConfigFilesLabel, c.ID)
} }
for _, f := range strings.Split(files, ",") { for _, f := range strings.Split(files, ",") {
@ -120,7 +120,7 @@ func groupContainerByLabel(containers []container.Summary, labelName string) (ma
for _, c := range containers { for _, c := range containers {
label, ok := c.Labels[labelName] label, ok := c.Labels[labelName]
if !ok { if !ok {
return nil, nil, fmt.Errorf("No label %q set on container %q of compose project", labelName, c.ID) return nil, nil, fmt.Errorf("no label %q set on container %q of compose project", labelName, c.ID)
} }
labelContainers, ok := containersByLabel[label] labelContainers, ok := containersByLabel[label]
if !ok { if !ok {

View File

@ -104,7 +104,7 @@ func TestCombinedConfigFiles(t *testing.T) {
}{ }{
"project1": {ConfigFiles: "/home/docker-compose.yaml", Error: nil}, "project1": {ConfigFiles: "/home/docker-compose.yaml", Error: nil},
"project2": {ConfigFiles: "/home/project2-docker-compose.yaml", Error: nil}, "project2": {ConfigFiles: "/home/project2-docker-compose.yaml", Error: nil},
"project3": {ConfigFiles: "", Error: fmt.Errorf("No label %q set on container %q of compose project", api.ConfigFilesLabel, "service4")}, "project3": {ConfigFiles: "", Error: fmt.Errorf("no label %q set on container %q of compose project", api.ConfigFilesLabel, "service4")},
} }
for project, containers := range containersByLabel { for project, containers := range containersByLabel {

View File

@ -754,7 +754,7 @@ func (s *composeService) imageCreatedTime(ctx context.Context, project *types.Pr
return time.Now(), err return time.Now(), err
} }
if len(containers) == 0 { if len(containers) == 0 {
return time.Now(), fmt.Errorf("Could not get created time for service's image") return time.Now(), fmt.Errorf("could not get created time for service's image")
} }
img, err := s.apiClient().ImageInspect(ctx, containers[0].ImageID) img, err := s.apiClient().ImageInspect(ctx, containers[0].ImageID)

View File

@ -98,7 +98,7 @@ func TestUpDependenciesNotStopped(t *testing.T) {
if exitErr.ExitCode() == -1 { if exitErr.ExitCode() == -1 {
t.Fatalf("`compose up` was killed: %v", err) t.Fatalf("`compose up` was killed: %v", err)
} }
require.EqualValues(t, 130, exitErr.ExitCode()) require.Equal(t, 130, exitErr.ExitCode())
} }
RequireServiceState(t, c, "app", "exited") RequireServiceState(t, c, "app", "exited")

View File

@ -149,7 +149,7 @@ func TestGitBranchSwitch(t *testing.T) {
f.assertEvents(path) f.assertEvents(path)
// Make sure there are no errors in the out stream // Make sure there are no errors in the out stream
assert.Equal(t, "", f.out.String()) assert.Empty(t, f.out.String())
} }
func TestWatchesAreRecursive(t *testing.T) { func TestWatchesAreRecursive(t *testing.T) {

View File

@ -274,7 +274,7 @@ func newWatcher(paths []string) (Notify, error) {
fsw, err := fsnotify.NewWatcher() fsw, err := fsnotify.NewWatcher()
if err != nil { if err != nil {
if strings.Contains(err.Error(), "too many open files") && runtime.GOOS == "linux" { if strings.Contains(err.Error(), "too many open files") && runtime.GOOS == "linux" {
return nil, fmt.Errorf("Hit OS limits creating a watcher.\n" + return nil, fmt.Errorf("hit OS limits creating a watcher.\n" +
"Run 'sysctl fs.inotify.max_user_instances' to check your inotify limits.\n" + "Run 'sysctl fs.inotify.max_user_instances' to check your inotify limits.\n" +
"To raise them, run 'sudo sysctl fs.inotify.max_user_instances=1024'") "To raise them, run 'sudo sysctl fs.inotify.max_user_instances=1024'")
} }
@ -317,7 +317,7 @@ func greatestExistingAncestors(paths []string) ([]string, error) {
for _, p := range paths { for _, p := range paths {
newP, err := greatestExistingAncestor(p) newP, err := greatestExistingAncestor(p)
if err != nil { if err != nil {
return nil, fmt.Errorf("Finding ancestor of %s: %w", p, err) return nil, fmt.Errorf("finding ancestor of %s: %w", p, err)
} }
result = append(result, newP) result = append(result, newP)
} }