From a0ecdcbec46f2cd944b1ad9e1ffb51b94f227b6b Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Mon, 15 Oct 2018 18:10:24 -0400 Subject: [PATCH] go/analysis/passes: add doc and copyright comments ...and other trivial cleanups. Multi-line doc comments have been moved to exported Doc constants for the sake of godoc. Change-Id: Ib1cbec5806c699d51283c34685c4cd96953f5384 Reviewed-on: https://go-review.googlesource.com/c/142360 Reviewed-by: Michael Matloob --- go/analysis/multichecker/multichecker.go | 15 +++++++++++ go/analysis/passes/asmdecl/asmdecl.go | 2 ++ go/analysis/passes/asmdecl/asmdecl_test.go | 6 ++++- go/analysis/passes/assign/assign.go | 11 +++++--- go/analysis/passes/assign/assign_test.go | 4 +++ go/analysis/passes/atomic/atomic.go | 12 ++++++--- go/analysis/passes/atomic/atomic_test.go | 6 ++++- go/analysis/passes/bools/bools.go | 2 ++ go/analysis/passes/bools/bools_test.go | 6 ++++- go/analysis/passes/buildtag/buildtag.go | 1 + go/analysis/passes/buildtag/buildtag_test.go | 5 +++- go/analysis/passes/cgocall/cgocall.go | 12 ++++++--- go/analysis/passes/cgocall/cgocall_test.go | 6 ++++- go/analysis/passes/composite/composite.go | 12 ++++++--- .../passes/composite/composite_test.go | 6 ++++- go/analysis/passes/copylock/copylock.go | 10 +++++++- go/analysis/passes/copylock/copylock_test.go | 4 +++ go/analysis/passes/ctrlflow/ctrlflow_test.go | 4 +++ go/analysis/passes/findcall/findcall.go | 25 ++++++++++++------- go/analysis/passes/findcall/findcall_test.go | 4 +++ go/analysis/passes/inspect/inspect.go | 2 +- go/analysis/passes/loopclosure/loopclosure.go | 12 ++++++--- .../passes/loopclosure/loopclosure_test.go | 4 +++ go/analysis/passes/lostcancel/lostcancel.go | 6 +++-- .../passes/lostcancel/lostcancel_test.go | 6 ++++- go/analysis/passes/nilfunc/nilfunc.go | 12 ++++++--- go/analysis/passes/nilfunc/nilfunc_test.go | 4 +++ go/analysis/passes/pkgfact/pkgfact.go | 4 +++ go/analysis/passes/pkgfact/pkgfact_test.go | 6 ++++- go/analysis/passes/shift/shift.go | 2 ++ go/analysis/passes/shift/shift_test.go | 6 ++++- go/analysis/passes/stdmethods/stdmethods.go | 12 ++++++--- .../passes/stdmethods/stdmethods_test.go | 4 +++ go/analysis/passes/structtag/structtag.go | 12 ++++++--- .../passes/structtag/structtag_test.go | 6 ++++- go/analysis/passes/tests/tests.go | 14 +++++++---- go/analysis/passes/tests/tests_test.go | 4 +++ go/analysis/passes/unreachable/unreachable.go | 11 +++++--- .../passes/unreachable/unreachable_test.go | 4 +++ go/analysis/passes/unsafeptr/unsafeptr.go | 12 ++++++++- .../passes/unsafeptr/unsafeptr_test.go | 6 ++++- .../passes/unusedresult/unusedresult.go | 12 +++++---- .../passes/unusedresult/unusedresult_test.go | 4 +++ 43 files changed, 247 insertions(+), 71 deletions(-) diff --git a/go/analysis/multichecker/multichecker.go b/go/analysis/multichecker/multichecker.go index ec7243a0..0621cf66 100644 --- a/go/analysis/multichecker/multichecker.go +++ b/go/analysis/multichecker/multichecker.go @@ -15,8 +15,23 @@ import ( "golang.org/x/tools/go/analysis/internal/checker" ) +// TODO(adonovan): support tri-state enable flags so -printf.enable=true means +// "run only printf" and -printf.enable=false means "run all but printf" + +// TODO(adonovan): document (and verify) the exit codes: +// "Vet's exit code is 2 for erroneous invocation of the tool, 1 if a +// problem was reported, and 0 otherwise. Note that the tool does not +// check every possible problem and depends on unreliable heuristics +// so it should be used as guidance only, not as a firm indicator of +// program correctness." + const usage = `Analyze is a tool for static analysis of Go programs. +Analyze examines Go source code and reports suspicious constructs, such as Printf +calls whose arguments do not align with the format string. It uses heuristics +that do not guarantee all reports are genuine problems, but it can find errors +not caught by the compilers. + Usage: analyze [-flag] [package] ` diff --git a/go/analysis/passes/asmdecl/asmdecl.go b/go/analysis/passes/asmdecl/asmdecl.go index 5a076ee2..1e6e32a9 100644 --- a/go/analysis/passes/asmdecl/asmdecl.go +++ b/go/analysis/passes/asmdecl/asmdecl.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package asmdecl defines an Analyzer that reports mismatches between +// assembly files and Go declarations. package asmdecl import ( diff --git a/go/analysis/passes/asmdecl/asmdecl_test.go b/go/analysis/passes/asmdecl/asmdecl_test.go index c703c4bc..e978fbba 100644 --- a/go/analysis/passes/asmdecl/asmdecl_test.go +++ b/go/analysis/passes/asmdecl/asmdecl_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package asmdecl_test import ( @@ -7,7 +11,7 @@ import ( "golang.org/x/tools/go/analysis/passes/asmdecl" ) -func TestFromFileSystem(t *testing.T) { +func Test(t *testing.T) { testdata := analysistest.TestData() analysistest.Run(t, testdata, asmdecl.Analyzer, "a") } diff --git a/go/analysis/passes/assign/assign.go b/go/analysis/passes/assign/assign.go index 271b45e9..4dff2908 100644 --- a/go/analysis/passes/assign/assign.go +++ b/go/analysis/passes/assign/assign.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package assign defines an Analyzer that detects useless assignments. package assign // TODO(adonovan): check also for assignments to struct fields inside @@ -18,13 +19,15 @@ import ( "golang.org/x/tools/go/ast/inspector" ) -var Analyzer = &analysis.Analyzer{ - Name: "assign", - Doc: `check for useless assignments +const Doc = `check for useless assignments This checker reports assignments of the form x = x or a[i] = a[i]. These are almost always useless, and even when they aren't they are -usually a mistake.`, +usually a mistake.` + +var Analyzer = &analysis.Analyzer{ + Name: "assign", + Doc: Doc, Requires: []*analysis.Analyzer{inspect.Analyzer}, Run: run, } diff --git a/go/analysis/passes/assign/assign_test.go b/go/analysis/passes/assign/assign_test.go index bde77095..f43d6dfa 100644 --- a/go/analysis/passes/assign/assign_test.go +++ b/go/analysis/passes/assign/assign_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package assign_test import ( diff --git a/go/analysis/passes/atomic/atomic.go b/go/analysis/passes/atomic/atomic.go index 1c305709..45243d6f 100644 --- a/go/analysis/passes/atomic/atomic.go +++ b/go/analysis/passes/atomic/atomic.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package atomic defines an Analyzer that checks for common mistakes +// using the sync/atomic package. package atomic import ( @@ -15,15 +17,17 @@ import ( "golang.org/x/tools/go/ast/inspector" ) -var Analyzer = &analysis.Analyzer{ - Name: "atomic", - Doc: `check for common mistakes using the sync/atomic package +const Doc = `check for common mistakes using the sync/atomic package The atomic checker looks for assignment statements of the form: x = atomic.AddUint64(&x, 1) -which are not atomic.`, +which are not atomic.` + +var Analyzer = &analysis.Analyzer{ + Name: "atomic", + Doc: Doc, Requires: []*analysis.Analyzer{inspect.Analyzer}, RunDespiteErrors: true, Run: run, diff --git a/go/analysis/passes/atomic/atomic_test.go b/go/analysis/passes/atomic/atomic_test.go index d34bb748..f5f60a3f 100644 --- a/go/analysis/passes/atomic/atomic_test.go +++ b/go/analysis/passes/atomic/atomic_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package atomic_test import ( @@ -7,7 +11,7 @@ import ( "golang.org/x/tools/go/analysis/passes/atomic" ) -func TestFromFileSystem(t *testing.T) { +func Test(t *testing.T) { testdata := analysistest.TestData() analysistest.Run(t, testdata, atomic.Analyzer, "a") } diff --git a/go/analysis/passes/bools/bools.go b/go/analysis/passes/bools/bools.go index 40ca730d..0e6f2695 100644 --- a/go/analysis/passes/bools/bools.go +++ b/go/analysis/passes/bools/bools.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package bools defines an Analyzer that detects common mistakes +// involving boolean operators. package bools import ( diff --git a/go/analysis/passes/bools/bools_test.go b/go/analysis/passes/bools/bools_test.go index ed959598..57324707 100644 --- a/go/analysis/passes/bools/bools_test.go +++ b/go/analysis/passes/bools/bools_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package bools_test import ( @@ -7,7 +11,7 @@ import ( "golang.org/x/tools/go/analysis/passes/bools" ) -func TestFromFileSystem(t *testing.T) { +func Test(t *testing.T) { testdata := analysistest.TestData() analysistest.Run(t, testdata, bools.Analyzer, "a") } diff --git a/go/analysis/passes/buildtag/buildtag.go b/go/analysis/passes/buildtag/buildtag.go index 7187afaa..5a441e60 100644 --- a/go/analysis/passes/buildtag/buildtag.go +++ b/go/analysis/passes/buildtag/buildtag.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package buildtag defines an Analyzer that checks build tags. package buildtag import ( diff --git a/go/analysis/passes/buildtag/buildtag_test.go b/go/analysis/passes/buildtag/buildtag_test.go index 98aec64a..e95cc1a2 100644 --- a/go/analysis/passes/buildtag/buildtag_test.go +++ b/go/analysis/passes/buildtag/buildtag_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package buildtag_test import ( @@ -9,6 +13,5 @@ import ( func Test(t *testing.T) { testdata := analysistest.TestData() - // loads testdata/src/a/a.go analysistest.Run(t, testdata, buildtag.Analyzer, "a") } diff --git a/go/analysis/passes/cgocall/cgocall.go b/go/analysis/passes/cgocall/cgocall.go index daf65b97..7eb24a4a 100644 --- a/go/analysis/passes/cgocall/cgocall.go +++ b/go/analysis/passes/cgocall/cgocall.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package cgocall defines an Analyzer that detects some violations of +// the cgo pointer passing rules. package cgocall import ( @@ -18,16 +20,18 @@ import ( "golang.org/x/tools/go/ast/inspector" ) -var Analyzer = &analysis.Analyzer{ - Name: "cgocall", - 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 whose types are almost always invalid according to the cgo pointer sharing rules. Specifically, it warns about attempts to pass a Go chan, map, func, -or slice to C, either directly, or via a pointer, array, or struct.`, +or slice to C, either directly, or via a pointer, array, or struct.` + +var Analyzer = &analysis.Analyzer{ + Name: "cgocall", + Doc: Doc, Requires: []*analysis.Analyzer{inspect.Analyzer}, RunDespiteErrors: true, Run: run, diff --git a/go/analysis/passes/cgocall/cgocall_test.go b/go/analysis/passes/cgocall/cgocall_test.go index db228187..aebd4327 100644 --- a/go/analysis/passes/cgocall/cgocall_test.go +++ b/go/analysis/passes/cgocall/cgocall_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package cgocall_test import ( @@ -7,7 +11,7 @@ import ( "golang.org/x/tools/go/analysis/passes/cgocall" ) -func TestFromFileSystem(t *testing.T) { +func Test(t *testing.T) { testdata := analysistest.TestData() analysistest.Run(t, testdata, cgocall.Analyzer, "a", "b") } diff --git a/go/analysis/passes/composite/composite.go b/go/analysis/passes/composite/composite.go index 403cbe93..b7cfe8a9 100644 --- a/go/analysis/passes/composite/composite.go +++ b/go/analysis/passes/composite/composite.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package composite defines an Analyzer that checks for unkeyed +// composite literals. package composite import ( @@ -14,14 +16,16 @@ import ( "golang.org/x/tools/go/ast/inspector" ) -var Analyzer = &analysis.Analyzer{ - Name: "composites", - Doc: `checked for unkeyed composite literals +const Doc = `checked for unkeyed composite literals This analyzer reports a diagnostic for composite literals of struct types imported from another package that do not use the field-keyed syntax. Such literals are fragile because the addition of a new field -(even if unexported) to the struct will cause compilation to fail.`, +(even if unexported) to the struct will cause compilation to fail.` + +var Analyzer = &analysis.Analyzer{ + Name: "composites", + Doc: Doc, Requires: []*analysis.Analyzer{inspect.Analyzer}, RunDespiteErrors: true, Run: run, diff --git a/go/analysis/passes/composite/composite_test.go b/go/analysis/passes/composite/composite_test.go index 384898a6..c55015c2 100644 --- a/go/analysis/passes/composite/composite_test.go +++ b/go/analysis/passes/composite/composite_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package composite_test import ( @@ -7,7 +11,7 @@ import ( "golang.org/x/tools/go/analysis/passes/composite" ) -func TestFromFileSystem(t *testing.T) { +func Test(t *testing.T) { testdata := analysistest.TestData() analysistest.Run(t, testdata, composite.Analyzer, "a") } diff --git a/go/analysis/passes/copylock/copylock.go b/go/analysis/passes/copylock/copylock.go index c199c2ea..067aed57 100644 --- a/go/analysis/passes/copylock/copylock.go +++ b/go/analysis/passes/copylock/copylock.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package copylock defines an Analyzer that checks for locks +// erroneously passed by value. package copylock import ( @@ -17,9 +19,15 @@ import ( "golang.org/x/tools/go/ast/inspector" ) +const Doc = `check for locks erroneously passed by value + +Inadvertently copying a value containing a lock, such as sync.Mutex or +sync.WaitGroup, may cause both copies to malfunction. Generally such +values should be referred to through a pointer.` + var Analyzer = &analysis.Analyzer{ Name: "copylocks", - Doc: "check for locks erroneously passed by value", + Doc: Doc, Requires: []*analysis.Analyzer{inspect.Analyzer}, RunDespiteErrors: true, Run: run, diff --git a/go/analysis/passes/copylock/copylock_test.go b/go/analysis/passes/copylock/copylock_test.go index acbdb52a..d33d0a2e 100644 --- a/go/analysis/passes/copylock/copylock_test.go +++ b/go/analysis/passes/copylock/copylock_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package copylock_test import ( diff --git a/go/analysis/passes/ctrlflow/ctrlflow_test.go b/go/analysis/passes/ctrlflow/ctrlflow_test.go index 658da9ff..0aae7cb0 100644 --- a/go/analysis/passes/ctrlflow/ctrlflow_test.go +++ b/go/analysis/passes/ctrlflow/ctrlflow_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package ctrlflow_test import ( diff --git a/go/analysis/passes/findcall/findcall.go b/go/analysis/passes/findcall/findcall.go index 31f3f0b5..ebc6e86a 100644 --- a/go/analysis/passes/findcall/findcall.go +++ b/go/analysis/passes/findcall/findcall.go @@ -1,6 +1,11 @@ -// The findcall package is a trivial example and test of an analyzer of -// Go source code. It reports a diagnostic for every call to a function or -// method of the name specified by its --name flag. +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// The findcall package defines an Analyzer that serves as a trivial +// example and test of the Analysis API. It reports a diagnostic for +// every call to a function or method of the name specified by its +// -name flag. package findcall import ( @@ -10,13 +15,15 @@ import ( "golang.org/x/tools/go/analysis" ) -var Analyzer = &analysis.Analyzer{ - Name: "findcall", - Doc: `find calls to a particular function +const Doc = `find calls to a particular function The findcall analysis reports calls to functions or methods -of a particular name.`, - Run: findcall, +of a particular name.` + +var Analyzer = &analysis.Analyzer{ + Name: "findcall", + Doc: Doc, + Run: run, RunDespiteErrors: true, FactTypes: []analysis.Fact{new(foundFact)}, } @@ -27,7 +34,7 @@ func init() { Analyzer.Flags.StringVar(&name, "name", name, "name of the function to find") } -func findcall(pass *analysis.Pass) (interface{}, error) { +func run(pass *analysis.Pass) (interface{}, error) { for _, f := range pass.Files { ast.Inspect(f, func(n ast.Node) bool { if call, ok := n.(*ast.CallExpr); ok { diff --git a/go/analysis/passes/findcall/findcall_test.go b/go/analysis/passes/findcall/findcall_test.go index f1b9adc1..788bc1e5 100644 --- a/go/analysis/passes/findcall/findcall_test.go +++ b/go/analysis/passes/findcall/findcall_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package findcall_test import ( diff --git a/go/analysis/passes/inspect/inspect.go b/go/analysis/passes/inspect/inspect.go index d9c0c2c0..bd065499 100644 --- a/go/analysis/passes/inspect/inspect.go +++ b/go/analysis/passes/inspect/inspect.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Package inspect is an analysis that provides an AST inspector +// Package inspect defines an Analyzer that provides an AST inspector // (golang.org/x/tools/go/ast/inspect.Inspect) for the syntax trees of a // package. It is only a building block for other analyzers. // diff --git a/go/analysis/passes/loopclosure/loopclosure.go b/go/analysis/passes/loopclosure/loopclosure.go index e71630bb..da071406 100644 --- a/go/analysis/passes/loopclosure/loopclosure.go +++ b/go/analysis/passes/loopclosure/loopclosure.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package loopclosure defines an Analyzer that checks for references to +// enclosing loop variables from within nested functions. package loopclosure import ( @@ -22,9 +24,7 @@ import ( // }() // } -var Analyzer = &analysis.Analyzer{ - Name: "loopclosure", - Doc: `check references to loop variables from within nested functions +const Doc = `check references to loop variables from within nested functions This analyzer checks for references to loop variables from within a function literal inside the loop body. It checks only instances where @@ -40,7 +40,11 @@ For example: }() } -See: https://golang.org/doc/go_faq.html#closures_and_goroutines`, +See: https://golang.org/doc/go_faq.html#closures_and_goroutines` + +var Analyzer = &analysis.Analyzer{ + Name: "loopclosure", + Doc: Doc, Requires: []*analysis.Analyzer{inspect.Analyzer}, Run: run, } diff --git a/go/analysis/passes/loopclosure/loopclosure_test.go b/go/analysis/passes/loopclosure/loopclosure_test.go index 8253ab72..0916f5e6 100644 --- a/go/analysis/passes/loopclosure/loopclosure_test.go +++ b/go/analysis/passes/loopclosure/loopclosure_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package loopclosure_test import ( diff --git a/go/analysis/passes/lostcancel/lostcancel.go b/go/analysis/passes/lostcancel/lostcancel.go index d022b34e..fcf9f553 100644 --- a/go/analysis/passes/lostcancel/lostcancel.go +++ b/go/analysis/passes/lostcancel/lostcancel.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package lostcancel defines an Analyzer that checks for failure to +// call a context cancelation function. package lostcancel import ( @@ -16,7 +18,7 @@ import ( "golang.org/x/tools/go/cfg" ) -const doc = `check cancel func returned by context.WithCancel is called +const Doc = `check cancel func returned by context.WithCancel is called The cancelation function returned by context.WithCancel, WithTimeout, and WithDeadline must be called or the new context will remain live @@ -25,7 +27,7 @@ until its parent context is cancelled. var Analyzer = &analysis.Analyzer{ Name: "lostcancel", - Doc: doc, + Doc: Doc, Run: run, Requires: []*analysis.Analyzer{ inspect.Analyzer, diff --git a/go/analysis/passes/lostcancel/lostcancel_test.go b/go/analysis/passes/lostcancel/lostcancel_test.go index 759634b4..5fe817b3 100644 --- a/go/analysis/passes/lostcancel/lostcancel_test.go +++ b/go/analysis/passes/lostcancel/lostcancel_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package lostcancel_test import ( @@ -9,5 +13,5 @@ import ( func Test(t *testing.T) { testdata := analysistest.TestData() - analysistest.Run(t, testdata, lostcancel.Analyzer, "a") // load testdata/src/a/a.go + analysistest.Run(t, testdata, lostcancel.Analyzer, "a") } diff --git a/go/analysis/passes/nilfunc/nilfunc.go b/go/analysis/passes/nilfunc/nilfunc.go index 7a2344ff..9c2d4df2 100644 --- a/go/analysis/passes/nilfunc/nilfunc.go +++ b/go/analysis/passes/nilfunc/nilfunc.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package nilfunc defines an Analyzer that checks for useless +// comparisons against nil. package nilfunc import ( @@ -14,11 +16,13 @@ import ( "golang.org/x/tools/go/ast/inspector" ) -var Analyzer = &analysis.Analyzer{ - Name: "nilfunc", - Doc: `check for useless comparisons between functions and nil +const Doc = `check for useless comparisons between functions and nil -A useless comparison is one like f == nil as opposed to f() == nil.`, +A useless comparison is one like f == nil as opposed to f() == nil.` + +var Analyzer = &analysis.Analyzer{ + Name: "nilfunc", + Doc: Doc, Requires: []*analysis.Analyzer{inspect.Analyzer}, Run: run, } diff --git a/go/analysis/passes/nilfunc/nilfunc_test.go b/go/analysis/passes/nilfunc/nilfunc_test.go index 8218e713..6eac063d 100644 --- a/go/analysis/passes/nilfunc/nilfunc_test.go +++ b/go/analysis/passes/nilfunc/nilfunc_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package nilfunc_test import ( diff --git a/go/analysis/passes/pkgfact/pkgfact.go b/go/analysis/passes/pkgfact/pkgfact.go index d1ba6c2a..eca0f256 100644 --- a/go/analysis/passes/pkgfact/pkgfact.go +++ b/go/analysis/passes/pkgfact/pkgfact.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + // The pkgfact package is a demonstration and test of the package fact // mechanism. // diff --git a/go/analysis/passes/pkgfact/pkgfact_test.go b/go/analysis/passes/pkgfact/pkgfact_test.go index 1e408833..c0e1f403 100644 --- a/go/analysis/passes/pkgfact/pkgfact_test.go +++ b/go/analysis/passes/pkgfact/pkgfact_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package pkgfact_test import ( @@ -9,5 +13,5 @@ import ( func Test(t *testing.T) { testdata := analysistest.TestData() - analysistest.Run(t, testdata, pkgfact.Analyzer, "c") // load testdata/src/c/c.go + analysistest.Run(t, testdata, pkgfact.Analyzer, "c") } diff --git a/go/analysis/passes/shift/shift.go b/go/analysis/passes/shift/shift.go index 889f5f38..56b150b2 100644 --- a/go/analysis/passes/shift/shift.go +++ b/go/analysis/passes/shift/shift.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package shift defines an Analyzer that checks for shifts that exceed +// the width of an integer. package shift // TODO(adonovan): integrate with ctrflow (CFG-based) dead code analysis. May diff --git a/go/analysis/passes/shift/shift_test.go b/go/analysis/passes/shift/shift_test.go index 56741d8e..8b41b609 100644 --- a/go/analysis/passes/shift/shift_test.go +++ b/go/analysis/passes/shift/shift_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package shift_test import ( @@ -7,7 +11,7 @@ import ( "golang.org/x/tools/go/analysis/passes/shift" ) -func TestFromFileSystem(t *testing.T) { +func Test(t *testing.T) { testdata := analysistest.TestData() analysistest.Run(t, testdata, shift.Analyzer, "a") } diff --git a/go/analysis/passes/stdmethods/stdmethods.go b/go/analysis/passes/stdmethods/stdmethods.go index 840a1b9d..eead289e 100644 --- a/go/analysis/passes/stdmethods/stdmethods.go +++ b/go/analysis/passes/stdmethods/stdmethods.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package stdmethods defines an Analyzer that checks for misspellings +// in the signatures of methods similar to well-known interfaces. package stdmethods import ( @@ -18,9 +20,7 @@ import ( "golang.org/x/tools/go/ast/inspector" ) -var Analyzer = &analysis.Analyzer{ - Name: "stdmethods", - Doc: `check signature of methods of well-known interfaces +const Doc = `check signature of methods of well-known interfaces Sometimes a type may be intended to satisfy an interface but may fail to do so because of a mistake in its method signature. @@ -39,7 +39,11 @@ Checked method names include: Peek ReadByte ReadFrom ReadRune Scan Seek UnmarshalJSON UnreadByte UnreadRune WriteByte WriteTo -`, +` + +var Analyzer = &analysis.Analyzer{ + Name: "stdmethods", + Doc: Doc, Requires: []*analysis.Analyzer{inspect.Analyzer}, Run: run, } diff --git a/go/analysis/passes/stdmethods/stdmethods_test.go b/go/analysis/passes/stdmethods/stdmethods_test.go index 33a0f9a8..fe4fe53c 100644 --- a/go/analysis/passes/stdmethods/stdmethods_test.go +++ b/go/analysis/passes/stdmethods/stdmethods_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package stdmethods_test import ( diff --git a/go/analysis/passes/structtag/structtag.go b/go/analysis/passes/structtag/structtag.go index 48b64771..78133fe6 100644 --- a/go/analysis/passes/structtag/structtag.go +++ b/go/analysis/passes/structtag/structtag.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package structtag defines an Analyzer that checks struct field tags +// are well formed. package structtag import ( @@ -19,11 +21,13 @@ import ( "golang.org/x/tools/go/ast/inspector" ) -var Analyzer = &analysis.Analyzer{ - Name: "structtag", - Doc: `check that struct field tags conform to reflect.StructTag.Get +const Doc = `check that struct field tags conform to reflect.StructTag.Get -Also report certain struct tags (json, xml) used with unexported fields.`, +Also report certain struct tags (json, xml) used with unexported fields.` + +var Analyzer = &analysis.Analyzer{ + Name: "structtag", + Doc: Doc, Requires: []*analysis.Analyzer{inspect.Analyzer}, RunDespiteErrors: true, Run: run, diff --git a/go/analysis/passes/structtag/structtag_test.go b/go/analysis/passes/structtag/structtag_test.go index 7ce6d0b1..1755bea8 100644 --- a/go/analysis/passes/structtag/structtag_test.go +++ b/go/analysis/passes/structtag/structtag_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package structtag_test import ( @@ -7,7 +11,7 @@ import ( "golang.org/x/tools/go/analysis/passes/structtag" ) -func TestFromFileSystem(t *testing.T) { +func Test(t *testing.T) { testdata := analysistest.TestData() analysistest.Run(t, testdata, structtag.Analyzer, "a") } diff --git a/go/analysis/passes/tests/tests.go b/go/analysis/passes/tests/tests.go index fca9854c..35b0a3e7 100644 --- a/go/analysis/passes/tests/tests.go +++ b/go/analysis/passes/tests/tests.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package tests defines an Analyzer that checks for common mistaken +// usages of tests and examples. package tests import ( @@ -14,14 +16,16 @@ import ( "golang.org/x/tools/go/analysis" ) -var Analyzer = &analysis.Analyzer{ - Name: "tests", - Doc: `check for common mistaken usages of tests and examples +const Doc = `check for common mistaken usages of tests and examples The tests checker walks Test, Benchmark and Example functions checking malformed names, wrong signatures and examples documenting non-existent -identifiers.`, - Run: run, +identifiers.` + +var Analyzer = &analysis.Analyzer{ + Name: "tests", + Doc: Doc, + Run: run, } func run(pass *analysis.Pass) (interface{}, error) { diff --git a/go/analysis/passes/tests/tests_test.go b/go/analysis/passes/tests/tests_test.go index 6d42a1a9..172ae8ef 100644 --- a/go/analysis/passes/tests/tests_test.go +++ b/go/analysis/passes/tests/tests_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package tests_test import ( diff --git a/go/analysis/passes/unreachable/unreachable.go b/go/analysis/passes/unreachable/unreachable.go index 98cad56a..19bc9c2d 100644 --- a/go/analysis/passes/unreachable/unreachable.go +++ b/go/analysis/passes/unreachable/unreachable.go @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package unreachable defines an Analyzer that checks for unreachable code. package unreachable // TODO(adonovan): use the new cfg package, which is more precise. @@ -16,13 +17,15 @@ import ( "golang.org/x/tools/go/ast/inspector" ) -var Analyzer = &analysis.Analyzer{ - Name: "unreachable", - Doc: `check for unreachable code +const Doc = `check for unreachable code The unreachable analyzer finds statements that execution can never reach because they are preceded by an return statement, a call to panic, an -infinite loop, or similar constructs.`, +infinite loop, or similar constructs.` + +var Analyzer = &analysis.Analyzer{ + Name: "unreachable", + Doc: Doc, Requires: []*analysis.Analyzer{inspect.Analyzer}, RunDespiteErrors: true, Run: run, diff --git a/go/analysis/passes/unreachable/unreachable_test.go b/go/analysis/passes/unreachable/unreachable_test.go index e38feaff..13f56897 100644 --- a/go/analysis/passes/unreachable/unreachable_test.go +++ b/go/analysis/passes/unreachable/unreachable_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package unreachable_test import ( diff --git a/go/analysis/passes/unsafeptr/unsafeptr.go b/go/analysis/passes/unsafeptr/unsafeptr.go index aa5518ec..116d622b 100644 --- a/go/analysis/passes/unsafeptr/unsafeptr.go +++ b/go/analysis/passes/unsafeptr/unsafeptr.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// Package unsafeptr defines an Analyzer that checks for invalid +// conversions of uintptr to unsafe.Pointer. package unsafeptr import ( @@ -14,9 +16,17 @@ import ( "golang.org/x/tools/go/ast/inspector" ) +const Doc = `check for invalid conversions of uintptr to unsafe.Pointer + +The unsafeptr analyzer reports likely incorrect uses of unsafe.Pointer +to convert integers to pointers. A conversion from uintptr to +unsafe.Pointer is invalid if it implies that there is a uintptr-typed +word in memory that holds a pointer value, because that word will be +invisible to stack copying and to the garbage collector.` + var Analyzer = &analysis.Analyzer{ Name: "unsafeptr", - Doc: "check for invalid conversions of uintptr to unsafe.Pointer", + Doc: Doc, Requires: []*analysis.Analyzer{inspect.Analyzer}, Run: run, } diff --git a/go/analysis/passes/unsafeptr/unsafeptr_test.go b/go/analysis/passes/unsafeptr/unsafeptr_test.go index 9d82e99f..18e22c6c 100644 --- a/go/analysis/passes/unsafeptr/unsafeptr_test.go +++ b/go/analysis/passes/unsafeptr/unsafeptr_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package unsafeptr_test import ( @@ -7,7 +11,7 @@ import ( "golang.org/x/tools/go/analysis/passes/unsafeptr" ) -func TestFromFileSystem(t *testing.T) { +func Test(t *testing.T) { testdata := analysistest.TestData() analysistest.Run(t, testdata, unsafeptr.Analyzer, "a") } diff --git a/go/analysis/passes/unusedresult/unusedresult.go b/go/analysis/passes/unusedresult/unusedresult.go index 3d969a4d..76d4ab23 100644 --- a/go/analysis/passes/unusedresult/unusedresult.go +++ b/go/analysis/passes/unusedresult/unusedresult.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Package unusedresult defines an analyer that checks for unused +// Package unusedresult defines an analyzer that checks for unused // results of calls to certain pure functions. package unusedresult @@ -23,15 +23,17 @@ import ( // fact for each function that tail-calls one of the functions that we // check, and check those functions too. -var Analyzer = &analysis.Analyzer{ - Name: "unusedresult", - Doc: `check for unused results of calls to some functions +const Doc = `check for unused results of calls to some functions Some functions like fmt.Errorf return a result and have no side effects, so it is always a mistake to discard the result. This analyzer reports calls to certain functions in which the result of the call is ignored. -The set of functions may be controlled using flags.`, +The set of functions may be controlled using flags.` + +var Analyzer = &analysis.Analyzer{ + Name: "unusedresult", + Doc: Doc, Requires: []*analysis.Analyzer{inspect.Analyzer}, Run: run, } diff --git a/go/analysis/passes/unusedresult/unusedresult_test.go b/go/analysis/passes/unusedresult/unusedresult_test.go index 65f22f3e..90bf7ba4 100644 --- a/go/analysis/passes/unusedresult/unusedresult_test.go +++ b/go/analysis/passes/unusedresult/unusedresult_test.go @@ -1,3 +1,7 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package unusedresult_test import (