ABC metrics for Go source code.
ABCGo uses these rules to calculate ABC:
- Add one to the assignment count when:
- Occurrence of an assignment operator:
=,*=,/=,%=,+=,<<=,>>=,&=,^=. - Occurrence of an increment or a decrement operator:
++,--.
- Occurrence of an assignment operator:
- Add one to branch count when:
- Occurrence of a function call.
- Add one to condition count when:
- Occurrence of a conditional operator:
<,>,<=,>=,==,!=. - Occurrence of the following keywords:
else,case.
- Occurrence of a conditional operator:
Final score is calculated as follows:
$ go get -u github.com/droptheplot/abcgo
$ (cd $GOPATH/src/github.com/droptheplot/abcgo && go install)$ abcgo -path main.go
Source Func Score A B C
main.go:28 init 9 1 8 5
main.go:54 main 13 5 13 1$ abcgo -path ./
Source Func Score A B C
main.go:28 init 9 1 8 5
main.go:54 main 13 5 13 1
main_test.go:54 TestSomething 9 0 9 2$ abcgo -path main.go -format json
[
{
"path": "main.go",
"line": 54,
"name": "main",
"assignment": 5,
"branch": 13,
"condition": 1,
"score": 13
},
{
"path": "main.go",
"line": 54,
"name": "init",
"assignment": 1,
"branch": 8,
"condition": 5,
"score": 9
}
](source, line, function name, score)
$ abcgo -path main.go -format raw
main.go 28 init 9
main.go 54 main 13
main_test.go 54 TestSomething 9$ abcgo -path ./ -format summary
A B C
Project summary: 22 43 15-path [path]- Path to file or directory.-format [format]- Output format (table(default),raworjson).-sort- Sort functions by score.-no-test- Skip*_test.gofiles.