fzipp/gocyclo
소개
Go 소스 코드에 있는 함수의 순환 복잡도를 계산합니다.
기타 프로젝트측정된 스타 증가
- in 24h
- +1
- in 7 days
- +3
- in 15 days
- +4
- in 1 month
- +10
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originalgocyclo
Gocyclo calculates cyclomatic complexities of functions in Go source code.
Cyclomatic complexity is a code quality metric which can be used to identify code that needs refactoring. It measures the number of linearly independent paths through a function's 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', '&&' or '||'
A function with a higher cyclomatic complexity requires more test cases to cover all possible paths and is potentially harder to understand. The complexity can be reduced by applying common refactoring techniques that lead to smaller functions.
Installation
To install the gocyclo command, run
$ go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
and put the resulting binary in one of your PATH directories if
$GOPATH/bin isn't already in your PATH.
Usage
Calculate cyclomatic complexities of Go functions.
Usage:
gocyclo [flags] <Go file or directory> ...
Flags:
-over N show functions with complexity > N only and
return exit code 1 if the set is non-empty
-top N show the top N most complex functions only
-avg, -avg-short show the average complexity over all functions;
the short option prints the value without a label
-ignore REGEX exclude files matching the given regular expression
The output fields for each line are:
<complexity> <package> <function> <file:line:column>
Examples
$ gocyclo .
$ gocyclo main.go
$ gocyclo -top 10 src/
$ gocyclo -over 25 docker
$ gocyclo -avg .
$ gocyclo -top 20 -ignore "_test|Godeps|vendor/" .
$ gocyclo -over 3 -avg gocyclo/
Example output:
9 gocyclo (*complexityVisitor).Visit complexity.go:30:1
8 main main cmd/gocyclo/main.go:53:1
7 gocyclo (*fileAnalyzer).analyzeDecl analyze.go:96:1
4 gocyclo Analyze analyze.go:24:1
4 gocyclo parseDirectives directives.go:27:1
4 gocyclo (Stats).SortAndFilter stats.go:52:1
Average: 2.72
Note that the average is calculated over all analyzed functions, not just the printed ones.
Ignoring individual functions
Individual functions can be ignored with a gocyclo:ignore directive:
//gocyclo:ignore
func f1() {
// ...
}
//gocyclo:ignore
var f2 = func() {
// ...
}
License
This project is free and open source software licensed under the BSD 3-Clause License.
관련 프로젝트 살펴보기
불러오는 중…