Skip to content

Instantly share code, notes, and snippets.

@adrianbrad
Last active March 22, 2023 12:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianbrad/3811b6c9e720a51f19f67efc66da40f2 to your computer and use it in GitHub Desktop.
Save adrianbrad/3811b6c9e720a51f19f67efc66da40f2 to your computer and use it in GitHub Desktop.
golangci-lint strict config file
# .golangci.yml
run:
modules-download-mode: vendor
skip-dirs: [vendor]
linters-settings:
staticcheck:
# Select the Go version to target. The default is '1.13'.
go: "1.19"
# https://staticcheck.io/docs/options#checks
checks: [ "all" ]
tagliatelle:
# Check the struck tag name case.
case:
# Use the struct field name to check the name of the struct tag.
# Default: false
use-field-name: true
rules:
# Any struct tag type can be used.
# Support string case: `camel`, `pascal`, `kebab`, `snake`, `goCamel`, `goPascal`, `goKebab`, `goSnake`, `upper`, `lower`
json: snake
dupl:
threshold: 300 # tokens count of duplicate code to trigger issue
goconst:
min-len: 2 # minimal length of string constant
min-occurrences: 2 # minimal occurrences count to trigger
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- whyNoLint
- hugeParam
gocyclo:
min-complexity: 8 # minimal code cyclomatic complexity to report
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks: [argument,case,condition,return]
misspell:
locale: US
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: true # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
gocognit:
min-complexity: 10 # minimal code cognitive complexity to report
gofumpt:
extra-rules: true
varnamelen:
max-distance: 15
ignore-names:
- tx
- err
- pk
- to
- db
- wg
- id
- DB
ignore-type-assert-ok: true
ignore-map-index-ok: true
ignore-chan-recv-ok: true
ignore-decls:
- t testing.T
- i int
- T any
- i *is.I
- eg *errgroup.Group
- ok bool
- wh *webhook.Webhook
- ev *event.Event
revive:
ignore-generated-header: true
enable-all-rules: true
confidence: 0.1
rules:
- name: nested-structs
disabled: true
- name: function-result-limit
arguments: [ 3 ]
- name: function-length
disabled: true
- name: banned-characters
disabled: true
- name: max-public-structs
disabled: true
- name: line-length-limit
arguments: [ 80 ]
- name: argument-limit
disabled: true
- name: cyclomatic
disabled: true
- name: file-header
disabled: true
- name: cognitive-complexity
disabled: true
- name: package-comments
disabled: true
- name: add-constant
disabled: true
- name: unhandled-error
disabled: true
- name: var-naming
arguments: [[], ["WS", "VM"]]
linters:
disable-all: true
enable:
# - asasalint # Check for pass []any as any in variadic func(...any)
- bidichk # Checks for dangerous unicode character sequences
- contextcheck # check the function whether use a non-inherited context
- containedctx # containedctx is a linter that detects struct contained context.Context field
- decorder # check declaration order and count of types, constants, variables and functions
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted.
- grouper # An analyzer to analyze expression groups.
- govet # Vet examines Go source code and reports suspicious constructs, only purpose of this tool is to detect go structs that would take less memory if their fields were sorted
- bodyclose # Detects whether the HTTP response body is closed successfully, not closing the response body could lead to memory leaks
- goconst # Finds repeated strings that could be replaced by a constant
- godot # Check if comments end in a period
- gomnd # An analyzer to detect magic numbers.
- goerr113 # Golang linter to check the errors handling expressions
- gocritic # Provides many diagnostics that check for bugs, performance and style issues.
- exhaustive # Check exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables -- VERY IMPORTANT TO USE
- errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error.
- forcetypeassert # finds forced type assertions
- importas # Enforces consistent import aliases
- gci # improves imports
- dupl # Detects code clones
- revive # Makes code style recomandations
- gocyclo # Computes and checks the cyclomatic complexity of functions
- gofumpt # Stricter gofmt
- errcheck # Checks unchecked errors in go programs
- gosimple # Linter for Go source code that specializes in simplifying a code
- ineffassign # Detects when assignments to existing variables are not used
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
- tagliatelle # Checks the struct tags.
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
- unused # Checks Go code for unused constants, variables, functions and types
- varnamelen # checks that the length of a variable's name matches its scope style
- gocognit # Computes and checks the cognitive complexity of functions https://github.com/uudashr/gocognit
- gosec # Inspects source code for security problems
- prealloc # Finds slice declarations that could potentially be preallocated
- nilnil # Checks that there is no simultaneous return of nil error and an invalid value.
- wsl # Whitespace Linter - Forces you to use empty lines!
- usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library.
- interfacebloat # A linter that checks the number of methods inside an interface.
- logrlint # Check logr arguments.
- reassign # Checks that package variables are not reassigned
- dupword # checks for duplicate words in the source code comments.
issues:
exclude-use-default: false
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- gocyclo
- errcheck
- gosec
- gocognit
- forcetypeassert
- varnamelen
- nilnil
- path: mock
linters:
- gomnd
- revive
- gocyclo
- errcheck
- dupl
- gosec
- forcetypeassert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment