prodinspect

package module
v0.0.0-...-b5112ca Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2019 License: MIT Imports: 8 Imported by: 1

README

prodinspect

inspect but for production code only.

How to use

First, install the package via go get.

$ go get github.com/ichiban/prodinspect

Then, require prodinspect.Analyzer and use *prodinspect.Inspector in your analyzer.

package cyclomatic

import (
	"fmt"
	"go/ast"
	"go/token"
	"go/types"
	"os"

	"golang.org/x/tools/go/analysis"

	"github.com/ichiban/prodinspect"
)

var Analyzer = &analysis.Analyzer{
	Name:      "cyclomatic",
	Doc:       `check cyclomatic complexity of functions.`,
	Requires:  []*analysis.Analyzer{prodinspect.Analyzer},
	Run:       run,
}

func run(pass *analysis.Pass) (interface{}, error) {
	inspect := pass.ResultOf[prodinspect.Analyzer].(*prodinspect.Inspector)

	// ...

	return nil, nil
}

Definition of production code

Go files except:

  • test files (files with _test.go suffix)
  • generated files (files with // Code generated * DO NOT EDIT. comment)

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name:             "prodinspect",
	Doc:              `AST traversal that ignores test and/or generated files`,
	Requires:         []*analysis.Analyzer{inspect.Analyzer},
	Run:              run,
	RunDespiteErrors: true,
	ResultType:       reflect.TypeOf(new(Inspector)),
}

Functions

This section is empty.

Types

type Filer

type Filer interface {
	File(p token.Pos) (f *token.File)
}

type Inspector

type Inspector struct {
	// contains filtered or unexported fields
}

func New

func New(base WithStacker, fset Filer) *Inspector

func (*Inspector) Nodes

func (i *Inspector) Nodes(types []ast.Node, f func(n ast.Node, push bool) (prune bool))

func (*Inspector) Preorder

func (i *Inspector) Preorder(types []ast.Node, f func(n ast.Node))

func (*Inspector) WithStack

func (i *Inspector) WithStack(types []ast.Node, f func(n ast.Node, push bool, stack []ast.Node) (prune bool))

type WithStacker

type WithStacker interface {
	WithStack(types []ast.Node, f func(n ast.Node, push bool, stack []ast.Node) (prune bool))
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL