Skip to content

v2: formatters.goimports is rejected by golangci-lint config verify #5642

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

Closed
6 of 7 tasks
nightmarlin opened this issue Mar 27, 2025 · 4 comments · Fixed by #5643
Closed
6 of 7 tasks

v2: formatters.goimports is rejected by golangci-lint config verify #5642

nightmarlin opened this issue Mar 27, 2025 · 4 comments · Fixed by #5643
Labels
area: docs bug Something isn't working

Comments

@nightmarlin
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?

Brew

Description of the problem

The documentation for the goimports formatter gives the example

formatters:
  goimports:
    # A list of prefixes, which, if set, checks import paths
    # with the given prefixes are grouped after 3rd-party packages.
    # Default: []
    local-prefixes:
      - github.com/org/project

however golangci-lint config verify (and the api spec at https://golangci-lint.run/jsonschema/golangci.jsonschema.json) do not allow the goimports property on the formatters object

$ golangci-lint config verify

jsonschema: "formatters" does not validate with "/properties/formatters/additionalProperties": additional properties 'goimports' not allowed
Failed executing command with error: the configuration contains invalid elements

this causes issues when using https://github.com/golangci/golangci-lint-action, as the action verifies the config file before running.

Version of golangci-lint

$ golangci-lint --version

golangci-lint has version 2.0.2 built with go1.24.1 from 2b224c2 on 2025-03-25T20:33:26Z

Configuration

# yaml-language-server: $schema=https://golangci-lint.run/jsonschema/golangci.jsonschema.json
version: '2'
formatters:
  enable: [ 'goimports' ]
  goimports:
    # group in-project imports together
    local-prefixes: [ 'goimportslangci' ]

Go environment

$ go version && go env

go version go1.24.1 darwin/arm64
AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE='on'
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/lewis.miller/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/lewis.miller/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/xz/913d7fmj16q8s2qdnf2p5lym0000gp/T/go-build1966632313=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/lewis.miller/Repos/goimportslangci/go.mod'
GOMODCACHE='/Users/lewis.miller/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/lewis.miller/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/opt/go/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/lewis.miller/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/opt/go/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.1'
GOWORK=''
PKG_CONFIG='pkg-config'

Verbose output of running

$ golangci-lint cache clean

$ golangci-lint run -v

INFO golangci-lint has version 2.0.2 built with go1.24.1 from 2b224c2 on 2025-03-25T20:33:26Z 
INFO [config_reader] Config search paths: [./ /Users/lewis.miller/Repos/goimportslangci /Users/lewis.miller/Repos /Users/lewis.miller /Users /] 
INFO [config_reader] Used config file .golangci.yml 
INFO maxprocs: Leaving GOMAXPROCS=10: CPU quota undefined 
INFO [goenv] Read go env for 9.803916ms: map[string]string{"GOCACHE":"/Users/lewis.miller/Library/Caches/go-build", "GOROOT":"/opt/homebrew/opt/go/libexec"} 
INFO [lintersdb] Active 6 linters: [errcheck goimports govet ineffassign staticcheck unused] 
INFO [loader] Go packages loading at mode 8767 (deps|exports_file|files|name|types_sizes|compiled_files|imports) took 195.669291ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 1.190417ms 
INFO [linters_context/goanalysis] analyzers took 968.07349ms with top 10 stages: buildir: 642.060878ms, ctrlflow: 45.479417ms, nilness: 43.827539ms, fact_deprecated: 43.713166ms, printf: 36.556625ms, SA5012: 35.996956ms, inspect: 33.147542ms, fact_purity: 32.555706ms, typedness: 30.178334ms, goimports: 12.534833ms 
INFO [runner] processing took 1.833µs with stages: max_same_issues: 292ns, exclusion_paths: 250ns, exclusion_rules: 209ns, nolint_filter: 208ns, uniq_by_line: 166ns, path_absoluter: 125ns, severity-rules: 125ns, max_from_linter: 125ns, fixer: 42ns, generated_file_filter: 42ns, filename_unadjuster: 42ns, diff: 42ns, source_code: 42ns, invalid_issue: 41ns, sort_results: 41ns, path_prettifier: 41ns, path_relativity: 0s, cgo: 0s, path_shortener: 0s, max_per_file_from_linter: 0s 
INFO [runner] linters took 585.397333ms with stages: goanalysis_metalinter: 585.33025ms 
0 issues.
INFO File cache stats: 0 entries of total size 0B 
INFO Memory: 9 samples, avg is 140.3MB, max is 260.7MB 
INFO Execution took 793.116416ms  

$ golangci-lint config verify -v

INFO [config_reader] Config search paths: [./ /Users/lewis.miller/Repos/goimportslangci /Users/lewis.miller/Repos /Users/lewis.miller /Users /] 
INFO [config_reader] Used config file .golangci.yml 
jsonschema: "formatters" does not validate with "/properties/formatters/additionalProperties": additional properties 'goimports' not allowed
Failed executing command with error: the configuration contains invalid elements

golangci-lint seems to ignore the config file failure here, but it's flagged in CI by the action

Image

A minimal reproducible example or link to a public repository

// this go code is irrelevant to the issue, but i didnt want to leave the box blank 👍
package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello World")
}

Validation

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

Supporter

@nightmarlin nightmarlin added the bug Something isn't working label Mar 27, 2025
Copy link

boring-cyborg bot commented Mar 27, 2025

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

@nightmarlin
Copy link
Author

looking at the jsonschema file, it seems as though the docs here are wrong: https://github.com/golangci/golangci-lint/blob/main/jsonschema/golangci.jsonschema.json#L4597 implies that the docs at https://golangci-lint.run/usage/formatters/#goimports should actually be

formatters:
  settings:
    goimports:
      # A list of prefixes, which, if set, checks import paths
      # with the given prefixes are grouped after 3rd-party packages.
      # Default: []
      local-prefixes:
        - github.com/org/project

will test and see if that works as expected

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

ldez commented Mar 27, 2025

The documentation has a bug I will fix that.

@ldez ldez added bug Something isn't working area: docs and removed question Further information is requested labels Mar 27, 2025
@nightmarlin
Copy link
Author

thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: docs bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants