-
Notifications
You must be signed in to change notification settings - Fork 8
/
s.go
145 lines (123 loc) · 2.22 KB
/
s.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package s
import (
"fmt"
"e"
)
type Embedded struct {
E string
F string
g string
H string
}
type Test struct {
A string
B int
C float32
D bool
}
type Test2 struct {
Embedded
External e.External
}
func shouldPass() Test {
return Test{
A: "a",
B: 1,
C: 0.0,
D: false,
}
}
func shouldPassPrivateLocalTypeCorrect1() {
type myTpe struct {
a string
b string
}
_ = myTpe{"", ""}
}
func shouldPassPrivateLocalTypeCorrect2() {
type myTpe struct {
a string
b string
c string
}
_ = myTpe{"", "", ""}
}
func shouldPass2() Test2 {
return Test2{
External: e.External{
A: "",
B: "",
},
Embedded: Embedded{
E: "",
F: "",
H: "",
g: "",
},
}
}
func shouldPassWithReturn() (Test, error) {
if true {
// Empty structs in return statements are ignored if also returning an error
return Test{}, fmt.Errorf("error")
}
_ = Test{} // want "A, B, C, D are missing in Test"
return Test{}, fmt.Errorf("error")
}
func shouldPass3() {
// Checking to make sure state from tracking the previous return statement doesn't affect this struct
_ = Test{} // want "A, B, C, D are missing in Test"
}
func shouldPassWithoutNames() Test {
return Test{"", 0, 0, false}
}
func shouldFailWithReturn() (Test, error) {
// Empty structs in return statements are not ignored if returning nil error
return Test{}, nil // want "A, B, C, D are missing in Test"
}
func shouldFailWithMissingFields() Test {
return Test{ // want "C is missing in Test"
A: "a",
B: 1,
D: false,
}
}
// Unchecked is a struct not listed in StructPatternList
type Unchecked struct {
A int
B int
}
func unchecked() {
// This struct is not listed in StructPatternList so the linter won't complain that it's not filled out
_ = Unchecked{
A: 1,
}
}
func excluded() {
// this struct is excluded therefore should not be linted
_ = e.ExternalExcluded{}
}
func shouldFailOnEmbedded() Test2 {
return Test2{
Embedded: Embedded{ // want "E, g, H are missing in Embedded"
F: "",
},
External: e.External{
A: "",
B: "",
},
}
}
func shoildFailOnExternal() Test2 {
return Test2{
External: e.External{ // want "A is missing in External"
B: "",
},
Embedded: Embedded{
E: "",
F: "",
H: "",
g: "",
},
}
}