go/analysis/passes/tests: Use ReportRangef to refactor some code in checkTest

Use ReportRangef to replace the original Reportf
to try to implement two TODOs.

Change-Id: I9dfc0f47881d7638e460164a9dc5573394b92eee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/579615
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Tim King <taking@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/go/analysis/passes/tests/tests.go b/go/analysis/passes/tests/tests.go
index 39d0d9e..f5e760c 100644
--- a/go/analysis/passes/tests/tests.go
+++ b/go/analysis/passes/tests/tests.go
@@ -447,6 +447,18 @@
 	}
 }
 
+type tokenRange struct {
+	p, e token.Pos
+}
+
+func (r tokenRange) Pos() token.Pos {
+	return r.p
+}
+
+func (r tokenRange) End() token.Pos {
+	return r.e
+}
+
 func checkTest(pass *analysis.Pass, fn *ast.FuncDecl, prefix string) {
 	// Want functions with 0 results and 1 parameter.
 	if fn.Type.Results != nil && len(fn.Type.Results.List) > 0 ||
@@ -464,12 +476,11 @@
 	if tparams := fn.Type.TypeParams; tparams != nil && len(tparams.List) > 0 {
 		// Note: cmd/go/internal/load also errors about TestXXX and BenchmarkXXX functions with type parameters.
 		// We have currently decided to also warn before compilation/package loading. This can help users in IDEs.
-		// TODO(adonovan): use ReportRangef(tparams).
-		pass.Reportf(fn.Pos(), "%s has type parameters: it will not be run by go test as a %sXXX function", fn.Name.Name, prefix)
+		at := tokenRange{tparams.Opening, tparams.Closing}
+		pass.ReportRangef(at, "%s has type parameters: it will not be run by go test as a %sXXX function", fn.Name.Name, prefix)
 	}
 
 	if !isTestSuffix(fn.Name.Name[len(prefix):]) {
-		// TODO(adonovan): use ReportRangef(fn.Name).
-		pass.Reportf(fn.Pos(), "%s has malformed name: first letter after '%s' must not be lowercase", fn.Name.Name, prefix)
+		pass.ReportRangef(fn.Name, "%s has malformed name: first letter after '%s' must not be lowercase", fn.Name.Name, prefix)
 	}
 }
diff --git a/gopls/internal/test/marker/testdata/diagnostics/analyzers.txt b/gopls/internal/test/marker/testdata/diagnostics/analyzers.txt
index 38f8a81..86f55d9 100644
--- a/gopls/internal/test/marker/testdata/diagnostics/analyzers.txt
+++ b/gopls/internal/test/marker/testdata/diagnostics/analyzers.txt
@@ -34,7 +34,7 @@
 }
 
 // tests
-func Testbad(t *testing.T) { //@diag("", re"Testbad has malformed name: first letter after 'Test' must not be lowercase")
+func Testbad(t *testing.T) { //@diag("Testbad", re"Testbad has malformed name: first letter after 'Test' must not be lowercase")
 }
 
 // timeformat