gostyle

command module
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: MIT Imports: 11 Imported by: 0

README

gostyle

THIS IS A WORK IN PROGRESS AND PROOF OF CONCEPT AND STUDY WORK

gostyle is a set of analyzers for coding styles.

Disclaimer

gostyle IS NOT Go Style.

"Go Style" is a great style and we will actively refer to it, but we cannot implement the same rules exactly, and we may extend the rules.

Usage

$ go vet -vettool=`which gostyle`

Analyzers

Although not perfect, it provides analyzers based on helpful styles.

Effective Go
Go Style

Disabling and Ignoring

Disable analyzer

Use -[analyser name].disable flag.

$ go vet -vettool=`which gostyle` -mixedcaps.disable # Disable mixedcaps analyzer only
Ignore directive
  • //lint:ignore
  • //nolint:all
  • //nostyle:all
  • //nostyle:[analyzer name] (e.g. //nostyle:mixedcaps)

Configuration

gostyle can be configured by -gostyle.config=$PWD/.gostyle.yml like golangci-lint.

$ 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:
getters
analyzers-settings:
  getters:
    include-generated: false # include generated codes (default: false)
    exclude:                 # exclude words
      - GetViaHTTP
ifacenames
analyzers-settings:
  ifacenames:
    include-generated: false # include generated codes (default: false)
    all: true                # all interface names with the -er suffix are required (default: false)
mixedcaps
analyzers-settings:
  mixedcaps:
    include-generated: false # include generated codes (default: false)
    exclude:                 # exclude words
      - DBTX
      - EXPECT
nilslices
analyzers-settings:
  nilslices:
    include-generated: false # include generated codes (default: false)
pkgnames
analyzers-settings:
  pkgnames:
    include-generated: false # include generated codes (default: false)
recvnames
analyzers-settings:
  recvnames:
    include-generated: false # include generated codes (default: false)
repetition
analyzers-settings:
  repetition:
    include-generated: false # include generated codes (default: false)
    exclude:                 # exclude words
      - limitStr
underscores
analyzers-settings:
  underscores:
    include-generated: false # include generated codes (default: false)
    exclude:                 # exclude words
      - DBTX
      - EXPECT
varnames
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)

Install

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

manually:

Download binary from releases page

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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