Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update golangci-lint config #379

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
305 changes: 264 additions & 41 deletions _template/.golangci.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,276 @@
run:
timeout: 10m
issues-exit-code: 1
tests: true

linters:
# Enable specific linter
# https://golangci-lint.run/usage/linters/
enable:
- cyclop # Go linter that checks if the cyclic complexity of a function is acceptable
- dogsled # Checks assignments with too many blank identifiers (e.g. x, , , _, := f())
- dupl # Tool for code clone detection
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
- exhaustive # check exhaustiveness of enum switch statements
- exportloopref # checks for pointers to enclosing loop variables
- funlen # Tool for detection of long functions
- gochecknoglobals # A global variable is a variable declared in package scope and that can be read and written to by any function within the package.
- gocritic # Provides diagnostics that check for bugs, performance and style issues.
- goconst # Inspects source code for security problems
- gocyclo # Computes and checks the cyclomatic complexity of functions
- goerr113 # Golang linter to check the errors handling expressions
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt.
- gomnd # An analyzer to detect magic numbers.
- goprintffuncname # Checks that printf-like functions are named with f at the end
- gosec # Inspects source code for security problems
- misspell # Finds commonly misspelled English words in comments
- nakedret # Finds naked returns in functions greater than a specified function length
- nestif # Reports deeply nested if statements
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
- noctx # noctx finds sending http request without context.Context
- nolintlint # Reports ill-formed or insufficient nolint directives
- prealloc # Finds slice declarations that could potentially be pre-allocated
- promlinter # Check Prometheus metrics naming via promlint
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
- unconvert # Remove unnecessary type conversions
- unparam # Reports unused function parameters
- whitespace # Tool for detection of leading and trailing whitespace

linters-settings:
errcheck:
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
check-type-assertions: true

# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: true
exhaustive:
# Presence of "default" case in switch statements satisfies exhaustiveness,
# even if all enum members are not listed.
default-signifies-exhaustive: true
funlen:
lines: 100
statements: 50
gci:
custom-order: true
sections:
- standard
- default
- prefix(dev.azure.com/schwarzit)
goimports:
local-prefixes: dev.azure.com/schwarzit
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
gocyclo:
min-complexity: 30
gocognit:
min-complexity: 30
dupl:
threshold: 150
goconst:
min-len: 3
min-occurrences: 2
govet:
enable-all: true
disable:
- fieldalignment
depguard:
rules:
all:
deny:
- pkg: github.com/sirupsen/logrus
desc: logging is done using the internal/log and log/slog package
- pkg: log$
desc: logging is done using the internal/log and log/slog package
- pkg: go.uber.org/zap
desc: logging is done using the internal/log and log/slog package
misspell:
#locale: US
lll:
line-length: 140
tab-width: 1
cyclop:
# the maximal code complexity to report
max-complexity: 20
# the maximal average package complexity. If it's higher than 0.0 (float) the check is enabled (default 0.0)
package-average: 0.0
unused:
# treat code as a program (not a library) and report unused exported identifiers; default is false.
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
unparam:
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
max-func-lines: 5
prealloc:
# XXX: we don't recommend using this linter before doing performance profiling.
# For most programs usage of prealloc will be a premature optimization.

# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
# True by default.
simple: true
range-loops: true # Report preallocation suggestions on range loops, true by default
for-loops: true # Report preallocation suggestions on for loops, false by default
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- octalLiteral
- unnamedResult
# Settings passed to gocritic.
# The settings key is the name of a supported gocritic checker.
# The list of supported checkers can be find in https://go-critic.github.io/overview.
settings:
hugeParam:
# Size in bytes that makes the warning trigger.
# Default: 80
sizeThreshold: 80
dogsled:
# checks assignments with too many blank identifiers; default is 2
max-blank-identifiers: 2
whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
gomoddirectives:
# List of allowed `replace` directives. Default is empty.
# Add your allowed `replace` targets here, this rule is so you don't accidentally commit replacements you added for testing
replace-allow-list: []
gomnd:
settings:
mnd:
# don't include the "operation" and "assign"
checks:
- argument
- case
- condition
- return
- operation
- assign
nolintlint:
allow-leading-space: false # require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: true # require an explanation for nolint directives
require-specific: true # require nolint directives to be specific about which linter is being skipped
nlreturn:
# Size of the block (including return statement that is still "OK")
# so no return split required.
block-size: 5
stylecheck:
initialisms: ["ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS"]
revive:
rules:
- name: context-keys-type
disabled: false
- name: time-naming
disabled: false
- name: var-declaration
disabled: false
- name: unexported-return
disabled: false
- name: errorf
disabled: false
- name: blank-imports
disabled: false
- name: context-as-argument
disabled: false
- name: dot-imports
disabled: false
- name: error-return
disabled: false
- name: error-strings
disabled: false
- name: error-naming
disabled: false
- name: exported
disabled: false
- name: increment-decrement
disabled: false
- name: var-naming
disabled: false
- name: package-comments
disabled: false
- name: range
disabled: false
- name: receiver-naming
disabled: false
- name: indent-error-flow
disabled: false

linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- depguard
- dogsled
- dupl
- exportloopref
- exhaustive
- funlen
- gochecknoinits
- goconst
- gocritic
- gocyclo
- godot
- gofmt
- goimports
- gomnd
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- megacheck
- misspell
- nakedret
- nolintlint
- revive
- staticcheck
- stylecheck
- typecheck
- unconvert
- unused
- whitespace
- gochecknoglobals
- goerr113
- prealloc
- asciicheck
- nestif
- bodyclose
- cyclop
- durationcheck
- errcheck
- errorlint
- forbidigo
- forcetypeassert
- gci
- gocognit
- gofumpt
- gomoddirectives
- gomodguard
- importas
- makezero
- nilerr
- nlreturn
- noctx
- predeclared
- promlinter
- rowserrcheck
- sqlclosecheck
- tparallel
- unparam
- wastedassign
- wsl

# don't enable:
# - tagliatelle # have a different naming schema
# - golint # deprecated
# - scopelint # deprecated
# - interfacer # deprecated
# - testpackage # this is not best practice in go
# - godox # we want to use keywords like TODO or FIX in the code


issues:
# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
- path: _test\.go
linters:
- gochecknoglobals
- gosec
- funlen
- noctx
- funlen
- goerr113
- gomnd
- forcetypeassert
- dogsled
- goconst
- unparam
- dupl
- text: 'declaration of "err" shadows declaration'
linters:
- govet
max-same-issues: 0
max-issues-per-linter: 0
run:
timeout: 10m
issues-exit-code: 1
tests: true
build-tags:
- integration
Loading