diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index ff015539fabb..9801a5c3ff87 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -408,6 +408,10 @@ linters: - io.Copy(*bytes.Buffer) - io.Copy(os.Stdout) + # Display function signature instead of selector. + # Default: false + verbose: true + errchkjson: # With check-error-free-encoding set to true, errchkjson does warn about errors # from json encoding functions that are safe to be ignored, diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 9da8ac328072..e98d54dc4dc4 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -1115,6 +1115,11 @@ "description": "To disable the errcheck built-in exclude list", "type": "boolean", "default": false + }, + "verbose": { + "description": "Display function signature instead of selector", + "type": "boolean", + "default": false } } }, diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 065abfab47c1..cadb4a765914 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -372,6 +372,7 @@ type ErrcheckSettings struct { CheckTypeAssertions bool `mapstructure:"check-type-assertions"` CheckAssignToBlank bool `mapstructure:"check-blank"` ExcludeFunctions []string `mapstructure:"exclude-functions"` + Verbose bool `mapstructure:"verbose"` } type ErrChkJSONSettings struct { diff --git a/pkg/golinters/errcheck/errcheck.go b/pkg/golinters/errcheck/errcheck.go index 2e2136caa2ea..ae34a53ef62c 100644 --- a/pkg/golinters/errcheck/errcheck.go +++ b/pkg/golinters/errcheck/errcheck.go @@ -37,7 +37,7 @@ func New(settings *config.ErrcheckSettings) *goanalysis.Linter { checker.Tags = lintCtx.Cfg.Run.BuildTags analyzer.Run = func(pass *analysis.Pass) (any, error) { - issues := runErrCheck(pass, checker) + issues := runErrCheck(pass, checker, settings.Verbose) if len(issues) == 0 { return nil, nil @@ -56,7 +56,7 @@ func New(settings *config.ErrcheckSettings) *goanalysis.Linter { WithLoadMode(goanalysis.LoadModeTypesInfo) } -func runErrCheck(pass *analysis.Pass, checker *errcheck.Checker) []goanalysis.Issue { +func runErrCheck(pass *analysis.Pass, checker *errcheck.Checker, verbose bool) []goanalysis.Issue { pkg := &packages.Package{ Fset: pass.Fset, Syntax: pass.Files, @@ -76,6 +76,9 @@ func runErrCheck(pass *analysis.Pass, checker *errcheck.Checker) []goanalysis.Is if err.FuncName != "" { code := cmp.Or(err.SelectorName, err.FuncName) + if verbose { + code = err.FuncName + } text = fmt.Sprintf("Error return value of %s is not checked", internal.FormatCode(code)) }