diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml index 6e6dff421716..1685b9e72ae6 100644 --- a/.golangci.next.reference.yml +++ b/.golangci.next.reference.yml @@ -3788,6 +3788,12 @@ linters: # Defaults: [ "Unlock", "RUnlock" ] allow-cuddle-with-rhs: [ "Foo", "Bar" ] + # Allow cuddling with any block as long as the variable is used somewhere in + # the block. + # https://github.com/bombsimon/wsl/blob/HEAD/doc/configuration.md#allow-cuddle-used-in-block + # Default: false + allow-cuddle-used-in-block: true + # Causes an error when an If statement that checks an error variable doesn't # cuddle with the assignment of that variable. # https://github.com/bombsimon/wsl/blob/HEAD/doc/configuration.md#force-err-cuddling diff --git a/go.mod b/go.mod index faba42dbd1a0..c2ef531ab1dc 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( github.com/ashanbrown/makezero v1.2.0 github.com/bkielbasa/cyclop v1.2.3 github.com/blizzy78/varnamelen v0.8.0 - github.com/bombsimon/wsl/v4 v4.5.0 + github.com/bombsimon/wsl/v4 v4.6.0 github.com/breml/bidichk v0.3.2 github.com/breml/errchkjson v0.4.0 github.com/butuzov/ireturn v0.3.1 diff --git a/go.sum b/go.sum index 1e7eadc9ee2a..52ae5f3fc34f 100644 --- a/go.sum +++ b/go.sum @@ -94,8 +94,8 @@ github.com/bkielbasa/cyclop v1.2.3 h1:faIVMIGDIANuGPWH031CZJTi2ymOQBULs9H21HSMa5 github.com/bkielbasa/cyclop v1.2.3/go.mod h1:kHTwA9Q0uZqOADdupvcFJQtp/ksSnytRMe8ztxG8Fuo= github.com/blizzy78/varnamelen v0.8.0 h1:oqSblyuQvFsW1hbBHh1zfwrKe3kcSj0rnXkKzsQ089M= github.com/blizzy78/varnamelen v0.8.0/go.mod h1:V9TzQZ4fLJ1DSrjVDfl89H7aMnTvKkApdHeyESmyR7k= -github.com/bombsimon/wsl/v4 v4.5.0 h1:iZRsEvDdyhd2La0FVi5k6tYehpOR/R7qIUjmKk7N74A= -github.com/bombsimon/wsl/v4 v4.5.0/go.mod h1:NOQ3aLF4nD7N5YPXMruR6ZXDOAqLoM0GEpLwTdvmOSc= +github.com/bombsimon/wsl/v4 v4.6.0 h1:ew2R/N42su553DKTYqt3HSxaQN+uHQPv4xZ2MBmwaW4= +github.com/bombsimon/wsl/v4 v4.6.0/go.mod h1:uV/+6BkffuzSAVYD+yGyld1AChO7/EuLrCF/8xTiapg= github.com/breml/bidichk v0.3.2 h1:xV4flJ9V5xWTqxL+/PMFF6dtJPvZLPsyixAoPe8BGJs= github.com/breml/bidichk v0.3.2/go.mod h1:VzFLBxuYtT23z5+iVkamXO386OB+/sVwZOpIj6zXGos= github.com/breml/errchkjson v0.4.0 h1:gftf6uWZMtIa/Is3XJgibewBm2ksAQSY/kABDNFTAdk= diff --git a/jsonschema/golangci.jsonschema.json b/jsonschema/golangci.jsonschema.json index f51e5e86eb23..686de7d66405 100644 --- a/jsonschema/golangci.jsonschema.json +++ b/jsonschema/golangci.jsonschema.json @@ -3954,6 +3954,11 @@ "type": "string" } }, + "allow-cuddle-used-in-block": { + "description": "Allow cuddling with any block as long as the variable is used somewhere in the block", + "type": "boolean", + "default": false + }, "allow-multiline-assign": { "description": "Allow multiline assignments to be cuddled.", "type": "boolean", diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json index f51e5e86eb23..686de7d66405 100644 --- a/jsonschema/golangci.next.jsonschema.json +++ b/jsonschema/golangci.next.jsonschema.json @@ -3954,6 +3954,11 @@ "type": "string" } }, + "allow-cuddle-used-in-block": { + "description": "Allow cuddling with any block as long as the variable is used somewhere in the block", + "type": "boolean", + "default": false + }, "allow-multiline-assign": { "description": "Allow multiline assignments to be cuddled.", "type": "boolean", diff --git a/pkg/commands/internal/migrate/versiontwo/linters_settings.go b/pkg/commands/internal/migrate/versiontwo/linters_settings.go index 2fe5051699bb..3461620e20f7 100644 --- a/pkg/commands/internal/migrate/versiontwo/linters_settings.go +++ b/pkg/commands/internal/migrate/versiontwo/linters_settings.go @@ -749,6 +749,7 @@ type WSLSettings struct { AllowCuddleDeclaration *bool `yaml:"allow-cuddle-declarations,omitempty" toml:"allow-cuddle-declarations,multiline,omitempty"` AllowCuddleWithCalls []string `yaml:"allow-cuddle-with-calls,omitempty" toml:"allow-cuddle-with-calls,multiline,omitempty"` AllowCuddleWithRHS []string `yaml:"allow-cuddle-with-rhs,omitempty" toml:"allow-cuddle-with-rhs,multiline,omitempty"` + AllowCuddleUsedInBlock *bool `yaml:"allow-cuddle-used-in-block,omitempty" toml:"allow-cuddle-used-in-block,multiline,omitempty"` ForceCuddleErrCheckAndAssign *bool `yaml:"force-err-cuddling,omitempty" toml:"force-err-cuddling,multiline,omitempty"` ErrorVariableNames []string `yaml:"error-variable-names,omitempty" toml:"error-variable-names,multiline,omitempty"` ForceExclusiveShortDeclarations *bool `yaml:"force-short-decl-cuddling,omitempty" toml:"force-short-decl-cuddling,multiline,omitempty"` diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 27b67d66da26..db18a564306b 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -188,6 +188,7 @@ var defaultLintersSettings = LintersSettings{ AllowCuddleDeclaration: false, AllowCuddleWithCalls: []string{"Lock", "RLock"}, AllowCuddleWithRHS: []string{"Unlock", "RUnlock"}, + AllowCuddleUsedInBlock: false, ForceCuddleErrCheckAndAssign: false, ErrorVariableNames: []string{"err"}, ForceExclusiveShortDeclarations: false, @@ -972,6 +973,7 @@ type WSLSettings struct { AllowCuddleDeclaration bool `mapstructure:"allow-cuddle-declarations"` AllowCuddleWithCalls []string `mapstructure:"allow-cuddle-with-calls"` AllowCuddleWithRHS []string `mapstructure:"allow-cuddle-with-rhs"` + AllowCuddleUsedInBlock bool `mapstructure:"allow-cuddle-used-in-block"` ForceCuddleErrCheckAndAssign bool `mapstructure:"force-err-cuddling"` ErrorVariableNames []string `mapstructure:"error-variable-names"` ForceExclusiveShortDeclarations bool `mapstructure:"force-short-decl-cuddling"` diff --git a/pkg/golinters/wsl/wsl.go b/pkg/golinters/wsl/wsl.go index 2f71f342e781..12148627eb5b 100644 --- a/pkg/golinters/wsl/wsl.go +++ b/pkg/golinters/wsl/wsl.go @@ -23,6 +23,7 @@ func New(settings *config.WSLSettings) *goanalysis.Linter { AllowCuddleWithCalls: settings.AllowCuddleWithCalls, AllowCuddleWithRHS: settings.AllowCuddleWithRHS, ForceCuddleErrCheckAndAssign: settings.ForceCuddleErrCheckAndAssign, + AllowCuddleUsedInBlock: settings.AllowCuddleUsedInBlock, ErrorVariableNames: settings.ErrorVariableNames, ForceExclusiveShortDeclarations: settings.ForceExclusiveShortDeclarations, IncludeGenerated: true, // force to true because golangci-lint already have a way to filter generated files.