gocyclo

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2020 License: BSD-3-Clause Imports: 10 Imported by: 18

README

PkgGoDev Go Report Card

Gocyclo calculates cyclomatic complexities of functions in Go source code.

The cyclomatic complexity of a function is calculated according to the following rules:

 1 is the base complexity of a function
+1 for each 'if', 'for', 'case', 'default', '&&' or '||'

To install, run

$ go get github.com/fzipp/gocyclo/cmd/gocyclo

and put the resulting binary in one of your PATH directories if $GOPATH/bin isn't already in your PATH.

Usage:

$ gocyclo [<flag> ...] <Go file or directory> ...

Examples:

$ gocyclo .
$ gocyclo main.go
$ gocyclo -top 10 src/
$ gocyclo -over 25 docker
$ gocyclo -avg .
$ gocyclo -ignore "_test|Godeps" .

The output fields for each line are:

<complexity> <package> <function> <file:row:column>

Individual functions can be ignored with a gocyclo:ignore directive:

//gocyclo:ignore
func f() {
    // ...
}

//gocyclo:ignore
var g = func() {
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Complexity

func Complexity(fn ast.Node) int

Complexity calculates the cyclomatic complexity of a function.

Types

type Stat

type Stat struct {
	PkgName    string
	FuncName   string
	Complexity int
	Pos        token.Position
}

func (Stat) String

func (s Stat) String() string

type Stats

type Stats []Stat

func Analyze

func Analyze(paths []string, ignore *regexp.Regexp) Stats

func (Stats) AverageComplexity

func (s Stats) AverageComplexity() float64

func (Stats) SortAndFilter

func (s Stats) SortAndFilter(top, over int) Stats

func (Stats) TotalComplexity

func (s Stats) TotalComplexity() uint64

Directories

Path Synopsis
cmd
gocyclo command
Gocyclo calculates the cyclomatic complexities of functions and methods in Go source code.
Gocyclo calculates the cyclomatic complexities of functions and methods in Go source code.

Jump to

Keyboard shortcuts

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