forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsl.go
102 lines (84 loc) · 2.03 KB
/
wsl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//args: -Ewsl
//config: linters-settings.wsl.tests=1
package testdata
import (
"context"
"fmt"
)
func main() {
var (
y = 0
)
if y < 1 { // ERROR "if statements should only be cuddled with assignments"
fmt.Println("tight")
}
thisIsNotUsedInIf := true
if 2 > 1 { // ERROR "if statements should only be cuddled with assignments used in the if statement itself"
return
}
one := 1
two := 2
three := 3
if three == 3 { // ERROR "only one cuddle assignment allowed before if statement"
fmt.Println("too many cuddled assignments", one, two, thisIsNotUsedInIf)
}
var a = "a"
var b = "b" // ERROR "declarations should never be cuddled"
if true {
return
}
if false { // ERROR "if statements should only be cuddled with assignments"
return
}
for i := range make([]int, 10) {
fmt.Println(i)
fmt.Println(i + i)
continue // ERROR "branch statements should not be cuddled if block has more than two lines"
}
assignOne := a
fmt.Println(assignOne)
assignTwo := b // ERROR "assignments should only be cuddled with other assignments"
fmt.Println(assignTwo)
_, cf1 := context.WithCancel(context.Background())
_, cf2 := context.WithCancel(context.Background())
defer cf1() // ERROR "only one cuddle assignment allowed before defer statement"
defer cf2()
err := multiline(
"spanning",
"multiple",
)
if err != nil {
panic(err)
}
notErr := multiline(
"spanning",
"multiple",
)
if err != nil { // ERROR "if statements should only be cuddled with assignments used in the if statement itself"
panic(notErr)
}
}
func multiline(s ...string) error {
return nil
}
func f1() int {
x := 1
return x
}
func f2() int {
x := 1
y := 3
return x + y // ERROR "return statements should not be cuddled if block has more than two lines"
}
func f3() int {
sum := 0
for _, v := range []int{2, 4, 8} {
sum += v
}
notSum := 0
for _, v := range []int{1, 2, 4} { // ERROR "ranges should only be cuddled with assignments used in the iteration"
sum += v
}
return sum + notSum
}
func onelineShouldNotError() error { return nil }