Skip to content

Commit e5f7ae1

Browse files
committed
go/analysis: add Analyser.URL and Diagnostic.URI fields
These fields allow the analyzer to provide links to its online documentation. Also: - set URI field for all x/tools Analyzers. - include these URIs in the gopls docs. Fixes golang/go#57906 Change-Id: Iec0a34386d834edfae4e9161a18a1d14a7a43b74 Reviewed-on: https://go-review.googlesource.com/c/tools/+/476615 Reviewed-by: Robert Findley <[email protected]> Run-TryBot: Alan Donovan <[email protected]> TryBot-Result: Gopher Robot <[email protected]> gopls-CI: kokoro <[email protected]>
1 parent b6dbcf8 commit e5f7ae1

File tree

50 files changed

+97
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+97
-2
lines changed

go/analysis/analysis.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ type Analyzer struct {
2424
// (no capital or period, max ~60 letters).
2525
Doc string
2626

27+
// URL holds an optional link to a web page with additional
28+
// documentation for this analyzer.
29+
URL string
30+
2731
// Flags defines any flags accepted by the analyzer.
2832
// The manner in which these flags are exposed to the user
2933
// depends on the driver which runs the analyzer.

go/analysis/diagnostic.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ type Diagnostic struct {
2020
Category string // optional
2121
Message string
2222

23+
// URL is the optional location of a web page that provides
24+
// additional documentation for this diagnostic.
25+
//
26+
// If URL is empty but a Category is specified, then the
27+
// Analysis driver should treat the URL as "#"+Category.
28+
//
29+
// The URL may be relative. If so, the base URL is that of the
30+
// Analyzer that produced the diagnostic;
31+
// see https://pkg.go.dev/net/url#URL.ResolveReference.
32+
URL string
33+
2334
// SuggestedFixes contains suggested fixes for a diagnostic which can be used to perform
2435
// edits to a file that address the diagnostic.
2536
// TODO(matloob): Should multiple SuggestedFixes be allowed for a diagnostic?

go/analysis/passes/asmdecl/asmdecl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const Doc = "report mismatches between assembly files and Go declarations"
2727
var Analyzer = &analysis.Analyzer{
2828
Name: "asmdecl",
2929
Doc: Doc,
30+
URL: "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/asmdecl",
3031
Run: run,
3132
}
3233

go/analysis/passes/assign/assign.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ usually a mistake.`
3030
var Analyzer = &analysis.Analyzer{
3131
Name: "assign",
3232
Doc: Doc,
33+
URL: "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/assign",
3334
Requires: []*analysis.Analyzer{inspect.Analyzer},
3435
Run: run,
3536
}

go/analysis/passes/atomic/atomic.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ which are not atomic.`
2828
var Analyzer = &analysis.Analyzer{
2929
Name: "atomic",
3030
Doc: Doc,
31+
URL: "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/atomic",
3132
Requires: []*analysis.Analyzer{inspect.Analyzer},
3233
RunDespiteErrors: true,
3334
Run: run,

go/analysis/passes/atomicalign/atomicalign.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const Doc = "check for non-64-bits-aligned arguments to sync/atomic functions"
2525
var Analyzer = &analysis.Analyzer{
2626
Name: "atomicalign",
2727
Doc: Doc,
28+
URL: "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/atomicalign",
2829
Requires: []*analysis.Analyzer{inspect.Analyzer},
2930
Run: run,
3031
}

go/analysis/passes/bools/bools.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const Doc = "check for common mistakes involving boolean operators"
2222
var Analyzer = &analysis.Analyzer{
2323
Name: "bools",
2424
Doc: Doc,
25+
URL: "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/bools",
2526
Requires: []*analysis.Analyzer{inspect.Analyzer},
2627
Run: run,
2728
}

go/analysis/passes/buildssa/buildssa.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
var Analyzer = &analysis.Analyzer{
2323
Name: "buildssa",
2424
Doc: "build SSA-form IR for later passes",
25+
URL: "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/buildssa",
2526
Run: run,
2627
ResultType: reflect.TypeOf(new(SSA)),
2728
}

go/analysis/passes/buildtag/buildtag.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const Doc = "check //go:build and // +build directives"
2525
var Analyzer = &analysis.Analyzer{
2626
Name: "buildtag",
2727
Doc: Doc,
28+
URL: "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/buildtag",
2829
Run: runBuildTag,
2930
}
3031

go/analysis/passes/cgocall/cgocall.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ or slice to C, either directly, or via a pointer, array, or struct.`
3535
var Analyzer = &analysis.Analyzer{
3636
Name: "cgocall",
3737
Doc: Doc,
38+
URL: "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/cgocall",
3839
RunDespiteErrors: true,
3940
Run: run,
4041
}

0 commit comments

Comments
 (0)