mirror of
https://github.com/golang/go
synced 2024-11-18 19:44:46 -07:00
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>
This commit is contained in:
parent
63d31665e3
commit
a0ecdcbec4
@ -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]
|
||||
`
|
||||
|
||||
|
@ -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 (
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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 (
|
||||
|
@ -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,
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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 (
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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 (
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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 (
|
||||
|
@ -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 (
|
||||
|
@ -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 {
|
||||
|
@ -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 (
|
||||
|
@ -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.
|
||||
//
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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 (
|
||||
|
@ -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,
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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 (
|
||||
|
@ -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.
|
||||
//
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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 (
|
||||
|
@ -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,
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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 (
|
||||
|
@ -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,
|
||||
|
@ -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 (
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
|
@ -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 (
|
||||
|
Loading…
Reference in New Issue
Block a user