A Golang tool that does static analysis, unit testing, code review and generate code quality report.

Overview

goreporter

goreporter Version Status

Current Release Build Status GoDoc License

A Golang tool that does static analysis, unit testing, code review and generate code quality report. This is a tool that concurrently runs a whole bunch of those linters and normalizes their output to a report:

Supported linters

  • gofmt - Checks if the code is properly formatted and could not be further simplified.
  • govet - Reports variables that may have been unintentionally shadowed.
  • golint - Golint is a linter for Go source code.
  • unittest - Golang unit test status.
  • deadcode - Finds unused code.
  • gocyclo - Computes the cyclomatic complexity of functions.
  • varcheck - Find unused global variables and constants.
  • structcheck - Find unused struct fields.
  • aligncheck - Warn about un-optimally aligned structures.
  • errcheck - Check that error return values are used.
  • copycode(dupl) - Reports potentially duplicated code.
  • gosimple - Report simplifications in code.
  • staticcheck - Statically detect bugs, both obvious and subtle ones.
  • godepgraph - Godepgraph is a program for generating a dependency graph of Go packages.
  • misspell - Correct commonly misspelled English words... quickly.
  • countcode - Count lines and files of project.
  • interfacer - Suggest narrower interfaces that can be used.
  • depth - Count the maxdepth of go functions.
  • flen - Flen provides stats on functions/methods lengths in a Golang package.

Template

  • html template file which can be loaded via -t <file>.

Todo List

  • This version will re-design the template.
  • Add interfacer and safesql and gofmt(-s),govet linter.

Installing

Requirements

Quickstart

Install goreporter (see above).

go get -u github.com/360EntSecGroup-Skylar/goreporter

Run it:

NOTE

You have to confirm that your project is operational. In particular, the problem with vendor, when the package is not found in the default path, goreporter will look again from the possible vendor path.

goreporter -p [projectRelativePath] -r [reportPath] -e [exceptPackagesName] -f [json/html/text]  {-t templatePathIfHtml}
  • -version Version of GoReporter.
  • -p Must be a valid Golang project path.
  • -r Save the path to the report.
  • -e Exceptional packages (multiple separated by commas, for example: "linters/aligncheck,linters/cyclo" ).
  • -f report format json, html OR text.
  • -t Template path,if not specified, the default template will be used.

By default, the default template is used to generate reports in html format.

Example

goreporter-display

you can see result detail:online-example-report

Credits

Logo is designed by Ri Xu

Comments
  • The template path is not specified

    The template path is not specified

    Using HEAD...

    goreporter -p ./myproject gives [Apollo]2017/04/11 14:18:39 The template path is not specified

    The README.md indicates specifying the template file is optional. I don't have a template file and would prefer it just supply me with a default template file for now. Thanks.

    help wanted 
    opened by MichaelHipp 12
  • E0719 17:34:33.309647   97171 depend.go:81] failed to import

    E0719 17:34:33.309647 97171 depend.go:81] failed to import

    E0719 17:34:33.309647 97171 depend.go:81] failed to import github.com/yashpal1995/mycode: cannot find package "vendor/github.com/yashpal1995/mycode/" in any of: $GOROOT $GOPATH

    $GOPATH/bin/goreporter -p github.com/yashpal1995/mycode -r ~/goreporter

    why it's searching in vendor directory of $GOPATH?

    help wanted question 
    opened by iyashu 10
  • function deepness

    function deepness

    Hello, I've made a change in the gocyclo github.com/arthurgustin/gocyclo in order to get the max-depth of each function. The problem is that:

    switch a {
        case 1:
        case 2:
        case 3:
        ...
        case N:
    }
    

    which is ok to me, has a high cyclomatic complexity and is equivalent to

    if true {
        if true{
            if true {
                ...
                    if true {
                    }
            }
        }
    }
    

    which is certainly not ok.

    So I added an option in the CLI to do that. Is there any way to integrate this change ? The user may choose what he wants, depending on the use case ? I could work on it

    help wanted 
    opened by arthurgustin 8
  • 虚拟机下2G内存运行遇到的问题

    虚拟机下2G内存运行遇到的问题

    之前一个request十分抱歉...

    cgo failed: [go tool cgo -objdir /tmp/net_C182270452 -- -I /tmp/net_C182270452 cgo_linux.go cgo_resnew.go cgo_socknew.go cgo_unix.go]: fork/exec /usr/local/go/bin/go: cannot allocate memory
    /usr/local/go/src/net/lookup_unix.go:54:24: undeclared name: cgoLookupHost
    /usr/local/go/src/net/lookup_unix.go:69:24: undeclared name: cgoLookupIP
    /usr/local/go/src/net/lookup_unix.go:81:23: undeclared name: cgoLookupPort
    /usr/local/go/src/net/lookup_unix.go:97:24: undeclared name: cgoLookupCNAME
    /usr/local/go/src/net/lookup_unix.go:164:23: undeclared name: cgoLookupPTR
    

    这个是在虚拟机上运行时遇到的,原因就是虚拟机内存过小导致的。所以做了这个修改。

    再次抱歉

    bug help wanted 
    opened by kl7sn 7
  • Slice bounds out of range when using ./

    Slice bounds out of range when using ./

    If I use ./, like this:

    goreporter -p ./ -d ./goreporter -r html -t ../../github.com/wgliang/goreporter/templates/template.html
    
    panic: runtime error: slice bounds out of range
    
    goroutine 1 [running]:
    main.DirList.func1(0xc4202261f8, 0x7, 0xccff80, 0xc42022b2b0, 0x0, 0x0, 0x0, 0x0)
            /home/nkovacs/progs/go/src/github.com/wgliang/goreporter/utils.go:24 +0x219
    path/filepath.walk(0xc4202261f8, 0x7, 0xccff80, 0xc42022b2b0, 0xc420385b00, 0x0, 0x0)
            /usr/local/go/src/path/filepath/path.go:351 +0x81
    path/filepath.walk(0x7ffc150c417f, 0x2, 0xccff80, 0xc420380270, 0xc420385b00, 0x0, 0x30)
            /usr/local/go/src/path/filepath/path.go:376 +0x414
    path/filepath.Walk(0x7ffc150c417f, 0x2, 0xc420385b00, 0xc4203801a0, 0x0)
            /usr/local/go/src/path/filepath/path.go:398 +0x14c
    main.DirList(0x7ffc150c417f, 0x2, 0x97057b, 0x3, 0x0, 0x0, 0xc4200fab70, 0x0, 0x0)
            /home/nkovacs/progs/go/src/github.com/wgliang/goreporter/utils.go:32 +0x16a
    main.(*Reporter).Engine(0xc4200b6240, 0x7ffc150c417f, 0x2, 0x0, 0x0)
            /home/nkovacs/progs/go/src/github.com/wgliang/goreporter/engine.go:130 +0x300
    main.main()
            /home/nkovacs/progs/go/src/github.com/wgliang/goreporter/main.go:73 +0x2e8
    

    If I cd into the goreporter directory, and use ../, it works.

    bug 
    opened by nkovacs 6
  • stuck while generate report

    stuck while generate report

    In my repo dir:

    >> goreporter -r . -p . -f html
    2018/11/06 17:59:04 The template path is not specified,and will use the default template
    2018/11/06 17:59:04 There are no packages that are excepted, review all items of the package
    2018/11/06 17:59:05 Linter:CountCode over,time consuming 1.567595063s
    2018/11/06 17:59:05 Linter:Cyclo over,time consuming 1.64384756s
    2018/11/06 17:59:05 Linter:Deadcode over,time consuming 1.644238291s
      GOREPORTER  10/100
    

    stuck here forever.

    for my env:

    GOARCH="amd64"
    GOBIN=""
    GOCACHE="/Users/XXX/Library/Caches/go-build"
    GOEXE=""
    GOFLAGS=""
    GOHOSTARCH="amd64"
    GOHOSTOS="darwin"
    GOOS="darwin"
    GOPATH="/Users/XXX/go"
    GOPROXY=""
    GORACE=""
    GOROOT="/usr/local/Cellar/go/1.11/libexec"
    GOTMPDIR=""
    GOTOOLDIR="/usr/local/Cellar/go/1.11/libexec/pkg/tool/darwin_amd64"
    GCCGO="gccgo"
    CC="clang"
    CXX="clang++"
    CGO_ENABLED="1"
    GOMOD=""
    CGO_CFLAGS="-g -O2"
    CGO_CPPFLAGS=""
    CGO_CXXFLAGS="-g -O2"
    CGO_FFLAGS="-g -O2"
    CGO_LDFLAGS="-g -O2"
    PKG_CONFIG="pkg-config"
    GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/90/hr1_x8993q9fyw7gf7g_85v80000gp/T/go-build392347019=/tmp/go-build -gno-record-gcc-switches -fno-common"
    
    
    opened by FelixSeptem 5
  • dependency error

    dependency error

    Hi I've test github.com/golang to see what would happen, and maybe find dependency error

    cd $GOPATH/src
    
    goreporter -p ./github.com/golang -f html
    2017/08/11 11:01:03 The template path is not specified,and will use the default template
    2017/08/11 11:01:03 The report path is not specified, and the current path is used by default
    2017/08/11 11:01:03 There are no packages that are excepted, review all items of the package
    2017/08/11 11:01:04 Linter:DeadCode over,time consuming 0.481549428s
    2017/08/11 11:01:04 Linter:ImportPackages over,time consuming 0.551166767s
    E0811 11:01:05.446199   23440 depend.go:81] failed to import ./github.com/golang: cannot find package "vendor/./github.com/golang" in any of:
        /usr/local/Cellar/go/1.8.3/libexec/src/vendor/github.com/golang (from $GOROOT)
        /Users/nickelchen/work/workspaces/go/src/vendor/github.com/golang (from $GOPATH)
    2017/08/11 11:01:05 Linter:DependGraph over,time consuming 1.801601824s
    ...
    ...
    

    Then tested several projects and they all report

    cannot find package "vendor/./github.com/..."
    
    bug 
    opened by sekirocc 5
  • refactor: (WIP) dependancy injection, stragy pattern

    refactor: (WIP) dependancy injection, stragy pattern

    Hello, I've worked on the code base. Summary:

    • Dependancy injection on the main function
    • Strategy pattern for each linter (only compute, not render)
    • Fixed some test

    I'm quite confident with the way linters compute are handled. I didn't touch the html generation part and maybe there is something to do. I want to avoid this:

    // convert all linter's data.
    	htmlData.converterUnitTest(*r)
    	htmlData.converterCopy(*r)
    	htmlData.converterCyclo(*r)
    	htmlData.converterDepth(*r)
    	htmlData.converterInterfacer(*r)
    	htmlData.converterSimple(*r)
    	htmlData.converterSpell(*r)
    	htmlData.converterCount(*r)
    	htmlData.converterDead(*r)
    	htmlData.converterDependGraph(*r)
    

    I have to think about the best way to fill the html template

    Also I deleted the package tool, because in my opinion it's the reporter responsability to generate the different outputs.

    What do you think ?

    enhancement help wanted 
    opened by arthurgustin 5
  • Unable to download godepth

    Unable to download godepth

    Getting 403 error

    Initialized empty Git repository in /root/go/src/github.com/360EntSecGroup-Skylar/godepth/.git/ error: The requested URL returned error: 403 Forbidden while accessing https://github.com/360EntSecGroup-Skylar/godepth/info/refs

    opened by aksh7860 4
  • Invalid javascript in generated html

    Invalid javascript in generated html

    The generated HTML document (with default template) is generated with an invalid javascript.

    Uncaught SyntaxError: Unexpected token N in JSON at position 41
        at JSON.parse (<anonymous>)
        at Object.1../subpage/codeCount.js (dialog-platform-2017-11-09-17-55-01.html:879)
        at s (dialog-platform-2017-11-09-17-55-01.html:877)
        at e (dialog-platform-2017-11-09-17-55-01.html:877)
        at dialog-platform-2017-11-09-17-55-01.html:877
    
    bug 
    opened by ostronom 4
  • copycode with Path: null

    copycode with Path: null

    The generated reports do not have the path filled. (Windows)

    var resData = {
        score:  77 ,
        avgcover: "84.9",
        date:"2017-07-24 12:22:26",
        codelines:  17919 ,
        gosimple_issue:  0 ,
        deadcode_count:  0 ,
        cycol_count:  0 ,
        project: "",
        gotest:{
            res: "[]",
            summary: "84.9",
            noTest: "[]"
        },
        gosimple: "[]",
        gospell:"[]",
        gosimpleLevel: 2,
        deadcode: "[]",
        copycode: "[{\"Files\":\"2\",\"Path\":null},{\"Files\":\"2\",\"Path\":null},{\"Files\":\"2\",\"Path\":null},{\"Files\":\"3\",\"Path\":null},{\"Files\":\"3\",\"Path\":null},{\"Files\":\"2\",\"Path\":null},{\"Files\":\"3\",\"Path\":null},{\"Files\":\"7\",\"Path\":null},{\"Files\":\"2\",\"Path\":null},{\"Files\":\"2\",\"Path\":null},{\"Files\":\"2\",\"Path\":null},{\"Files\":\"2\",\"Path\":null},{\"Files\":\"2\",\"Path\":null},{\"Files\":\"4\",\"Path\":null},{\"Files\":\"3\",\"Path\":null},{\"Files\":\"6\",\"Path\":null}]",
        gocyclo :"[{\"Pkg\":\"\",\"Size\":60,\"Info\":null}]"
    }
    

    HTML do so not render... and shows only "Please wait..." is it only works on linux?

    bug 
    opened by Dexus 4
  • go get failed

    go get failed

    image

    GO111MODULE="on" GOARCH="amd64" GOBIN="" GOCACHE="/home/yhk/.cache/go-build" GOENV="/home/yhk/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/yhk/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/yhk/go" GOPRIVATE="" GOPROXY="https://goproxy.io,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.16.2" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/yhk/goWorkspace/photoprism/go.mod" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1699168475=/tmp/go-build -gno-record-gcc-switches"

    opened by yuanhuikai 1
  • How to run under gomod

    How to run under gomod

    the project layout is blow:

    -myProject
      -libA
      -cmd
        -server
          -main.go
        -client
          -main.go
      -libB
      -go.mod
      -go.sum
    

    When I run cd myProject && goreporter -p ., it warns me that:

    package myProject/cmd/server is not in GOROOT
    package myProject/cmd/client is not in GOROOT
    package myProject/libA is not in GOROOT
    package myProject/libB is not in GOROOT
    

    How could I fix this?

    opened by caibirdme 1
  • Constants - Uppercase reported as error

    Constants - Uppercase reported as error

    I think that the reporting on constants may be incorrect. GoReporter states that uppercase is incorrect, however that is not the case for constants. viz:

    GoReporter: "don't use ALL_CAPS in Go names; use CamelCase"

    https://www.golangprograms.com/go-language/constants.html

    Naming Conventions for Golang Constants By convention, constant names are usually written in uppercase letters. This is for their easy identification and differentiation from variables in the source code.

    opened by brianoh 0
Releases(version3.0.2)
Owner
QI-ANXIN GROUP
QI-ANXIN Open Source
QI-ANXIN GROUP
🐶 Automated code review tool integrated with any code analysis tools regardless of programming language

reviewdog - A code review dog who keeps your codebase healthy. reviewdog provides a way to post review comments to code hosting service, such as GitHu

reviewdog 5.6k Sep 26, 2022
🐶 Automated code review tool integrated with any code analysis tools regardless of programming language

reviewdog - A code review dog who keeps your codebase healthy. reviewdog provides a way to post review comments to code hosting service, such as GitHu

reviewdog 5.5k Sep 21, 2022
Act as part of the business code and will report aqua scan report after application installed

starboard-report This repo aim to enrich the functionality of starboard. Starboard integrates security tools into the Kubernetes environment, so that

null 17 Nov 25, 2021
Analyzer: zapvet is static analysis tool for zap

zapvet zapvet is static analysis tool for zap. fieldtype: fieldtype finds confliction type of field Install You can get zapvet by go install command (

GoStaticAnalysis 5 Sep 18, 2022
Retnilnil is a static analysis tool to detect `return nil, nil`

retnilnil retnilnil is a static analysis tool for Golang that detects return nil, nil in functions with (*T, error) as the return type. func f() (*T,

neglect-yp 3 Jun 9, 2022
GoKart - Go Security Static Analysis

GoKart is a static analysis tool for Go that finds vulnerabilities using the SSA (single static assignment) form of Go source code.

Praetorian 2k Sep 16, 2022
a simple golang SSA viewer tool use for code analysis or make a linter

ssaviewer A simple golang SSA viewer tool use for code analysis or make a linter ssa.html generate code modify from src/cmd/compile/internal/ssa/html.

null 7 May 17, 2022
A report card for your Go application

Go Report Card A web application that generates a report on the quality of an open source go project. It uses several measures, including gofmt, go ve

GoJP 1.7k Sep 21, 2022
Tool: ptrls prints result of pointer analysis

ptrls Install $ go install github.com/gostaticanalysis/ptrls/cmd/[email protected] Usage $ cd testdata/a $ cat a.go package main func main() { f(map[str

GoStaticAnalysis 1 Feb 1, 2022
A static code analyzer for annotated TODO comments

todocheck todocheck is a static code analyzer for annotated TODO comments. It let's you create actionable TODOs by annotating them with issues from an

Preslav Mihaylov 390 Sep 19, 2022
octocov is a tool for collecting code metrics (code coverage, code to test ratio and test execution time).

octocov is a tool for collecting code metrics (code coverage, code to test ratio and test execution time).

Ken’ichiro Oyama 130 Sep 22, 2022
[mirror] Performance measurement, storage, and analysis.

Go performance measurement, storage, and analysis tools This subrepository holds the source for various packages and tools related to performance meas

Go 319 Sep 23, 2022
structslop is a static analyzer for Go that recommends struct field rearrangements to provide for maximum space/allocation efficiency.

structslop Package structslop defines an Analyzer that checks struct can be re-arranged fields to get optimal struct size.

orijtech 666 Sep 23, 2022
Go-perfguard - A static analyzer with emphasis on performance

perfguard This tool is a work in progress. It's not production-ready yet. perfgu

Iskander (Alex) Sharipov 57 Sep 17, 2022
Sloc, Cloc and Code: scc is a very fast accurate code counter with complexity calculations and COCOMO estimates written in pure Go

Sloc Cloc and Code (scc) A tool similar to cloc, sloccount and tokei. For counting physical the lines of code, blank lines, comment lines, and physica

Ben Boyter 3.8k Sep 30, 2022
depth is tool to retrieve and visualize Go source code dependency trees.

depth is tool to retrieve and visualize Go source code dependency trees. Install Download the appropriate binary for your platform from the Rele

Kyle Banks 784 Sep 25, 2022
Tool to populate your code with traceable and secure error codes

Essential part of any project, especially customer facing is proper and secure error handling. When error happens and customer reports it, it would be nice to know the context of the error and where it exactly occured.

vs 52 Apr 1, 2022
Refactoring and code transformation tool for Go.

gopatch is a tool to match and transform Go code. It is meant to aid in refactoring and restyling.

Uber Go 498 Sep 29, 2022