Skip to content

Commit da39e26

Browse files
bombsimonldez
andcommitted
wsl: new v5
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent 6d9ab42 commit da39e26

File tree

9 files changed

+233
-92
lines changed

9 files changed

+233
-92
lines changed

.golangci.next.reference.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ linters:
126126
- whitespace
127127
- wrapcheck
128128
- wsl
129+
- wsl_v5
129130
- zerologlint
130131

131132
# Disable specific linters.
@@ -236,6 +237,7 @@ linters:
236237
- whitespace
237238
- wrapcheck
238239
- wsl
240+
- wsl_v5
239241
- zerologlint
240242

241243
# All available settings of specific linters.
@@ -3912,6 +3914,61 @@ linters:
39123914
# Default: false
39133915
force-short-decl-cuddling: true
39143916

3917+
wsl_v5:
3918+
# Allow cuddling a variable if it's used first in the immediate following
3919+
# block, even if the statement with the block doesn't use the variable
3920+
# Default: true
3921+
allow-first-in-block: true
3922+
3923+
# Same as above, but allows cuddling if the variable is used anywhere in
3924+
# the following (or nested) block
3925+
# Default: false
3926+
allow-whole-block: false
3927+
3928+
# If a block contains more than this number of lines the branch statement
3929+
# need to be separated by a whitespace
3930+
# Default: 2
3931+
branch-max-lines: 2
3932+
3933+
# If set to a non negative number, case blocks needs to end with a
3934+
# whitespace if exceeding this number
3935+
# Default: 0
3936+
case-max-lines: 0
3937+
3938+
# Preset with checks. Can be `all`, `none`, `default` or empty
3939+
# Default: ""
3940+
default: ~
3941+
3942+
# Enabled checks. Will be additive to any preset.
3943+
# Default: None
3944+
enable:
3945+
- append
3946+
- assign
3947+
- branch
3948+
- decl
3949+
- defer
3950+
- err
3951+
- expr
3952+
- for
3953+
- go
3954+
- if
3955+
- inc-dec
3956+
- label
3957+
- range
3958+
- return
3959+
- select
3960+
- send
3961+
- switch
3962+
- type-switch
3963+
- leading-whitespace
3964+
- trailing-whitespace
3965+
3966+
# Disable checks. Will be subtractive to any preset.
3967+
# Default: None
3968+
disable:
3969+
- assign-exclusive
3970+
- assign-expr
3971+
39153972
# The custom section can be used to define linter plugins to be loaded at runtime.
39163973
# See README documentation for more info.
39173974
custom:

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ require (
2626
github.com/bkielbasa/cyclop v1.2.3
2727
github.com/blizzy78/varnamelen v0.8.0
2828
github.com/bombsimon/wsl/v4 v4.7.0
29+
github.com/bombsimon/wsl/v5 v5.0.0-rc2
2930
github.com/breml/bidichk v0.3.3
3031
github.com/breml/errchkjson v0.4.1
3132
github.com/butuzov/ireturn v0.4.0

go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/commands/internal/migrate/migrate_linters_settings.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func toAsasalintSettings(old versionone.AsasalintSettings) versiontwo.AsasalintS
100100
}
101101

102102
func toBiDiChkSettings(old versionone.BiDiChkSettings) versiontwo.BiDiChkSettings {
103-
// The values are true be default, but the default are defined after the configuration loading.
103+
// The values are true be default, but the defaults are defined after the configuration loading.
104104
// So the serialization doesn't have good results, but it's complex to do better.
105105
return versiontwo.BiDiChkSettings{
106106
LeftToRightEmbedding: old.LeftToRightEmbedding,
@@ -998,8 +998,8 @@ func toWrapcheckSettings(old versionone.WrapcheckSettings) versiontwo.WrapcheckS
998998
}
999999
}
10001000

1001-
func toWSLSettings(old versionone.WSLSettings) versiontwo.WSLSettings {
1002-
return versiontwo.WSLSettings{
1001+
func toWSLSettings(old versionone.WSLSettings) versiontwo.WSLv4Settings {
1002+
return versiontwo.WSLv4Settings{
10031003
StrictAppend: old.StrictAppend,
10041004
AllowAssignAndCallCuddle: old.AllowAssignAndCallCuddle,
10051005
AllowAssignAndAnythingCuddle: old.AllowAssignAndAnythingCuddle,

pkg/commands/internal/migrate/versiontwo/linters_settings.go

Lines changed: 99 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/linters_settings.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ var defaultLintersSettings = LintersSettings{
184184
MaxDistance: 5,
185185
MinNameLength: 3,
186186
},
187-
WSL: WSLSettings{
187+
WSL: WSLv4Settings{
188188
StrictAppend: true,
189189
AllowAssignAndCallCuddle: true,
190190
AllowAssignAndAnythingCuddle: false,
@@ -200,6 +200,15 @@ var defaultLintersSettings = LintersSettings{
200200
ErrorVariableNames: []string{"err"},
201201
ForceExclusiveShortDeclarations: false,
202202
},
203+
WSLv5: WSLv5Settings{
204+
AllowFirstInBlock: true,
205+
AllowWholeBlock: false,
206+
BranchMaxLines: 2,
207+
CaseMaxLines: 0,
208+
Default: "",
209+
Enable: []string{},
210+
Disable: []string{},
211+
},
203212
}
204213

205214
type LintersSettings struct {
@@ -283,7 +292,8 @@ type LintersSettings struct {
283292
Varnamelen VarnamelenSettings `mapstructure:"varnamelen"`
284293
Whitespace WhitespaceSettings `mapstructure:"whitespace"`
285294
Wrapcheck WrapcheckSettings `mapstructure:"wrapcheck"`
286-
WSL WSLSettings `mapstructure:"wsl"`
295+
WSL WSLv4Settings `mapstructure:"wsl"` // Deprecated: use WSLv5 instead.
296+
WSLv5 WSLv5Settings `mapstructure:"wsl_v5"`
287297

288298
Custom map[string]CustomLinterSettings `mapstructure:"custom"`
289299
}
@@ -992,7 +1002,8 @@ type WrapcheckSettings struct {
9921002
ReportInternalErrors bool `mapstructure:"report-internal-errors"`
9931003
}
9941004

995-
type WSLSettings struct {
1005+
// Deprecated: use WSLv5Settings instead.
1006+
type WSLv4Settings struct {
9961007
StrictAppend bool `mapstructure:"strict-append"`
9971008
AllowAssignAndCallCuddle bool `mapstructure:"allow-assign-and-call"`
9981009
AllowAssignAndAnythingCuddle bool `mapstructure:"allow-assign-and-anything"`
@@ -1009,6 +1020,16 @@ type WSLSettings struct {
10091020
ForceExclusiveShortDeclarations bool `mapstructure:"force-short-decl-cuddling"`
10101021
}
10111022

1023+
type WSLv5Settings struct {
1024+
AllowFirstInBlock bool `mapstructure:"allow-first-in-block"`
1025+
AllowWholeBlock bool `mapstructure:"allow-whole-block"`
1026+
BranchMaxLines int `mapstructure:"branch-max-lines"`
1027+
CaseMaxLines int `mapstructure:"case-max-lines"`
1028+
Default string `mapstructure:"default"`
1029+
Enable []string `mapstructure:"enable"`
1030+
Disable []string `mapstructure:"disable"`
1031+
}
1032+
10121033
// CustomLinterSettings encapsulates the meta-data of a private linter.
10131034
type CustomLinterSettings struct {
10141035
// Type plugin type.

pkg/golinters/wsl/wsl.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package wsl
22

33
import (
4-
"github.com/bombsimon/wsl/v4"
5-
4+
wslv4 "github.com/bombsimon/wsl/v4"
65
"github.com/golangci/golangci-lint/v2/pkg/config"
76
"github.com/golangci/golangci-lint/v2/pkg/goanalysis"
87
)
98

10-
func New(settings *config.WSLSettings) *goanalysis.Linter {
11-
var conf *wsl.Configuration
9+
// Deprecated: use NewV5 instead.
10+
func NewV4(settings *config.WSLv4Settings) *goanalysis.Linter {
11+
var conf *wslv4.Configuration
1212

1313
if settings != nil {
14-
conf = &wsl.Configuration{
14+
conf = &wslv4.Configuration{
1515
StrictAppend: settings.StrictAppend,
1616
AllowAssignAndCallCuddle: settings.AllowAssignAndCallCuddle,
1717
AllowAssignAndAnythingCuddle: settings.AllowAssignAndAnythingCuddle,
@@ -31,6 +31,6 @@ func New(settings *config.WSLSettings) *goanalysis.Linter {
3131
}
3232

3333
return goanalysis.
34-
NewLinterFromAnalyzer(wsl.NewAnalyzer(conf)).
34+
NewLinterFromAnalyzer(wslv4.NewAnalyzer(conf)).
3535
WithLoadMode(goanalysis.LoadModeSyntax)
3636
}

pkg/golinters/wsl/wsl_v5.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package wsl
2+
3+
import (
4+
"github.com/bombsimon/wsl/v5"
5+
"github.com/golangci/golangci-lint/v2/pkg/golinters/internal"
6+
7+
"github.com/golangci/golangci-lint/v2/pkg/config"
8+
"github.com/golangci/golangci-lint/v2/pkg/goanalysis"
9+
)
10+
11+
func NewV5(settings *config.WSLv5Settings) *goanalysis.Linter {
12+
var conf *wsl.Configuration
13+
14+
if settings != nil {
15+
checkSet, err := wsl.NewCheckSet(settings.Default, settings.Enable, settings.Disable)
16+
if err != nil {
17+
internal.LinterLogger.Fatalf("wsl: invalid check: %v", err)
18+
}
19+
20+
conf = &wsl.Configuration{
21+
IncludeGenerated: true, // force to true because golangci-lint already has a way to filter generated files.
22+
AllowFirstInBlock: settings.AllowFirstInBlock,
23+
AllowWholeBlock: settings.AllowWholeBlock,
24+
BranchMaxLines: settings.BranchMaxLines,
25+
CaseMaxLines: settings.CaseMaxLines,
26+
Checks: checkSet,
27+
}
28+
}
29+
30+
return goanalysis.
31+
NewLinterFromAnalyzer(wsl.NewAnalyzer(conf)).
32+
WithVersion(5).
33+
WithLoadMode(goanalysis.LoadModeSyntax)
34+
}

pkg/lint/lintersdb/builder_linter.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,13 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
691691
WithLoadForGoAnalysis().
692692
WithURL("https://github.com/tomarrell/wrapcheck"),
693693

694-
linter.NewConfig(wsl.New(&cfg.Linters.Settings.WSL)).
694+
linter.NewConfig(wsl.NewV4(&cfg.Linters.Settings.WSL)).
695+
DeprecatedWarning("new major version.", "v2.2.0", "wsl_v5").
696+
WithSince("v1.20.0").
697+
WithAutoFix().
698+
WithURL("https://github.com/bombsimon/wsl"),
699+
700+
linter.NewConfig(wsl.NewV5(&cfg.Linters.Settings.WSLv5)).
695701
WithSince("v1.20.0").
696702
WithAutoFix().
697703
WithURL("https://github.com/bombsimon/wsl"),

0 commit comments

Comments
 (0)