Skip to content

Commit c65785c

Browse files
committed
Add new configuration option
1 parent a72504e commit c65785c

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

.golangci.next.reference.yml

+6
Original file line numberDiff line numberDiff line change
@@ -3885,6 +3885,12 @@ linters-settings:
38853885
# Defaults: [ "Unlock", "RUnlock" ]
38863886
allow-cuddle-with-rhs: [ "Foo", "Bar" ]
38873887

3888+
# Allow cuddling with any block as long as the variable is used somewhere in
3889+
# the block.
3890+
# https://github.com/bombsimon/wsl/blob/HEAD/doc/configuration.md#allow-cuddle-used-in-block
3891+
# Default: false
3892+
allow-cuddle-used-in-block: true
3893+
38883894
# Causes an error when an If statement that checks an error variable doesn't
38893895
# cuddle with the assignment of that variable.
38903896
# https://github.com/bombsimon/wsl/blob/HEAD/doc/configuration.md#force-err-cuddling

jsonschema/golangci.next.jsonschema.json

+5
Original file line numberDiff line numberDiff line change
@@ -3782,6 +3782,11 @@
37823782
"type": "string"
37833783
}
37843784
},
3785+
"allow-cuddle-used-in-block": {
3786+
"description": "Allow cuddling with any block as long as the variable is used somewhere in the block",
3787+
"type": "boolean",
3788+
"default": false
3789+
},
37853790
"allow-multiline-assign": {
37863791
"description": "Allow multiline assignments to be cuddled.",
37873792
"type": "boolean",

pkg/config/linters_settings.go

+2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ var defaultLintersSettings = LintersSettings{
207207
AllowCuddleDeclaration: false,
208208
AllowCuddleWithCalls: []string{"Lock", "RLock"},
209209
AllowCuddleWithRHS: []string{"Unlock", "RUnlock"},
210+
AllowCuddleUsedInBlock: false,
210211
ForceCuddleErrCheckAndAssign: false,
211212
ErrorVariableNames: []string{"err"},
212213
ForceExclusiveShortDeclarations: false,
@@ -1082,6 +1083,7 @@ type WSLSettings struct {
10821083
AllowCuddleDeclaration bool `mapstructure:"allow-cuddle-declarations"`
10831084
AllowCuddleWithCalls []string `mapstructure:"allow-cuddle-with-calls"`
10841085
AllowCuddleWithRHS []string `mapstructure:"allow-cuddle-with-rhs"`
1086+
AllowCuddleUsedInBlock bool `mapstructure:"allow-cuddle-used-in-block"`
10851087
ForceCuddleErrCheckAndAssign bool `mapstructure:"force-err-cuddling"`
10861088
ErrorVariableNames []string `mapstructure:"error-variable-names"`
10871089
ForceExclusiveShortDeclarations bool `mapstructure:"force-short-decl-cuddling"`

pkg/golinters/wsl/wsl.go

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func New(settings *config.WSLSettings) *goanalysis.Linter {
2323
AllowCuddleWithCalls: settings.AllowCuddleWithCalls,
2424
AllowCuddleWithRHS: settings.AllowCuddleWithRHS,
2525
ForceCuddleErrCheckAndAssign: settings.ForceCuddleErrCheckAndAssign,
26+
AllowCuddleUsedInBlock: settings.AllowCuddleUsedInBlock,
2627
ErrorVariableNames: settings.ErrorVariableNames,
2728
ForceExclusiveShortDeclarations: settings.ForceExclusiveShortDeclarations,
2829
IncludeGenerated: true, // force to true because golangci-lint already have a way to filter generated files.

0 commit comments

Comments
 (0)