Skip to content

Commit d4b4ad8

Browse files
bombsimontpounds
authored andcommitted
Update WSL to v1.2.1 (#794)
* Update WSL to v1.2.1 * Add new tests for fixed false positives, don't derive defaults from WSL
1 parent 7577d54 commit d4b4ad8

File tree

12 files changed

+344
-126
lines changed

12 files changed

+344
-126
lines changed

.golangci.example.yml

+9
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@ linters-settings:
211211
whitespace:
212212
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
213213
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
214+
wsl:
215+
# If true append is only allowed to be cuddled if appending value is
216+
# matching variables, fields or types on line above. Default is true.
217+
strict-append: true
218+
# Allow calls and assignments to be cuddled as long as the lines have any
219+
# matching variables, fields or types. Default is true.
220+
allow-assign-and-call: true
221+
# Allow multiline assignments to be cuddled. Default is true.
222+
allow-multiline-assign: true
214223

215224
linters:
216225
enable:

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,15 @@ linters-settings:
804804
whitespace:
805805
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
806806
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
807+
wsl:
808+
# If true append is only allowed to be cuddled if appending value is
809+
# matching variables, fields or types on line above. Default is true.
810+
strict-append: true
811+
# Allow calls and assignments to be cuddled as long as the lines have any
812+
# matching variables, fields or types. Default is true.
813+
allow-assign-and-call: true
814+
# Allow multiline assignments to be cuddled. Default is true.
815+
allow-multiline-assign: true
807816
808817
linters:
809818
enable:

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.12
44

55
require (
66
github.com/OpenPeeDeeP/depguard v1.0.1
7-
github.com/bombsimon/wsl v1.0.1
7+
github.com/bombsimon/wsl v1.2.1
88
github.com/fatih/color v1.7.0
99
github.com/go-critic/go-critic v0.3.5-0.20190904082202-d79a9f0c64db
1010
github.com/go-lintpack/lintpack v0.5.2

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
1111
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
1212
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
1313
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
14-
github.com/bombsimon/wsl v1.0.1 h1:GkrpOj7ajds8re6EJXN+k6UtatYSktupigQ2ZfOUIOU=
15-
github.com/bombsimon/wsl v1.0.1/go.mod h1:DSRwCD8c7NecM11/LnZcTS8nS8OND5ybj04DWM4l8mc=
14+
github.com/bombsimon/wsl v1.2.1 h1:DcLf3V66dJi4a+KHt+F1FdOeBZ05adHqTMYFvjgv06k=
15+
github.com/bombsimon/wsl v1.2.1/go.mod h1:43lEF/i0kpXbLCeDXL9LMT8c92HyBywXb0AsgMHYngM=
1616
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
1717
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
1818
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=

pkg/config/config.go

+12
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ type LintersSettings struct {
176176
MultiFunc bool `mapstructure:"multi-func"`
177177
}
178178

179+
WSL WSLSettings
179180
Lll LllSettings
180181
Unparam UnparamSettings
181182
Nakedret NakedretSettings
@@ -249,6 +250,12 @@ type GocognitSettings struct {
249250
MinComplexity int `mapstructure:"min-complexity"`
250251
}
251252

253+
type WSLSettings struct {
254+
StrictAppend bool `mapstructure:"strict-append"`
255+
AllowAssignAndCallCuddle bool `mapstructure:"allow-assign-and-call"`
256+
AllowMultiLineAssignCuddle bool `mapstructure:"allow-multiline-assign"`
257+
}
258+
252259
var defaultLintersSettings = LintersSettings{
253260
Lll: LllSettings{
254261
LineLength: 120,
@@ -277,6 +284,11 @@ var defaultLintersSettings = LintersSettings{
277284
Gocognit: GocognitSettings{
278285
MinComplexity: 30,
279286
},
287+
WSL: WSLSettings{
288+
StrictAppend: true,
289+
AllowAssignAndCallCuddle: true,
290+
AllowMultiLineAssignCuddle: true,
291+
},
280292
}
281293

282294
type Linters struct {

pkg/golinters/wsl.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,25 @@ func NewWSL() *goanalysis.Linter {
3333
nil,
3434
).WithContextSetter(func(lintCtx *linter.Context) {
3535
analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
36-
files := []string{}
36+
var (
37+
files = []string{}
38+
linterCfg = lintCtx.Cfg.LintersSettings.WSL
39+
processorCfg = wsl.Configuration{
40+
StrictAppend: linterCfg.StrictAppend,
41+
AllowAssignAndCallCuddle: linterCfg.AllowAssignAndCallCuddle,
42+
AllowMultiLineAssignCuddle: linterCfg.AllowMultiLineAssignCuddle,
43+
AllowCuddleWithCalls: []string{"Lock", "RLock"},
44+
AllowCuddleWithRHS: []string{"Unlock", "RUnlock"},
45+
}
46+
)
3747

3848
for _, file := range pass.Files {
3949
files = append(files, pass.Fset.Position(file.Pos()).Filename)
4050
}
4151

42-
wslErrors, _ := wsl.ProcessFiles(files)
52+
wslErrors, _ := wsl.NewProcessorWithConfig(processorCfg).
53+
ProcessFiles(files)
54+
4355
if len(wslErrors) == 0 {
4456
return nil, nil
4557
}

test/testdata/wsl.go

+22
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,26 @@ func main() {
5252
_, cf2 := context.WithCancel(context.Background())
5353
defer cf1() // ERROR "only one cuddle assignment allowed before defer statement"
5454
defer cf2()
55+
56+
err := multiline(
57+
"spanning",
58+
"multiple",
59+
)
60+
if err != nil {
61+
panic(err)
62+
}
63+
64+
notErr := multiline(
65+
"spanning",
66+
"multiple",
67+
)
68+
if err != nil { // ERROR "if statements should only be cuddled with assignments used in the if statement itself"
69+
panic(notErr)
70+
}
71+
}
72+
73+
func multiline(s ...string) error {
74+
return nil
5575
}
5676

5777
func f1() int {
@@ -78,3 +98,5 @@ func f3() int {
7898

7999
return sum + notSum
80100
}
101+
102+
func onelineShouldNotError() error { return nil }

vendor/github.com/bombsimon/wsl/README.md

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/bombsimon/wsl/go.mod

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/bombsimon/wsl/go.sum

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)