File tree Expand file tree Collapse file tree 10 files changed +184
-40
lines changed Expand file tree Collapse file tree 10 files changed +184
-40
lines changed Original file line number Diff line number Diff line change @@ -220,6 +220,10 @@ linters-settings:
220
220
allow-assign-and-call : true
221
221
# Allow multiline assignments to be cuddled. Default is true.
222
222
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
223
227
224
228
linters :
225
229
enable :
Original file line number Diff line number Diff line change @@ -819,6 +819,10 @@ linters-settings:
819
819
allow-assign-and-call: true
820
820
# Allow multiline assignments to be cuddled. Default is true.
821
821
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
822
826
823
827
linters:
824
828
enable:
Original file line number Diff line number Diff line change 4
4
5
5
require (
6
6
github.com/OpenPeeDeeP/depguard v1.0.1
7
- github.com/bombsimon/wsl v1.2.1
7
+ github.com/bombsimon/wsl v1.2.5
8
8
github.com/fatih/color v1.7.0
9
9
github.com/go-critic/go-critic v0.3.5-0.20190904082202-d79a9f0c64db
10
10
github.com/go-lintpack/lintpack v0.5.2
Original file line number Diff line number Diff line change @@ -11,8 +11,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
11
11
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 /go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8 =
12
12
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 /go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q =
13
13
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 =
16
16
github.com/cespare/xxhash v1.1.0 /go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc =
17
17
github.com/client9/misspell v0.3.4 /go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw =
18
18
github.com/coreos/bbolt v1.3.2 /go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk =
Original file line number Diff line number Diff line change @@ -255,9 +255,11 @@ type GocognitSettings struct {
255
255
}
256
256
257
257
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"`
261
263
}
262
264
263
265
var defaultLintersSettings = LintersSettings {
@@ -289,9 +291,11 @@ var defaultLintersSettings = LintersSettings{
289
291
MinComplexity : 30 ,
290
292
},
291
293
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 ,
295
299
},
296
300
}
297
301
Original file line number Diff line number Diff line change @@ -37,11 +37,13 @@ func NewWSL() *goanalysis.Linter {
37
37
files = []string {}
38
38
linterCfg = lintCtx .Cfg .LintersSettings .WSL
39
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" },
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" },
45
47
}
46
48
)
47
49
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ func testOneSource(t *testing.T, sourcePath string) {
105
105
"--print-issued-lines=false" ,
106
106
"--print-linter-name=false" ,
107
107
"--out-format=line-number" ,
108
+ "--max-same-issues=10" ,
108
109
}
109
110
110
111
rc := extractRunContextFromComments (t , sourcePath )
Original file line number Diff line number Diff line change @@ -100,3 +100,75 @@ func f3() int {
100
100
}
101
101
102
102
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
+ }
You can’t perform that action at this time.
0 commit comments