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.
$ gostyle run ./...$ 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 like golangci-lint.
$ gostyle init
.gostyle.yml is generated
# As a Standalone CLI
$ gostyle run --config=.gostyle.yml ./...
# As a vet tool
$ go vet -vettool=`which gostyle` -gostyle.config=$PWD/.gostyle.yml ./...Note
If no configuration file is specified, gostyle will automatically search for .gostyle.yml or .gostyle.yaml in the Git root directory.
# .gostyle.yml
analyzers:
disable:
# Disable specific analyzers.
- analyzer-name
# All available settings of specific analyzers.
analyzers-settings:
# See the dedicated "analyzers-settings" documentation section.
option: valueanalyzers-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
- EXPECTanalyzers-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
- limitStranalyzers-settings:
typealiases:
include-generated: false # include generated codes (default: false)
exclude: # exclude words
- TmpAliasHeaderanalyzers-settings:
underscores:
include-generated: false # include generated codes (default: false)
exclude: # exclude words
- DBTX
- EXPECTanalyzers-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
- hostnamego install:
$ go install github.com/k1LoW/gostyle@latestdeb:
$ 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.debRPM:
$ export GOSTYLE_VERSION=X.X.X
$ yum install https://github.com/k1LoW/gostyle/releases/download/v$GOSTYLE_VERSION/gostyle_$GOSTYLE_VERSION-1_amd64.rpmapk:
$ 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.apkhomebrew tap:
$ brew install k1LoW/tap/gostyleaqua:
$ aqua g -i k1LoW/gostylemanually:
Download binary from releases page