Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,12 @@ linters:
min-complexity: 4

nilnil:
# To check functions with only two return values (`return nil, nil`).
# If disabled then returns like `return nil, nil, ..., nil` are supported.
# Default: true
only-two: false
# In addition, detect opposite situation (simultaneous return of non-nil error and valid value).
# E.g, `return clone, fh.indexer.Update(clone)` will be considered as invalid.
# Default: false
detect-opposite: true
# List of return types to check.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/4meepo/tagalign v1.4.2
github.com/Abirdcfly/dupword v0.1.3
github.com/Antonboom/errname v1.1.0
github.com/Antonboom/nilnil v1.0.1
github.com/Antonboom/nilnil v1.1.0
github.com/Antonboom/testifylint v1.6.0
github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c
github.com/Crocmagnon/fatcontext v0.7.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,11 @@
"type": "object",
"additionalProperties": false,
"properties": {
"only-two": {
"type": "boolean",
"description": "To check functions with only two return values.",
"default": true
},
"detect-opposite": {
"type": "boolean",
"description": "In addition, detect opposite situation (simultaneous return of non-nil error and valid value).",
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ type NestifSettings struct {
}

type NilNilSettings struct {
OnlyTwo *bool `mapstructure:"only-two"`
DetectOpposite bool `mapstructure:"detect-opposite"`
CheckedTypes []string `mapstructure:"checked-types"`
}
Expand Down Expand Up @@ -849,7 +850,6 @@ type TestifylintSettings struct {
Formatter TestifylintFormatter `mapstructure:"formatter"`
GoRequire TestifylintGoRequire `mapstructure:"go-require"`
RequireError TestifylintRequireError `mapstructure:"require-error"`
RequireStringMsg bool `mapstructure:"require-string-msg"`
SuiteExtraAssertCall TestifylintSuiteExtraAssertCall `mapstructure:"suite-extra-assert-call"`
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/golinters/nilnil/nilnil.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func New(settings *config.NilNilSettings) *goanalysis.Linter {
cfg[a.Name] = map[string]any{
"detect-opposite": settings.DetectOpposite,
}
if b := settings.OnlyTwo; b != nil {
cfg[a.Name]["only-two"] = *b
}
if len(settings.CheckedTypes) != 0 {
cfg[a.Name]["checked-types"] = settings.CheckedTypes
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/golinters/nilnil/testdata/nilnil_multiple_nils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//golangcitest:args -Enilnil
//golangcitest:config_path testdata/nilnil_multiple_nils.yml
package testdata

func withoutArgs() {}
func withoutError1() *User { return nil }
func withoutError2() (*User, *User) { return nil, nil }
func withoutError3() (*User, *User, *User) { return nil, nil, nil }
func withoutError4() (*User, *User, *User, *User) { return nil, nil, nil, nil }

func invalidOrder() (error, *User) { return nil, nil }
func withError3rd() (*User, bool, error) { return nil, false, nil } // want "return both a `nil` error and an invalid value: use a sentinel error instead"
func withError4th() (*User, *User, *User, error) { return nil, nil, nil, nil } // want "return both a `nil` error and an invalid value: use a sentinel error instead"

type User struct{}
6 changes: 6 additions & 0 deletions pkg/golinters/nilnil/testdata/nilnil_multiple_nils.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "2"

linters:
settings:
nilnil:
only-two: false
Loading