diff options
author | Alan Donovan <adonovan@google.com> | 2018-10-15 18:10:24 -0400 |
---|---|---|
committer | Alan Donovan <adonovan@google.com> | 2018-10-16 20:28:15 +0000 |
commit | a0ecdcbec46f2cd944b1ad9e1ffb51b94f227b6b (patch) | |
tree | 3aba7cfc4c7bb84464b75cfc811c49ea5ee4b474 /go/analysis/passes | |
parent | 63d31665e311d0da81db6a27060589b038fad816 (diff) | |
download | golang-x-tools-a0ecdcbec46f2cd944b1ad9e1ffb51b94f227b6b.tar.gz |
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 <matloob@golang.org>
Diffstat (limited to 'go/analysis/passes')
42 files changed, 232 insertions, 71 deletions
diff --git a/go/analysis/passes/asmdecl/asmdecl.go b/go/analysis/passes/asmdecl/asmdecl.go index 5a076ee21..1e6e32a9a 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 c703c4bc0..e978fbbaa 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 271b45e9c..4dff2908c 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 bde77095f..f43d6dfab 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 1c3057092..45243d6f8 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 d34bb7486..f5f60a3fb 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 40ca730db..0e6f2695f 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 ed9595984..57324707a 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 7187afaae..5a441e609 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 98aec64af..e95cc1a25 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 daf65b976..7eb24a4a9 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 db228187d..aebd43276 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 403cbe938..b7cfe8a95 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 384898a6c..c55015c22 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 c199c2ea3..067aed57d 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 acbdb52aa..d33d0a2e2 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 658da9ff3..0aae7cb0a 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 31f3f0b51..ebc6e86a1 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 f1b9adc13..788bc1e5f 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 d9c0c2c0c..bd0654998 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 e71630bb9..da0714069 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 8253ab722..0916f5e6f 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 d022b34e7..fcf9f553a 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 759634b44..5fe817b30 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 7a2344ff6..9c2d4df20 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 8218e7134..6eac063d5 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 d1ba6c2a9..eca0f2562 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 1e408833d..c0e1f4035 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 889f5f383..56b150b2b 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 56741d8e7..8b41b609b 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 840a1b9db..eead289e4 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 33a0f9a83..fe4fe53c2 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 48b64771c..78133fe6f 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 7ce6d0b13..1755bea8f 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 fca9854c7..35b0a3e7c 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 6d42a1a9e..172ae8ef1 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 98cad56a6..19bc9c2db 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 e38feaffb..13f56897b 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 aa5518eca..116d622b3 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 9d82e99ff..18e22c6c1 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 3d969a4d5..76d4ab238 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 65f22f3e1..90bf7ba4f 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 ( |