47
47
48
48
// Files return package's files.
49
49
func (p * Package ) Files () map [string ]* File {
50
+ p .RLock ()
51
+ defer p .RUnlock ()
52
+
50
53
return p .files
51
54
}
52
55
@@ -74,20 +77,23 @@ func (p *Package) IsMain() bool {
74
77
func (p * Package ) TypesPkg () * types.Package {
75
78
p .RLock ()
76
79
defer p .RUnlock ()
80
+
77
81
return p .typesPkg
78
82
}
79
83
80
84
// TypesInfo yields type information of this package identifiers
81
85
func (p * Package ) TypesInfo () * types.Info {
82
86
p .RLock ()
83
87
defer p .RUnlock ()
88
+
84
89
return p .typesInfo
85
90
}
86
91
87
92
// Sortable yields a map of sortable types in this package
88
93
func (p * Package ) Sortable () map [string ]bool {
89
94
p .RLock ()
90
95
defer p .RUnlock ()
96
+
91
97
return p .sortable
92
98
}
93
99
@@ -150,9 +156,13 @@ func check(config *types.Config, n string, fset *token.FileSet, astFiles []*ast.
150
156
151
157
// TypeOf returns the type of expression.
152
158
func (p * Package ) TypeOf (expr ast.Expr ) types.Type {
159
+ p .RLock ()
160
+ defer p .RUnlock ()
161
+
153
162
if p .typesInfo == nil {
154
163
return nil
155
164
}
165
+
156
166
return p .typesInfo .TypeOf (expr )
157
167
}
158
168
@@ -166,6 +176,9 @@ const (
166
176
)
167
177
168
178
func (p * Package ) scanSortable () {
179
+ p .Lock ()
180
+ defer p .Unlock ()
181
+
169
182
sortableFlags := map [string ]sortableMethodsFlags {}
170
183
for _ , f := range p .files {
171
184
for _ , decl := range f .AST .Decls {
@@ -191,7 +204,7 @@ func (p *Package) scanSortable() {
191
204
func (p * Package ) lint (rules []Rule , config Config , failures chan Failure ) error {
192
205
p .scanSortable ()
193
206
var eg errgroup.Group
194
- for _ , file := range p .files {
207
+ for _ , file := range p .Files () {
195
208
eg .Go (func () error {
196
209
return file .lint (rules , config , failures )
197
210
})
@@ -202,6 +215,9 @@ func (p *Package) lint(rules []Rule, config Config, failures chan Failure) error
202
215
203
216
// IsAtLeastGoVersion returns true if the Go version for this package is v or higher, false otherwise
204
217
func (p * Package ) IsAtLeastGoVersion (v * goversion.Version ) bool {
218
+ p .RLock ()
219
+ defer p .RUnlock ()
220
+
205
221
return p .goVersion .GreaterThanOrEqual (v )
206
222
}
207
223
0 commit comments