From 53d48bfcf544a006a229aeb4d4ffdb6c4c9fa855 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Sat, 30 Nov 2019 17:56:20 -0500 Subject: [PATCH] go/analysis: gofmt snippets in package documentation Tab widths may vary, making tabs suitable for indentation but not alignment. Use spaces for alignment instead, as gofmt does. This improves the readability of the package comment on pkg.go.dev. While here, also make use of blank lines more consistent: two blank lines before a heading, and a single blank line everywhere else. Change-Id: I6b6a67b413d02066e2ce233f09d49c1ccdf28a84 Reviewed-on: https://go-review.googlesource.com/c/tools/+/209457 Reviewed-by: Michael Matloob --- go/analysis/doc.go | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/go/analysis/doc.go b/go/analysis/doc.go index a2353fc88b..1b7b7ed5ae 100644 --- a/go/analysis/doc.go +++ b/go/analysis/doc.go @@ -3,6 +3,7 @@ The analysis package defines the interface between a modular static analysis and an analysis driver program. + Background A static analysis is a function that inspects a package of Go code and @@ -41,9 +42,9 @@ the go/analysis/passes/ subdirectory: package unusedresult var Analyzer = &analysis.Analyzer{ - Name: "unusedresult", - Doc: "check for unused results of calls to some functions", - Run: run, + Name: "unusedresult", + Doc: "check for unused results of calls to some functions", + Run: run, ... } @@ -51,7 +52,6 @@ the go/analysis/passes/ subdirectory: ... } - An analysis driver is a program such as vet that runs a set of analyses and prints the diagnostics that they report. The driver program must import the list of Analyzers it needs. @@ -107,14 +107,14 @@ multiple analyzers. It is based on the multichecker package The Analyzer type has more fields besides those shown above: type Analyzer struct { - Name string - Doc string - Flags flag.FlagSet - Run func(*Pass) (interface{}, error) - RunDespiteErrors bool - ResultType reflect.Type - Requires []*Analyzer - FactTypes []Fact + Name string + Doc string + Flags flag.FlagSet + Run func(*Pass) (interface{}, error) + RunDespiteErrors bool + ResultType reflect.Type + Requires []*Analyzer + FactTypes []Fact } The Flags field declares a set of named (global) flag variables that @@ -154,13 +154,13 @@ package being analyzed, and provides operations to the Run function for reporting diagnostics and other information back to the driver. type Pass struct { - Fset *token.FileSet - Files []*ast.File - OtherFiles []string - Pkg *types.Package - TypesInfo *types.Info - ResultOf map[*Analyzer]interface{} - Report func(Diagnostic) + Fset *token.FileSet + Files []*ast.File + OtherFiles []string + Pkg *types.Package + TypesInfo *types.Info + ResultOf map[*Analyzer]interface{} + Report func(Diagnostic) ... } @@ -245,7 +245,7 @@ package. An Analyzer that uses facts must declare their types: var Analyzer = &analysis.Analyzer{ - Name: "printf", + Name: "printf", FactTypes: []analysis.Fact{new(isWrapper)}, ... } @@ -330,7 +330,5 @@ entirety as: A tool that provides multiple analyzers can use multichecker in a similar way, giving it the list of Analyzers. - - */ package analysis