Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] Failed executing command with error: can't load config: gofmt is a formatter #5597

Closed
6 of 7 tasks
yurishkuro opened this issue Mar 24, 2025 · 9 comments
Closed
6 of 7 tasks
Labels
question Further information is requested

Comments

@yurishkuro
Copy link

Welcome

  • Yes, I'm using a binary release within 2 latest releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've read the typecheck section of the FAQ.
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.).
  • I agree to follow this project's Code of Conduct

How did you install golangci-lint?

go install

Description of the problem

Trying to upgrade to v2 and it fails on the existing config. I have these previously valid linters in the config:

    - gofmt
    - gofumpt
    - goimports

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version v2.0.0 built with go1.24.1 from (unknown, modified: ?, mod sum: "h1:RQWk8VCuMQv9bBDy3x23yds2yf9aRZ86C9MWGIdNRuU=") on (unknown)

Configuration

issues:
  # Excluding configuration per-path, per-linter, per-text and per-source
  exclude-rules:
    # Exclude some linters from running on tests files.
    - path: _test\.go
      linters: [gosec, bodyclose, noctx]
    - linters: [gocritic]
      text: "dupArg"
    - linters: [gocritic]
      text: "exitAfterDefer"
    - linters: [gocritic]
      text: "appendAssign"

  exclude-dirs-use-default: false
  exclude-files:
    - ".*.pb.go$"
    - "proto-gen/.*"
    - "model/v1/prototest/.*"

  max-issues-per-linter: 0
  max-same-issues: 0

linters:
  disable:
    - errcheck
  enable:
    # Plain ASCII identifiers.
    - asciicheck

    # Checks for dangerous unicode character sequences.
    - bidichk

    # Checks whether HTTP response body is closed successfully.
    # TODO enable this but maybe find a way to disable in tests.
    - bodyclose

    # Check whether the function uses a non-inherited context.
    - contextcheck

    # Check declaration order of types, consts, vars and funcs.
    - decorder

    # Checks if package imports are in a list of acceptable packages (see cfg below).
    - depguard

    # Check for two durations multiplied together.
    - durationcheck

    # Checks `Err-` prefix for var and `-Error` suffix for error type.
    - errname

    # Suggests to use `%w` for error-wrapping.
    - errorlint

    # Checks for pointers to enclosing loop variables.
    - copyloopvar

    - gocritic
    - gofmt
    - gofumpt
    - goimports

    # Allow or ban replace directives in go.mod
    # or force explanation for retract directives.
    # Maybe enable once we get rid of old sarama.
    # - gomoddirectives

    - gosec

    # Linter that specializes in simplifying code.
    - gosimple
    - govet

    # Detects when assignments to existing variables are not used.
    - ineffassign

    - misspell

    # Finds naked/bare returns and requires change them.
    - nakedret

    # Require a bit more explicit returns.
    - nilerr

    # Finds sending HTTP request without context.Context.
    - noctx

    # Reports ill-formed or insufficient nolint directives.
    - nolintlint

    # Checks that fmt.Sprintf can be replaced with a faster alternative.
    - perfsprint

    # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
    - revive

    # Checks usage of github.com/stretchr/testify.
    - testifylint

    # Detects the possibility to use variables/constants from the Go standard library.
    - usestdlibvars

    # TODO consider adding more linters, cf. https://olegk.dev/go-linters-configuration-the-right-version

linters-settings:
  depguard:
    rules:
      main:
        files: ["$all"]
        allow:
          - "$gostd"
          - "github.com/stretchr/testify"
          - "github.com/gogo/protobuf"
          - "github.com/jaegertracing/jaeger-idl"
          - "go.uber.org/goleak"

run:
  go: "1.23"
  timeout: 20m

Go environment

$ go version && go env
go version go1.24.1 darwin/arm64

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO golangci-lint has version v2.0.0 built with go1.24.1 from (unknown, modified: ?, mod sum: "h1:RQWk8VCuMQv9bBDy3x23yds2yf9aRZ86C9MWGIdNRuU=") on (unknown) 
INFO [config_reader] Config search paths: [./ /Users/ysh/dev/jaegertracing/jaeger-idl /Users/ysh/dev/jaegertracing /Users/ysh/dev /Users/ysh /Users /] 
INFO [config_reader] Used config file .golangci.yaml 
Error: can't load config: gofmt is a formatter
Failed executing command with error: can't load config: gofmt is a formatter

A minimal reproducible example or link to a public repository

jaegertracing/jaeger-idl#160

Validation

  • Yes, I've included all information above (version, config, etc.).

Supporter

@yurishkuro yurishkuro added the bug Something isn't working label Mar 24, 2025
Copy link

boring-cyborg bot commented Mar 24, 2025

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@ldez ldez added question Further information is requested and removed bug Something isn't working labels Mar 24, 2025
@ldez
Copy link
Member

ldez commented Mar 24, 2025

Hello,

The configuration has changed: https://golangci-lint.run/product/migration-guide/#linters-settings

I recommend using the migration command: https://golangci-lint.run/product/migration-guide/#command-migrate

@ldez ldez closed this as completed Mar 24, 2025
@yurishkuro
Copy link
Author

Thanks, I'll check it out. If the linter can auto-detect v1 config it would be nice if it would print these links, rather than a cryptic error message.

@ldez
Copy link
Member

ldez commented Mar 24, 2025

The v1 (v1.64.8) detects the v2 configuration.

And v2 detects the v1 configuration, I need to check something.

@julieta-311
Copy link

julieta-311 commented Mar 24, 2025

I got the same error, I had no config file while using v1, golangci-lint migrate returned a warning (WARN No config file detected) and did nothing. I was running it via golangci-lint run --no-config ./... but now I manually created a .golangci.yaml config file and that resolved it.

@ldez
Copy link
Member

ldez commented Mar 24, 2025

The v2 validation was not in the right position: #5599

@ldez
Copy link
Member

ldez commented Mar 24, 2025

@julieta-311 can you create a dedicated issue?

@lratc
Copy link

lratc commented Mar 25, 2025

Either the command definition is incorrect in the documentation https://golangci-lint.run/usage/configuration/#fmt or the validation is being applied incorrectly because I am able to reproduce this issue with the command line flags:

$ docker run --rm golangci/golangci-lint:v2.0.1 golangci-lint fmt -E "goimports,gofmt"
Error: can't load config: goimports is a formatter
Failed executing command with error: can't load config: goimports is a formatter

@ldez
Copy link
Member

ldez commented Mar 25, 2025

@lratc can you open a dedicated issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants