gostyle
is a set of analyzers for coding styles.
gostyle
IS NOT Go Style.
"Go Style" in Google Style Guides is a great style and we will actively refer to it, but we cannot implement the same rules perfectly, and we may extend the rules.
gostyle
IS NOT STANDARD.
gostyle
IS to help you maintain YOUR Go project coding STYLE.
$ go vet -vettool=`which gostyle`
GitHub Actions for gostyle is here !!
# .github/workflows/ci.yml
on:
push:
jobs:
test:
runs-on: ubuntu-latest
steps:
[...]
-
uses: k1LoW/gostyle-action@v1
with:
config-file: .gostyle.yml
[...]
Although not perfect, it provides analyzers based on helpful styles.
"Effective Go" by The Go Authors is licensed under CC BY 4.0
Go Style in Google Style Guides
- Guide
- Decisions
- funcfmt ... based on https://google.github.io/styleguide/go/decisions#function-formatting
- getters ... based on https://google.github.io/styleguide/go/decisions#getters
- nilslices ... based on https://google.github.io/styleguide/go/decisions#nil-slices
- pkgnames ... based on https://google.github.io/styleguide/go/decisions#package-names
- recvnames ... based on https://google.github.io/styleguide/go/decisions#receiver-names
- recvtype ... based on https://google.github.io/styleguide/go/decisions#receiver-type
- repetition ... based on https://google.github.io/styleguide/go/decisions#repetition
- typealiases ... based on https://google.github.io/styleguide/go/decisions#type-aliases
- underscores ... based on https://google.github.io/styleguide/go/decisions#underscores
- useany ... based on https://google.github.io/styleguide/go/decisions#use-any
- useq ... based on https://google.github.io/styleguide/go/decisions#use-q
- varnames ... based on https://google.github.io/styleguide/go/decisions#variable-names
"Google Style Guides" by Google is licensed under CC BY 3.0
Go Code Review Comments in Go wiki
- contexts ... based on https://go.dev/wiki/CodeReviewComments#contexts
- dontpanic ... based on https://go.dev/wiki/CodeReviewComments#dont-panic
- errorstrings ... based on https://go.dev/wiki/CodeReviewComments#error-strings
- handlerrors ... based on https://go.dev/wiki/CodeReviewComments#handle-errors
Use -[analyser name].disable
flag.
$ go vet -vettool=`which gostyle` -mixedcaps.disable # Disable mixedcaps analyzer only
//lint:ignore
//nolint:all
//nostyle:all
//nostyle:[analyzer name]
(e.g.//nostyle:mixedcaps
)
gostyle
can be configured by -gostyle.config=$PWD/.gostyle.yml
like golangci-lint.
$ gostyle init
.gostyle.yml is generated
$ go vet -vettool=`which gostyle` -gostyle.config=$PWD/.gostyle.yml ./...
# All available settings of specific analyzers.
analyzers-settings:
# See the dedicated "analyzers-settings" documentation section.
option: value
analyzers:
disable:
# Disable specific analyzers.
- analyzer-name
analyzers-settings:
contexts:
include-generated: false # include generated codes (default: false)
exclude-test: true # exclude test files (default: false)
analyzers-settings:
dontpanic:
include-generated: false # include generated codes (default: false)
exclude-test: true # exclude test files (default: false)
analyzers-settings:
errorstrings:
include-generated: false # include generated codes (default: false)
exclude-test: true # exclude test files (default: false)
analyzers-settings:
funcfmt:
include-generated: false # include generated codes (default: false)
analyzers-settings:
getters:
include-generated: false # include generated codes (default: false)
exclude: # exclude words
- GetViaHTTP
( NOT handleerrors )
analyzers-settings:
handlerrors:
include-generated: false # include generated codes (default: false)
exclude-test: true # exclude test files (default: false)
analyzers-settings:
ifacenames:
include-generated: false # include generated codes (default: false)
all: true # all interface names with the -er suffix are required (default: false)
analyzers-settings:
mixedcaps:
include-generated: false # include generated codes (default: false)
exclude: # exclude words
- DBTX
- EXPECT
analyzers-settings:
nilslices:
include-generated: false # include generated codes (default: false)
analyzers-settings:
pkgnames:
include-generated: false # include generated codes (default: false)
analyzers-settings:
recvnames:
include-generated: false # include generated codes (default: false)
max: 3 # max length of receiver name (default: 2)
analyzers-settings:
recvnames:
include-generated: false # include generated codes (default: false)
analyzers-settings:
repetition:
include-generated: false # include generated codes (default: false)
exclude: # exclude words
- limitStr
analyzers-settings:
typealiases:
include-generated: false # include generated codes (default: false)
exclude: # exclude words
- TmpAliasHeader
analyzers-settings:
underscores:
include-generated: false # include generated codes (default: false)
exclude: # exclude words
- DBTX
- EXPECT
analyzers-settings:
useany:
include-generated: false # include generated codes (default: false)
analyzers-settings:
useq:
include-generated: false # include generated codes (default: false)
analyzers-settings:
varnames:
include-generated: false # include generated codes (default: false)
small-scope-max: 5 # max lines for small scope (default: 7)
small-varname-max: 3 # max length of variable name for small scope (default: -1)
medium-scope-max: 10 # max lines for medium scope (default: 15)
medium-varname-max: 5 # max length of variable name for medium scope (default: -1)
large-scope-max: 15 # max lines for large scope (default: 25)
large-varname-max: 7 # max length of variable name for large scope (default: -1)
very-large-varname-max: 9 # max length of variable name for very large scope (default: -1)
exclude: # exclude words
- hostname
go install:
$ go install github.com/k1LoW/gostyle@latest
deb:
$ export GOSTYLE_VERSION=X.X.X
$ curl -o gostyle.deb -L https://github.com/k1LoW/gostyle/releases/download/v$GOSTYLE_VERSION/gostyle_$GOSTYLE_VERSION-1_amd64.deb
$ dpkg -i gostyle.deb
RPM:
$ export GOSTYLE_VERSION=X.X.X
$ yum install https://github.com/k1LoW/gostyle/releases/download/v$GOSTYLE_VERSION/gostyle_$GOSTYLE_VERSION-1_amd64.rpm
apk:
$ export GOSTYLE_VERSION=X.X.X
$ curl -o gostyle.apk -L https://github.com/k1LoW/gostyle/releases/download/v$GOSTYLE_VERSION/gostyle_$GOSTYLE_VERSION-1_amd64.apk
$ apk add gostyle.apk
homebrew tap:
$ brew install k1LoW/tap/gostyle
aqua:
$ aqua g -i k1LoW/gostyle
manually:
Download binary from releases page