The Wayback Machine - https://web.archive.org/web/20230307190720/https://github.com/droptheplot/abcgo
Skip to content

droptheplot/abcgo

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
vim
 
 
 
 
 
 
 
 
 
 
 
 

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

About

ABC metrics for Go source code.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published