checkstyle

package module
v0.0.0-...-e47d31c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2018 License: MIT Imports: 8 Imported by: 2

README

go-checkstyle

Build Status

checkstyle is a style check tool like java checkstyle. This tool inspired by java checkstyle, golint. The style refered to some points in Go Code Review Comments.

Install

go get github.com/qiniu/checkstyle/gocheckstyle

Run

gocheckstyle -config=.go_style dir1 dir2

Config

config is json file like the following:

{
    "file_line": 500,
    "func_line": 50,
    "params_num":4,
    "results_num":3,
    "formated": true,
    "pkg_name": true,
    "camel_name":true,
    "ignore":[
        "a/*",
        "b/*/c/*.go"
    ],
    "fatal":[
        "formated"
    ]
}

Add to makefile

check_go_style:
	bash -c "mkdir -p checkstyle; cd checkstyle && export GOPATH=`pwd` && go get github.com/qiniu/checkstyle/gocheckstyle"
	checkstyle/bin/gocheckstyle -config=.go_style dir1 dir2

Integrate with jenkins checkstyle plugin

excute in shell

    mkdir -p checkstyle; cd checkstyle && export GOPATH=`pwd` && go get github.com/qiniu/checkstyle/gocheckstyle"
    checkstyle/bin/gocheckstyle -reporter=xml -config=.go_style dir1 dir2 2>gostyle.xml

then add postbuild checkstyle file gostyle.xml

Run checkstyle with one or more filenames or directories. The output of this tool is a list of suggestions. If you need to force obey the rule, place it in fatal.

Checkstyle's difference with other tools

Checkstyle differs from gofmt. Gofmt reformats Go source code, whereas checkstyle prints out coding style suggestion.

Checkstyle differs from golint. Checkstyle check file line/function line/param number, could be configed by user.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checker

type Checker interface {
	Check(fileName string, src []byte) ([]Problem, error)
	IsFatal(p *Problem) bool
}

func New

func New(config []byte) (Checker, error)

type Problem

type Problem struct {
	Position    *token.Position
	Description string
	// SourceLine  string
	Type ProblemType
}

type ProblemType

type ProblemType string
const (
	FileLine     ProblemType = "file_line"
	FunctionLine ProblemType = "func_line"
	ParamsNum    ProblemType = "params_num"
	ResultsNum   ProblemType = "results_num"
	Formated     ProblemType = "formated"
	PackageName  ProblemType = "pkg_name"
	CamelName    ProblemType = "camel_name"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL