From 49f0d947d8afa329c7fa0f9fcece0382ad34d359 Mon Sep 17 00:00:00 2001 From: Anton Telyshev Date: Mon, 17 Mar 2025 12:48:40 +0300 Subject: [PATCH 1/2] bump github.com/Antonboom/nilnil from 1.0.1 to 1.1.0 --- .golangci.next.reference.yml | 5 +++++ go.mod | 2 +- go.sum | 4 ++-- jsonschema/golangci.next.jsonschema.json | 5 +++++ pkg/config/linters_settings.go | 2 +- pkg/golinters/nilnil/nilnil.go | 3 +++ .../nilnil/testdata/nilnil_multiple_nils.go | 15 +++++++++++++++ .../nilnil/testdata/nilnil_multiple_nils.yml | 6 ++++++ 8 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 pkg/golinters/nilnil/testdata/nilnil_multiple_nils.go create mode 100644 pkg/golinters/nilnil/testdata/nilnil_multiple_nils.yml diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 36c49fbc452e..f1eff3cdcb1b 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -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. diff --git a/go.mod b/go.mod index 5d018aa399ef..76a3eee44e5a 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 15018fca544c..e815512f1bb9 100644 --- a/go.sum +++ b/go.sum @@ -41,8 +41,8 @@ github.com/Abirdcfly/dupword v0.1.3 h1:9Pa1NuAsZvpFPi9Pqkd93I7LIYRURj+A//dFd5tgB github.com/Abirdcfly/dupword v0.1.3/go.mod h1:8VbB2t7e10KRNdwTVoxdBaxla6avbhGzb8sCTygUMhw= github.com/Antonboom/errname v1.1.0 h1:A+ucvdpMwlo/myWrkHEUEBWc/xuXdud23S8tmTb/oAE= github.com/Antonboom/errname v1.1.0/go.mod h1:O1NMrzgUcVBGIfi3xlVuvX8Q/VP/73sseCaAppfjqZw= -github.com/Antonboom/nilnil v1.0.1 h1:C3Tkm0KUxgfO4Duk3PM+ztPncTFlOf0b2qadmS0s4xs= -github.com/Antonboom/nilnil v1.0.1/go.mod h1:CH7pW2JsRNFgEh8B2UaPZTEPhCMuFowP/e8Udp9Nnb0= +github.com/Antonboom/nilnil v1.1.0 h1:jGxJxjgYS3VUUtOTNk8Z1icwT5ESpLH/426fjmQG+ng= +github.com/Antonboom/nilnil v1.1.0/go.mod h1:b7sAlogQjFa1wV8jUW3o4PMzDVFLbTux+xnQdvzdcIE= github.com/Antonboom/testifylint v1.6.0 h1:6rdILVPt4+rqcvhid8w9wJNynKLUgqHNpFyM67UeXyc= github.com/Antonboom/testifylint v1.6.0/go.mod h1:k+nEkathI2NFjKO6HvwmSrbzUcQ6FAnbZV+ZRrnXPLI= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index 112bcb721997..8bf37394612c 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -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).", diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 4ecb1b2d94b9..498b93dd00b3 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -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"` } @@ -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"` } diff --git a/pkg/golinters/nilnil/nilnil.go b/pkg/golinters/nilnil/nilnil.go index be5b4ae269b2..5f42e24c96fc 100644 --- a/pkg/golinters/nilnil/nilnil.go +++ b/pkg/golinters/nilnil/nilnil.go @@ -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 } diff --git a/pkg/golinters/nilnil/testdata/nilnil_multiple_nils.go b/pkg/golinters/nilnil/testdata/nilnil_multiple_nils.go new file mode 100644 index 000000000000..132551f4cd5e --- /dev/null +++ b/pkg/golinters/nilnil/testdata/nilnil_multiple_nils.go @@ -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{} diff --git a/pkg/golinters/nilnil/testdata/nilnil_multiple_nils.yml b/pkg/golinters/nilnil/testdata/nilnil_multiple_nils.yml new file mode 100644 index 000000000000..171b31c15bd1 --- /dev/null +++ b/pkg/golinters/nilnil/testdata/nilnil_multiple_nils.yml @@ -0,0 +1,6 @@ +version: "2" + +linters: + settings: + nilnil: + only-two: false From 5d2ed1ae4e547a1a1206c8c5f654fffad69e4dce Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Mon, 17 Mar 2025 13:59:16 +0100 Subject: [PATCH 2/2] review --- jsonschema/golangci.jsonschema.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jsonschema/golangci.jsonschema.json b/jsonschema/golangci.jsonschema.json index 112bcb721997..8bf37394612c 100644 --- a/jsonschema/golangci.jsonschema.json +++ b/jsonschema/golangci.jsonschema.json @@ -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).",