Skip to content

Commit 22df2d7

Browse files
bombsimonjirfag
authored andcommitted
Update WSL to v1.2.5 (#811)
* Update WSL to v1.2.4 * Fix false positive multiline case * Fix false positive slice expression * Fix false positive index expression * Support to configure/allow cuddle declarations * Support to configurre/allow case blocks to end with whitespace * Support cuddle defer http body close * Re-generate README.md * Update WSL to v1.2.5 * Support output comments for example functions * Fix bad field tag for config
1 parent d47b6f5 commit 22df2d7

File tree

10 files changed

+184
-40
lines changed

10 files changed

+184
-40
lines changed

.golangci.example.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ linters-settings:
220220
allow-assign-and-call: true
221221
# Allow multiline assignments to be cuddled. Default is true.
222222
allow-multiline-assign: true
223+
# Allow case blocks to end with a whitespace.
224+
allow-case-traling-whitespace: true
225+
# Allow declarations (var) to be cuddled.
226+
allow-cuddle-declarations: false
223227

224228
linters:
225229
enable:

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,10 @@ linters-settings:
819819
allow-assign-and-call: true
820820
# Allow multiline assignments to be cuddled. Default is true.
821821
allow-multiline-assign: true
822+
# Allow case blocks to end with a whitespace.
823+
allow-case-traling-whitespace: true
824+
# Allow declarations (var) to be cuddled.
825+
allow-cuddle-declarations: false
822826
823827
linters:
824828
enable:

go.mod

Lines changed: 1 addition & 1 deletion
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.2.1
7+
github.com/bombsimon/wsl v1.2.5
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

Lines changed: 2 additions & 2 deletions
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.2.1 h1:DcLf3V66dJi4a+KHt+F1FdOeBZ05adHqTMYFvjgv06k=
15-
github.com/bombsimon/wsl v1.2.1/go.mod h1:43lEF/i0kpXbLCeDXL9LMT8c92HyBywXb0AsgMHYngM=
14+
github.com/bombsimon/wsl v1.2.5 h1:9gTOkIwVtoDZywvX802SDHokeX4kW1cKnV8ZTVAPkRs=
15+
github.com/bombsimon/wsl v1.2.5/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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,11 @@ type GocognitSettings struct {
255255
}
256256

257257
type WSLSettings struct {
258-
StrictAppend bool `mapstructure:"strict-append"`
259-
AllowAssignAndCallCuddle bool `mapstructure:"allow-assign-and-call"`
260-
AllowMultiLineAssignCuddle bool `mapstructure:"allow-multiline-assign"`
258+
StrictAppend bool `mapstructure:"strict-append"`
259+
AllowAssignAndCallCuddle bool `mapstructure:"allow-assign-and-call"`
260+
AllowMultiLineAssignCuddle bool `mapstructure:"allow-multiline-assign"`
261+
AllowCaseTrailingWhitespace bool `mapstructure:"allow-case-trailing-whitespace"`
262+
AllowCuddleDeclaration bool `mapstructure:"allow-cuddle-declarations"`
261263
}
262264

263265
var defaultLintersSettings = LintersSettings{
@@ -289,9 +291,11 @@ var defaultLintersSettings = LintersSettings{
289291
MinComplexity: 30,
290292
},
291293
WSL: WSLSettings{
292-
StrictAppend: true,
293-
AllowAssignAndCallCuddle: true,
294-
AllowMultiLineAssignCuddle: true,
294+
StrictAppend: true,
295+
AllowAssignAndCallCuddle: true,
296+
AllowMultiLineAssignCuddle: true,
297+
AllowCaseTrailingWhitespace: true,
298+
AllowCuddleDeclaration: false,
295299
},
296300
}
297301

pkg/golinters/wsl.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ func NewWSL() *goanalysis.Linter {
3737
files = []string{}
3838
linterCfg = lintCtx.Cfg.LintersSettings.WSL
3939
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"},
40+
StrictAppend: linterCfg.StrictAppend,
41+
AllowAssignAndCallCuddle: linterCfg.AllowAssignAndCallCuddle,
42+
AllowMultiLineAssignCuddle: linterCfg.AllowMultiLineAssignCuddle,
43+
AllowCaseTrailingWhitespace: linterCfg.AllowCaseTrailingWhitespace,
44+
AllowCuddleDeclaration: linterCfg.AllowCuddleDeclaration,
45+
AllowCuddleWithCalls: []string{"Lock", "RLock"},
46+
AllowCuddleWithRHS: []string{"Unlock", "RUnlock"},
4547
}
4648
)
4749

test/linters_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ func testOneSource(t *testing.T, sourcePath string) {
105105
"--print-issued-lines=false",
106106
"--print-linter-name=false",
107107
"--out-format=line-number",
108+
"--max-same-issues=10",
108109
}
109110

110111
rc := extractRunContextFromComments(t, sourcePath)

test/testdata/wsl.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,75 @@ func f3() int {
100100
}
101101

102102
func onelineShouldNotError() error { return nil }
103+
104+
func multilineCase() {
105+
// Multiline cases
106+
switch {
107+
case true,
108+
false:
109+
fmt.Println("ok")
110+
case false ||
111+
true:
112+
fmt.Println("ok")
113+
case true,
114+
false:
115+
fmt.Println("ok")
116+
}
117+
}
118+
119+
func sliceExpr() {
120+
// Index- and slice expressions.
121+
var aSlice = []int{1, 2, 3}
122+
123+
start := 2
124+
if v := aSlice[start]; v == 1 {
125+
fmt.Println("ok")
126+
}
127+
128+
notOk := 1
129+
if v := aSlice[start]; v == 1 { // ERROR "if statements should only be cuddled with assignments used in the if statement itself"
130+
fmt.Println("notOk")
131+
fmt.Println(notOk)
132+
}
133+
134+
end := 2
135+
if len(aSlice[start:end]) > 2 {
136+
fmt.Println("ok")
137+
}
138+
}
139+
140+
func indexExpr() {
141+
var aMap = map[string]struct{}{"key": {}}
142+
143+
key := "key"
144+
if k, ok := aMap[key]; ok {
145+
fmt.Println(k)
146+
}
147+
148+
xxx := "xxx"
149+
if _, ok := aMap[key]; ok { // ERROR "if statements should only be cuddled with assignments used in the if statement itself"
150+
fmt.Println("not ok")
151+
fmt.Println(xxx)
152+
}
153+
}
154+
155+
func allowTrailing(i int) {
156+
switch i {
157+
case 1:
158+
fmt.Println("one")
159+
160+
case 2:
161+
fmt.Println("two")
162+
163+
case 3:
164+
fmt.Println("three")
165+
}
166+
}
167+
168+
// ExampleSomeOutput simulates an example function.
169+
func ExampleSomeOutput() {
170+
fmt.Println("Hello, world")
171+
172+
// Output:
173+
// Hello, world
174+
}

0 commit comments

Comments
 (0)