@@ -190,6 +190,30 @@ func discoverGoRoot() (string, error) {
190
190
return strings .TrimSpace (string (output )), nil
191
191
}
192
192
193
+ // separateNotCompilingPackages moves not compiling packages into separate slices:
194
+ // a lot of linters crash on such packages. Leave them only for those linters
195
+ // which can work with them.
196
+ func separateNotCompilingPackages (lintCtx * golinters.Context ) {
197
+ prog := lintCtx .Program
198
+
199
+ compilingCreated := make ([]* loader.PackageInfo , 0 , len (prog .Created ))
200
+ for _ , info := range prog .Created {
201
+ if len (info .Errors ) != 0 {
202
+ lintCtx .NotCompilingPackages = append (lintCtx .NotCompilingPackages , info )
203
+ } else {
204
+ compilingCreated = append (compilingCreated , info )
205
+ }
206
+ }
207
+ prog .Created = compilingCreated
208
+
209
+ for k , info := range prog .Imported {
210
+ if len (info .Errors ) != 0 {
211
+ lintCtx .NotCompilingPackages = append (lintCtx .NotCompilingPackages , info )
212
+ delete (prog .Imported , k )
213
+ }
214
+ }
215
+ }
216
+
193
217
func buildLintCtx (ctx context.Context , linters []pkg.Linter , cfg * config.Config ) (* golinters.Context , error ) {
194
218
// Set GOROOT to have working cross-compilation: cross-compiled binaries
195
219
// have invalid GOROOT. XXX: can't use runtime.GOROOT().
@@ -228,14 +252,18 @@ func buildLintCtx(ctx context.Context, linters []pkg.Linter, cfg *config.Config)
228
252
astCache = astcache .LoadFromFiles (paths .Files )
229
253
}
230
254
231
- return & golinters.Context {
255
+ ret := & golinters.Context {
232
256
Paths : paths ,
233
257
Cfg : cfg ,
234
258
Program : prog ,
235
259
SSAProgram : ssaProg ,
236
260
LoaderConfig : loaderConfig ,
237
261
ASTCache : astCache ,
238
- }, nil
262
+ }
263
+
264
+ separateNotCompilingPackages (ret )
265
+
266
+ return ret , nil
239
267
}
240
268
241
269
func (e * Executor ) runAnalysis (ctx context.Context , args []string ) (<- chan result.Issue , error ) {
0 commit comments