Skip to content

golangci-lint config verify prints help on verification failure #4596

Closed
@matthewhughes934

Description

@matthewhughes934

Welcome

Description of the problem

Upon failing verification on a config, the verification error is printed and so is the command's help:

$ golangci-lint config verify
jsonschema: "linters-settings.govet" does not validate with "/properties/linters-settings/properties/govet/additionalProperties": additionalProperties 'check-shadowing' not allowed
Error: the configuration contains invalid elements
Usage:
  golangci-lint config verify [flags]

Global Flags:
      --color string   Use color when printing; can be 'always', 'auto', or 'never' (default "auto")
  -c, --config PATH    Read config from file path PATH
  -h, --help           Help for a command
      --no-config      Don't read config file
  -v, --verbose        Verbose output

Failed executing command with error: the configuration contains invalid elements

Expectation: help is only printed if I passed invalid flags/had some invalid setup.
I find printing the help clutters the output and makes it hard to read the reason for the failure

Thanks for adding the config verify command, I was recently looking for exactly this behaviour and was happy to see it included

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.57.2 built with go1.22.1 from 77a8601a on 2024-03-28T19:01:11Z

Configuration

  tests: true

linters-settings:
  errcheck:
    check-type-assertions: true
    check-blank: true
  govet:
    check-shadowing: false
  revive:
    rules:
      - name: exported
        disabled: true
      - name: context-as-argument
        disabled: false
  nolintlint:
    require-specific: true

linters:
  enable:
    - revive
    - misspell
    - nakedret
    - gas
    - unconvert
    - unparam
    - prealloc
    - goimports
    - gofumpt
    - gci

Go environment

$ go version && go env
go version go1.22.1 linux/amd64
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/me/.cache/go-build'
GOENV='/home/me/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/me/.local/share/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/me/.local/share/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.1'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/me/src/personal/go-cov/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1418383092=/tmp/go-build -gno-record-gcc-switches'

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
# paste output here

A minimal reproducible example or link to a public repository

You just need any invalid config (the one shared above will do) then run golangci-lint config verify.

I see cobra.Command has a SilenceUsage attribute but I'm not sure we can set this from within the verify command because of spf13/cobra#564. Maybe executeVerify could run as a command.Run (instead of a command.RunE) and just log its errors?

Validation

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

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