Skip to content

Commit 9d2fc84

Browse files
committed
errcheck: add verbose option
1 parent 37932d1 commit 9d2fc84

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

.golangci.next.reference.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ linters:
408408
- io.Copy(*bytes.Buffer)
409409
- io.Copy(os.Stdout)
410410

411+
# Display function signature instead of selector.
412+
# Default: false
413+
verbose: true
414+
411415
errchkjson:
412416
# With check-error-free-encoding set to true, errchkjson does warn about errors
413417
# from json encoding functions that are safe to be ignored,

jsonschema/golangci.next.jsonschema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,11 @@
11151115
"description": "To disable the errcheck built-in exclude list",
11161116
"type": "boolean",
11171117
"default": false
1118+
},
1119+
"verbose": {
1120+
"description": "Display function signature instead of selector",
1121+
"type": "boolean",
1122+
"default": false
11181123
}
11191124
}
11201125
},

pkg/config/linters_settings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ type ErrcheckSettings struct {
372372
CheckTypeAssertions bool `mapstructure:"check-type-assertions"`
373373
CheckAssignToBlank bool `mapstructure:"check-blank"`
374374
ExcludeFunctions []string `mapstructure:"exclude-functions"`
375+
Verbose bool `mapstructure:"verbose"`
375376
}
376377

377378
type ErrChkJSONSettings struct {

pkg/golinters/errcheck/errcheck.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func New(settings *config.ErrcheckSettings) *goanalysis.Linter {
3737
checker.Tags = lintCtx.Cfg.Run.BuildTags
3838

3939
analyzer.Run = func(pass *analysis.Pass) (any, error) {
40-
issues := runErrCheck(pass, checker)
40+
issues := runErrCheck(pass, checker, settings.Verbose)
4141

4242
if len(issues) == 0 {
4343
return nil, nil
@@ -56,7 +56,7 @@ func New(settings *config.ErrcheckSettings) *goanalysis.Linter {
5656
WithLoadMode(goanalysis.LoadModeTypesInfo)
5757
}
5858

59-
func runErrCheck(pass *analysis.Pass, checker *errcheck.Checker) []goanalysis.Issue {
59+
func runErrCheck(pass *analysis.Pass, checker *errcheck.Checker, verbose bool) []goanalysis.Issue {
6060
pkg := &packages.Package{
6161
Fset: pass.Fset,
6262
Syntax: pass.Files,
@@ -76,6 +76,9 @@ func runErrCheck(pass *analysis.Pass, checker *errcheck.Checker) []goanalysis.Is
7676

7777
if err.FuncName != "" {
7878
code := cmp.Or(err.SelectorName, err.FuncName)
79+
if verbose {
80+
code = err.FuncName
81+
}
7982

8083
text = fmt.Sprintf("Error return value of %s is not checked", internal.FormatCode(code))
8184
}

0 commit comments

Comments
 (0)