go/analysis/passes: ensure diagnostic-reporting analyses have exported Doc

This adds an exported Doc constant to the packages for the analyses that don't
have them that contains the Analyzer.Doc string for the package's Analyzer.
The godoc for the Doc constant can then be linked to in urls reported by
analysis tools.

Change-Id: I39df71abcb29bbddf1866286d63aa5216b6224d8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/207612
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Michael Matloob 2019-11-18 14:06:22 -05:00
parent faf0e61b8a
commit 1ef994f2c9
9 changed files with 23 additions and 13 deletions

View File

@ -22,9 +22,11 @@ import (
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
)
const Doc = "report mismatches between assembly files and Go declarations"
var Analyzer = &analysis.Analyzer{
Name: "asmdecl",
Doc: "report mismatches between assembly files and Go declarations",
Doc: Doc,
Run: run,
}

View File

@ -19,9 +19,11 @@ import (
"golang.org/x/tools/go/ast/inspector"
)
const Doc = "check for non-64-bits-aligned arguments to sync/atomic functions"
var Analyzer = &analysis.Analyzer{
Name: "atomicalign",
Doc: "check for non-64-bits-aligned arguments to sync/atomic functions",
Doc: Doc,
Requires: []*analysis.Analyzer{inspect.Analyzer},
Run: run,
}

View File

@ -17,9 +17,11 @@ import (
"golang.org/x/tools/go/ast/inspector"
)
const Doc = "check for common mistakes involving boolean operators"
var Analyzer = &analysis.Analyzer{
Name: "bools",
Doc: "check for common mistakes involving boolean operators",
Doc: Doc,
Requires: []*analysis.Analyzer{inspect.Analyzer},
Run: run,
}

View File

@ -16,9 +16,11 @@ import (
"golang.org/x/tools/go/analysis/passes/internal/analysisutil"
)
const Doc = "check that +build tags are well-formed and correctly located"
var Analyzer = &analysis.Analyzer{
Name: "buildtag",
Doc: "check that +build tags are well-formed and correctly located",
Doc: Doc,
Run: runBuildTag,
}

View File

@ -23,7 +23,7 @@ import (
const debug = false
const doc = `detect some violations of the cgo pointer passing rules
const Doc = `detect some violations of the cgo pointer passing rules
Check for invalid cgo pointer passing.
This looks for code that uses cgo to call C code passing values
@ -34,7 +34,7 @@ or slice to C, either directly, or via a pointer, array, or struct.`
var Analyzer = &analysis.Analyzer{
Name: "cgocall",
Doc: doc,
Doc: Doc,
RunDespiteErrors: true,
Run: run,
}

View File

@ -16,14 +16,14 @@ import (
"golang.org/x/tools/go/types/typeutil"
)
const doc = `report passing non-pointer or non-error values to errors.As
const Doc = `report passing non-pointer or non-error values to errors.As
The errorsas analysis reports calls to errors.As where the type
of the second argument is not a pointer to a type implementing error.`
var Analyzer = &analysis.Analyzer{
Name: "errorsas",
Doc: doc,
Doc: Doc,
Requires: []*analysis.Analyzer{inspect.Analyzer},
Run: run,
}

View File

@ -33,14 +33,14 @@ func init() {
var Analyzer = &analysis.Analyzer{
Name: "printf",
Doc: doc,
Doc: Doc,
Requires: []*analysis.Analyzer{inspect.Analyzer},
Run: run,
ResultType: reflect.TypeOf((*Result)(nil)),
FactTypes: []analysis.Fact{new(isWrapper)},
}
const doc = `check consistency of Printf format strings and arguments
const Doc = `check consistency of Printf format strings and arguments
The check applies to known functions (for example, those in package fmt)
as well as any detected wrappers of known functions.

View File

@ -21,9 +21,11 @@ import (
"golang.org/x/tools/go/ast/inspector"
)
const Doc = "check for shifts that equal or exceed the width of the integer"
var Analyzer = &analysis.Analyzer{
Name: "shift",
Doc: "check for shifts that equal or exceed the width of the integer",
Doc: Doc,
Requires: []*analysis.Analyzer{inspect.Analyzer},
Run: run,
}

View File

@ -16,14 +16,14 @@ import (
"golang.org/x/tools/go/types/typeutil"
)
const doc = `report passing non-pointer or non-interface values to unmarshal
const Doc = `report passing non-pointer or non-interface values to unmarshal
The unmarshal analysis reports calls to functions such as json.Unmarshal
in which the argument type is not a pointer or an interface.`
var Analyzer = &analysis.Analyzer{
Name: "unmarshal",
Doc: doc,
Doc: Doc,
Requires: []*analysis.Analyzer{inspect.Analyzer},
Run: run,
}