used

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

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

Go to latest
Published: Mar 24, 2017 License: MIT Imports: 10 Imported by: 0

README

used - compute the most-used identifiers in a Go program

The used tool analyzes a Go program to compute the most-used identifiers.

It can also filter the output of gometalinter to show problems only on the most-used identifiers. This lets you use data to prioritize what to fix/improve in a Go program.

Install

go get github.com/sqs/used/cmd/used

Usage

Show the most-used identifiers in a Go program
$ cat > /tmp/file.go <<EOF
package foo

func f1() { f2() } // note that f1 has no callers

func f2() {}

func init() {
	f2()
}
EOF

$ used -lint-output /tmp/file.go
/tmp.file.go:3:6: func f1 is used 0 times
/tmp.file.go:5:6: func f2 is used 2 times
Filter gometalinter output to show problems only on the most-used identifiers
$ go get gopkg.in/alecthomas/gometalinter.v1
$ gometalinter.v1 --install
$ go get github.com/gorilla/mux
$ cd $(go list -f '{{.Dir}}' github.com/gorilla/mux)
$ gometalinter.v1 --disable=gocyclo --disable=vetshadow --disable=goconst --json ./... | used -top 5 ./...
  {"linter":"golint","severity":"warning","path":"route.go","line":44,"col":1,"message":"exported method Route.SkipClean should have comment or be unexported"}
  {"linter":"errcheck","severity":"warning","path":"mux_test.go","line":1646,"col":11,"message":"error return value not checked (req.Write(\u0026buff))"}
  {"linter":"gosimple","severity":"warning","path":"mux_test.go","line":948,"col":3,"message":"should use 'return \u003cexpr\u003e' instead of 'if \u003cexpr\u003e { return \u003cbool\u003e }; return \u003cbool\u003e' (S1008)"}
  {"linter":"gosimple","severity":"warning","path":"old_test.go","line":596,"col":5,"message":"should omit comparison to bool constant, can be simplified to route.strictSlash (S1002)"}
  {"linter":"gosimple","severity":"warning","path":"old_test.go","line":602,"col":5,"message":"should omit comparison to bool constant, can be simplified to !route.strictSlash (S1002)"}

You can use any existing gometalinter flags, except that:

  • You must use gometalinter --json.
  • The file/package arguments to used must be a superset of what you pass to gometalinter (typically they are the same, and ./... is most common).

Acknowledgments

The used tool is derived from Dominik Honnef's unused tool.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckMode

type CheckMode int
const (
	CheckConstants CheckMode = 1 << iota
	CheckFields
	CheckFunctions
	CheckTypes
	CheckVariables

	CheckAll = CheckConstants | CheckFields | CheckFunctions | CheckTypes | CheckVariables
)

type Checker

type Checker struct {
	Mode               CheckMode
	WholeProgram       bool
	ConsiderReflection bool
	Debug              io.Writer
	// contains filtered or unexported fields
}

func NewChecker

func NewChecker(mode CheckMode) *Checker

func (*Checker) Check

func (c *Checker) Check(lprog *loader.Program) []Used

type Error

type Error struct {
	Errors map[string][]error
}

func (Error) Error

func (e Error) Error() string

type LintChecker

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

func NewLintChecker

func NewLintChecker(c *Checker) *LintChecker

func NewLintData

func NewLintData(used []Used) *LintChecker

func (*LintChecker) Funcs

func (l *LintChecker) Funcs() map[string]lint.Func

func (*LintChecker) Init

func (l *LintChecker) Init(*lint.Program)

func (*LintChecker) Lint

func (l *LintChecker) Lint(j *lint.Job)

func (*LintChecker) LintProblems

func (l *LintChecker) LintProblems(prog *loader.Program) (problems []Problem)

type Problem

type Problem struct {
	Pos  lint.Positioner
	Text string
}

type Used

type Used struct {
	Obj         types.Object
	Position    token.Position
	EndPosition token.Position
	N           uint // number of usages
}

Directories

Path Synopsis
cmd
used command
used reports the most-used identifiers in your code.
used reports the most-used identifiers in your code.

Jump to

Keyboard shortcuts

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