@@ -227,10 +227,6 @@ func (a *analyzer) run(pass *analysis.Pass) (any, error) {
227
227
}
228
228
229
229
// constraints
230
- for _ , diagnostic := range resultExpConstraints .Diagnostics {
231
- pass .Report (diagnostic )
232
- }
233
-
234
230
a .suggestReplaceImport (pass , imports , resultExpConstraints .shouldKeepImport , pkgExpConstraints , pkgComp )
235
231
236
232
return nil , nil
@@ -250,17 +246,7 @@ func (a *analyzer) detectPackageUsage(pass *analysis.Pass,
250
246
return analysis.Diagnostic {}, false
251
247
}
252
248
253
- obj := pass .TypesInfo .Uses [ident ]
254
- if obj == nil {
255
- return analysis.Diagnostic {}, false
256
- }
257
-
258
- pkg , ok := obj .(* types.PkgName )
259
- if ! ok {
260
- return analysis.Diagnostic {}, false
261
- }
262
-
263
- if pkg .Imported ().Path () != importPath {
249
+ if ! isPackageUsed (pass , ident , importPath ) {
264
250
return analysis.Diagnostic {}, false
265
251
}
266
252
@@ -292,17 +278,7 @@ func (a *analyzer) detectConstraintsUsage(pass *analysis.Pass, expr ast.Expr, re
292
278
return
293
279
}
294
280
295
- obj := pass .TypesInfo .Uses [ident ]
296
- if obj == nil {
297
- return
298
- }
299
-
300
- pkg , ok := obj .(* types.PkgName )
301
- if ! ok {
302
- return
303
- }
304
-
305
- if pkg .Imported ().Path () != pkgExpConstraints {
281
+ if ! isPackageUsed (pass , ident , pkgExpConstraints ) {
306
282
return
307
283
}
308
284
@@ -331,7 +307,7 @@ func (a *analyzer) detectConstraintsUsage(pass *analysis.Pass, expr ast.Expr, re
331
307
}
332
308
}
333
309
334
- result . Diagnostics = append ( result . Diagnostics , diagnostic )
310
+ pass . Report ( diagnostic )
335
311
}
336
312
337
313
func (a * analyzer ) suggestReplaceImport (pass * analysis.Pass , imports map [string ]* ast.ImportSpec , shouldKeep bool , importPath , stdPackage string ) {
@@ -426,6 +402,24 @@ func suggestedFixForConstraintsOrder(selExpr *ast.SelectorExpr) (analysis.Sugges
426
402
}, nil
427
403
}
428
404
405
+ func isPackageUsed (pass * analysis.Pass , ident * ast.Ident , importPath string ) bool {
406
+ obj := pass .TypesInfo .Uses [ident ]
407
+ if obj == nil {
408
+ return false
409
+ }
410
+
411
+ pkg , ok := obj .(* types.PkgName )
412
+ if ! ok {
413
+ return false
414
+ }
415
+
416
+ if pkg .Imported ().Path () != importPath {
417
+ return false
418
+ }
419
+
420
+ return true
421
+ }
422
+
429
423
func getGoVersion (pass * analysis.Pass ) int {
430
424
// Prior to go1.22, versions.FileVersion returns only the toolchain version,
431
425
// which is of no use to us,
0 commit comments