@@ -447,6 +447,18 @@ func checkExampleName(pass *analysis.Pass, fn *ast.FuncDecl) {
447
447
}
448
448
}
449
449
450
+ type tokenRange struct {
451
+ p , e token.Pos
452
+ }
453
+
454
+ func (r tokenRange ) Pos () token.Pos {
455
+ return r .p
456
+ }
457
+
458
+ func (r tokenRange ) End () token.Pos {
459
+ return r .e
460
+ }
461
+
450
462
func checkTest (pass * analysis.Pass , fn * ast.FuncDecl , prefix string ) {
451
463
// Want functions with 0 results and 1 parameter.
452
464
if fn .Type .Results != nil && len (fn .Type .Results .List ) > 0 ||
@@ -464,12 +476,11 @@ func checkTest(pass *analysis.Pass, fn *ast.FuncDecl, prefix string) {
464
476
if tparams := fn .Type .TypeParams ; tparams != nil && len (tparams .List ) > 0 {
465
477
// Note: cmd/go/internal/load also errors about TestXXX and BenchmarkXXX functions with type parameters.
466
478
// We have currently decided to also warn before compilation/package loading. This can help users in IDEs.
467
- // TODO(adonovan): use ReportRangef( tparams).
468
- pass .Reportf ( fn . Pos () , "%s has type parameters: it will not be run by go test as a %sXXX function" , fn .Name .Name , prefix )
479
+ at := tokenRange { tparams . Opening , tparams . Closing }
480
+ pass .ReportRangef ( at , "%s has type parameters: it will not be run by go test as a %sXXX function" , fn .Name .Name , prefix )
469
481
}
470
482
471
483
if ! isTestSuffix (fn .Name .Name [len (prefix ):]) {
472
- // TODO(adonovan): use ReportRangef(fn.Name).
473
- pass .Reportf (fn .Pos (), "%s has malformed name: first letter after '%s' must not be lowercase" , fn .Name .Name , prefix )
484
+ pass .ReportRangef (fn .Name , "%s has malformed name: first letter after '%s' must not be lowercase" , fn .Name .Name , prefix )
474
485
}
475
486
}
0 commit comments