1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Package inspect defines an Analyzer that provides an AST inspector
6 // (golang.org/x/tools/go/ast/inspect.Inspect) for the syntax trees of a
7 // package. It is only a building block for other analyzers.
9 // Example of use in another analysis:
12 // "golang.org/x/tools/go/analysis"
13 // "golang.org/x/tools/go/analysis/passes/inspect"
14 // "golang.org/x/tools/go/ast/inspector"
17 // var Analyzer = &analysis.Analyzer{
19 // Requires: []*analysis.Analyzer{inspect.Analyzer},
22 // func run(pass *analysis.Pass) (interface{}, error) {
23 // inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
24 // inspect.Preorder(nil, func(n ast.Node) {
35 "golang.org/x/tools/go/analysis"
36 "golang.org/x/tools/go/ast/inspector"
39 var Analyzer = &analysis.Analyzer{
41 Doc: "optimize AST traversal for later passes",
43 RunDespiteErrors: true,
44 ResultType: reflect.TypeOf(new(inspector.Inspector)),
47 func run(pass *analysis.Pass) (interface{}, error) {
48 return inspector.New(pass.Files), nil