Skip to content

gofmt can't be used as a linter #5627

Closed
@mhemeryck

Description

@mhemeryck

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?

Docker

Description of the problem

We were using the golangci linter as part of a CI/CD pipeline against a moving docker image tag.

Consequently, when v2 was made available, all of a sudden, our job started failing.

I did try to migrate our current setup over to v2, but I did notice that our current code fails for the case where we configure gofmt as part of the linter.

Full setup; invocation:

golangci-lint run -v

config file:

version: "2"

linters:
  default: none
  enable:
    - gofmt
    - gosec
run:
  timeout: 10m
  issues-exit-code: 0
output:
  formats:
    text:
      print-issued-lines: false
    code-climate:
      path: gl-code-quality-report.json

Error message:

Error: can't load config: gofmt is a formatter
Failed executing command with error: can't load config: gofmt is a formatter

Version info: we used golangci/golangci-lint:latest-alpine the logs mention (redacted):

level=info msg="golangci-lint has version 2.0.1 built with go1.24.1 from e8927ce2 on 2025-03-24T20:34:31Z"
...
Using docker image sha256:80a23913b76757104bb082e05fc7521ec5c4dd548071433410b1ac44511be8ba for golangci/golangci-lint:latest-alpine with digest golangci/golangci-lint@sha256:66854a432087d43cee95e82406b895f93a2cf6448e3edc67f46ce057dab07c7a ...
..

My guess is that the issue lies here:

if slices.Contains(getAllFormatterNames(), n) {

The code checks whether linter isn't a formatter. For gofmt, it's actually both a formatter and a linter, hence the issue.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 2.0.1 built with go1.24.1 from e8927ce2 on 2025-03-24T20:34:31Z

Configuration

version: "2"

linters:
  default: none
  enable:
    - gofmt
    - gosec
run:
  timeout: 10m
  issues-exit-code: 0
output:
  formats:
    text:
      print-issued-lines: false
    code-climate:
      path: gl-code-quality-report.json

Go environment

$ go version && go env
# paste output here

Verbose output of running

level=info msg="[config_reader] Used config file .golangci.yml"
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

// add your code here

Validation

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

Supporter

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions