From e0bd492bb79f88135e71e7781060760fab3763ab Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Wed, 4 Sep 2024 12:37:45 -0400 Subject: [PATCH] internal/fetch,godoc: handle lint exceptions This CL addresses the errors found by staticcheck when we upgraded to Go 1.23. All were deprecation warnings, and they were silenced by "ignore" directives until we could deal with them. In all cases, ignore the lint message was the right choice. The CL adds justifications. Change-Id: I09d4bb96cb9913f8e35189ed3a4af9deaa092447 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/610801 LUCI-TryBot-Result: Go LUCI Reviewed-by: Robert Findley kokoro-CI: kokoro --- internal/fetch/getters.go | 9 ++++++++- internal/godoc/codec/generate.go | 2 +- internal/godoc/codec/testdata/map.go | 2 +- internal/godoc/codec/testdata/slice.go | 2 +- internal/godoc/codec/testdata/struct.go | 2 +- internal/godoc/dochtml/internal/render/render_test.go | 4 ++++ internal/godoc/encode_ast.gen.go | 2 +- internal/godoc/encode_test.go | 2 +- 8 files changed, 18 insertions(+), 7 deletions(-) diff --git a/internal/fetch/getters.go b/internal/fetch/getters.go index 13ae0b539..0fb7e0c39 100644 --- a/internal/fetch/getters.go +++ b/internal/fetch/getters.go @@ -523,7 +523,14 @@ func (g *goPackagesModuleGetter) Search(ctx context.Context, query string, limit continue } if f.Doc != nil { - //lint:ignore SA1019 TODO(jba) create a doc.Package + //lint:ignore SA1019 doc.Synopsis is correct here. + // The lint message warns that doc.Synopsis is deprecated in favor + // of Package.Synopsis. + // Package.Synopsis would display links on separate lines if the + // Package were initialized with a package's code and if the synopsis + // contained links. + // We don't have the code and we wouldn't want the extra lines if we did, + // so doc.Synopsis is a better choice. result.Synopsis = doc.Synopsis(f.Doc.Text()) } } diff --git a/internal/godoc/codec/generate.go b/internal/godoc/codec/generate.go index 8642550d7..8854d628c 100644 --- a/internal/godoc/codec/generate.go +++ b/internal/godoc/codec/generate.go @@ -437,7 +437,7 @@ const initialBody = ` // Code generated by the codec package. DO NOT EDIT. -//lint:file-ignore SA1019 TODO(jba): fix +//lint:file-ignore SA1019 go/doc uses *ast.Object, so we must preserve it. package «.Package» diff --git a/internal/godoc/codec/testdata/map.go b/internal/godoc/codec/testdata/map.go index db8952b9b..611b73068 100644 --- a/internal/godoc/codec/testdata/map.go +++ b/internal/godoc/codec/testdata/map.go @@ -4,7 +4,7 @@ // Code generated by the codec package. DO NOT EDIT. -//lint:file-ignore SA1019 TODO(jba): fix +//lint:file-ignore SA1019 go/doc uses *ast.Object, so we must preserve it. package somepkg diff --git a/internal/godoc/codec/testdata/slice.go b/internal/godoc/codec/testdata/slice.go index 63d145be7..abe002c73 100644 --- a/internal/godoc/codec/testdata/slice.go +++ b/internal/godoc/codec/testdata/slice.go @@ -4,7 +4,7 @@ // Code generated by the codec package. DO NOT EDIT. -//lint:file-ignore SA1019 TODO(jba): fix +//lint:file-ignore SA1019 go/doc uses *ast.Object, so we must preserve it. package somepkg diff --git a/internal/godoc/codec/testdata/struct.go b/internal/godoc/codec/testdata/struct.go index 0c5cf7f0d..d102fc95f 100644 --- a/internal/godoc/codec/testdata/struct.go +++ b/internal/godoc/codec/testdata/struct.go @@ -4,7 +4,7 @@ // Code generated by the codec package. DO NOT EDIT. -//lint:file-ignore SA1019 TODO(jba): fix +//lint:file-ignore SA1019 go/doc uses *ast.Object, so we must preserve it. package somepkg diff --git a/internal/godoc/dochtml/internal/render/render_test.go b/internal/godoc/dochtml/internal/render/render_test.go index 0514a4f64..483423db4 100644 --- a/internal/godoc/dochtml/internal/render/render_test.go +++ b/internal/godoc/dochtml/internal/render/render_test.go @@ -14,6 +14,10 @@ import ( "strings" ) +//lint:file-ignore SA1019 We only need the syntax tree. +// ast.NewPackage is deprecated in favor of go/types, but we don't want or need full +// type information here, just the syntax tree. We are only rendering documentation. + var pkgTime, fsetTime = mustLoadPackage("time") func mustLoadPackage(path string) (*doc.Package, *token.FileSet) { diff --git a/internal/godoc/encode_ast.gen.go b/internal/godoc/encode_ast.gen.go index c27463906..bc49f4d69 100644 --- a/internal/godoc/encode_ast.gen.go +++ b/internal/godoc/encode_ast.gen.go @@ -4,7 +4,7 @@ // Code generated by the codec package. DO NOT EDIT. -//lint:file-ignore SA1019 TODO(jba): fix +//lint:file-ignore SA1019 go/doc uses *ast.Object, so we must preserve it. package godoc diff --git a/internal/godoc/encode_test.go b/internal/godoc/encode_test.go index 05ed056cb..837d08422 100644 --- a/internal/godoc/encode_test.go +++ b/internal/godoc/encode_test.go @@ -188,7 +188,7 @@ func printNode(w io.Writer, root ast.Node) error { idx := len(seen) seen[x] = idx pr("%s#%d", ts, idx) - //lint:ignore SA1019 TODO(jba) remove ast.Object + //lint:ignore SA1019 go/doc uses *ast.Object, so we must preserve it. if obj, ok := x.(*ast.Object); ok { pr(" %s %s %v\n", obj.Name, obj.Kind, obj.Data) prValue(obj.Decl, depth+1)