Skip to content

droptheplot/abcgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ABCGo

Go Report Card Build Status GoDoc

ABC metrics for Go source code.

Definition

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: ++, --.
  • 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.

Final score is calculated as follows:

Read more about ABC metrics.

Getting Started

Installation

$ go get -u github.com/droptheplot/abcgo
$ (cd $GOPATH/src/github.com/droptheplot/abcgo && go install)

Usage

Single file

$ 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

Directory

$ 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

JSON

$ 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
  }
]

Raw

(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

Summary

$ abcgo -path ./ -format summary
                   A    B    C
Project summary:   22   43   15

Options

  • -path [path] - Path to file or directory.
  • -format [format] - Output format (table (default), raw or json).
  • -sort - Sort functions by score.
  • -no-test - Skip *_test.go files.

Plugins