| 1 |
run: |
| 2 |
# Timeout for analysis, e.g. 30s, 5m. |
| 3 |
timeout: 3m |
| 4 |
|
| 5 |
# Fail if the error was met. |
| 6 |
issues-exit-code: 1 |
| 7 |
|
| 8 |
# This is very important, bugs in tests are not acceptable either. |
| 9 |
tests: true |
| 10 |
|
| 11 |
# In most cases this can be empty but there is a popular pattern |
| 12 |
# to keep integration tests under this tag. Such tests often require |
| 13 |
# additional setups like Postgres, Redis etc and are run separately. |
| 14 |
# (to be honest I don't find this useful but I have such tags) |
| 15 |
build-tags: |
| 16 |
- integration |
| 17 |
|
| 18 |
# With the read-only mode linter will fail if go.mod file is outdated. |
| 19 |
modules-download-mode: readonly |
| 20 |
|
| 21 |
# Keep this empty to use the Go version from the go.mod file. |
| 22 |
go: "" |
| 23 |
|
| 24 |
linters: |
| 25 |
disable-all: true |
| 26 |
enable: |
| 27 |
## enabled by default |
| 28 |
- errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases |
| 29 |
- gosimple # specializes in simplifying a code |
| 30 |
- govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string |
| 31 |
- ineffassign # detects when assignments to existing variables are not used |
| 32 |
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks |
| 33 |
- typecheck # like the front-end of a Go compiler, parses and type-checks Go code |
| 34 |
- unused # checks for unused constants, variables, functions and types |
| 35 |
- asasalint # checks for pass []any as any in variadic func(...any) |
| 36 |
- asciicheck # checks that your code does not contain non-ASCII identifiers |
| 37 |
- bidichk # checks for dangerous unicode character sequences |
| 38 |
- bodyclose # checks whether HTTP response body is closed successfully |
| 39 |
- cyclop # checks function and package cyclomatic complexity |
| 40 |
- dupl # tool for code clone detection |
| 41 |
- durationcheck # checks for two durations multiplied together |
| 42 |
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error |
| 43 |
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13 |
| 44 |
- exhaustive # checks exhaustiveness of enum switch statements |
| 45 |
- forbidigo # forbids identifiers |
| 46 |
- funlen # tool for detection of long functions |
| 47 |
- gocheckcompilerdirectives # validates go compiler directive comments (//go:) |
| 48 |
- gochecknoinits # checks that no init functions are present in Go code |
| 49 |
- gochecksumtype # checks exhaustiveness on Go "sum types" |
| 50 |
- gocognit # computes and checks the cognitive complexity of functions |
| 51 |
- goconst # finds repeated strings that could be replaced by a constant |
| 52 |
- gocritic # provides diagnostics that check for bugs, performance and style issues |
| 53 |
- gocyclo # computes and checks the cyclomatic complexity of functions |
| 54 |
- godot # checks if comments end in a period |
| 55 |
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt |
| 56 |
- gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod |
| 57 |
- gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations |
| 58 |
- goprintffuncname # checks that printf-like functions are named with f at the end |
| 59 |
- gosec # inspects source code for security problems |
| 60 |
- loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap) |
| 61 |
- makezero # finds slice declarations with non-zero initial length |
| 62 |
- mirror # reports wrong mirror patterns of bytes/strings usage |
| 63 |
- musttag # enforces field tags in (un)marshaled structs |
| 64 |
- nakedret # finds naked returns in functions greater than a specified function length |
| 65 |
- nestif # reports deeply nested if statements |
| 66 |
- nilerr # finds the code that returns nil even if it checks that the error is not nil |
| 67 |
- nilnil # checks that there is no simultaneous return of nil error and an invalid value |
| 68 |
- noctx # finds sending http request without context.Context |
| 69 |
- nolintlint # reports ill-formed or insufficient nolint directives |
| 70 |
- nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL |
| 71 |
- perfsprint # checks that fmt.Sprintf can be replaced with a faster alternative |
| 72 |
- predeclared # finds code that shadows one of Go's predeclared identifiers |
| 73 |
- promlinter # checks Prometheus metrics naming via promlint |
| 74 |
- protogetter # reports direct reads from proto message fields when getters should be used |
| 75 |
- reassign # checks that package variables are not reassigned |
| 76 |
- revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint |
| 77 |
- rowserrcheck # checks whether Err of rows is checked successfully |
| 78 |
- sloglint # ensure consistent code style when using log/slog |
| 79 |
- sqlclosecheck # checks that sql.Rows and sql.Stmt are closed |
| 80 |
- stylecheck # is a replacement for golint |
| 81 |
- testableexamples # checks if examples are testable (have an expected output) |
| 82 |
- testifylint # checks usage of github.com/stretchr/testify |
| 83 |
- testpackage # makes you use a separate _test package |
| 84 |
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes |
| 85 |
- unconvert # removes unnecessary type conversions |
| 86 |
- unparam # reports unused function parameters |
| 87 |
- usestdlibvars # detects the possibility to use variables/constants from the Go standard library |
| 88 |
- wastedassign # finds wasted assignment statements |
| 89 |
- whitespace # detects leading and trailing whitespace |
| 90 |
- misspell # finds commonly misspelled English words in comments |
| 91 |
- prealloc # can be used to find slice declarations that could potentially be preallocated |
| 92 |
- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers |
| 93 |
- containedctx # detects struct contained context.Context field |
| 94 |
- decorder # checks declaration order and count of types, constants, variables and functions |
| 95 |
- dogsled # checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) |
| 96 |
- paralleltest # detects missing usage of t.Parallel() method in your Go test |
| 97 |
- tagalign # checks that struct tags are well aligned |
| 98 |
|
| 99 |
## may want to enable |
| 100 |
# - wrapcheck # checks that errors returned from external packages are wrapped |
| 101 |
#- gci # controls golang package import order and makes it always deterministic |
| 102 |
#- ginkgolinter # [if you use ginkgo/gomega] enforces standards of using ginkgo and gomega |
| 103 |
#- godox # detects FIXME, TODO and other comment keywords |
| 104 |
#- goheader # checks is file header matches to pattern |
| 105 |
#- inamedparam # [great idea, but too strict, need to ignore a lot of cases by default] reports interfaces with unnamed method parameters |
| 106 |
#- interfacebloat # checks the number of methods inside an interface |
| 107 |
# - ireturn # accept interfaces, return concrete types |
| 108 |
# - varnamelen # [great idea, but too many false positives] checks that the length of a variable's name matches its scope |
| 109 |
# - nlreturn # checks for a new line before return and branch statements to increase code clarity |
| 110 |
|
| 111 |
## disabled |
| 112 |
# - lll # reports long lines |
| 113 |
# - exhaustruct # checks if all structure fields are initialized |
| 114 |
#- goerr113 # [too strict] checks the errors handling expressions |
| 115 |
#- gosmopolitan # reports certain i18n/l10n anti-patterns in your Go codebase |
| 116 |
#- grouper # analyzes expression groups |
| 117 |
#- importas # enforces consistent import aliases |
| 118 |
#- maintidx # measures the maintainability index of each function |
| 119 |
#- tagliatelle # checks the struct tags |
| 120 |
#- contextcheck # Check whether the function uses a non-inherited context. |
| 121 |
|
| 122 |
# This file contains only configs which differ from defaults. |
| 123 |
# All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml |
| 124 |
linters-settings: |
| 125 |
nestif: |
| 126 |
min-complexity: 8 |
| 127 |
cyclop: |
| 128 |
# The maximal code complexity to report. |
| 129 |
# Default: 10 |
| 130 |
max-complexity: 30 |
| 131 |
# The maximal average package complexity. |
| 132 |
# If it's higher than 0.0 (float) the check is enabled |
| 133 |
# Default: 0.0 |
| 134 |
package-average: 10.0 |
| 135 |
|
| 136 |
dupl: |
| 137 |
# tokens count to trigger issue, 150 by default |
| 138 |
threshold: 500 |
| 139 |
|
| 140 |
errcheck: |
| 141 |
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`. |
| 142 |
# Such cases aren't reported by default. |
| 143 |
# Default: false |
| 144 |
check-type-assertions: true |
| 145 |
|
| 146 |
exhaustive: |
| 147 |
check: |
| 148 |
- switch |
| 149 |
- map |
| 150 |
|
| 151 |
nlreturn: |
| 152 |
block-size: 8 |
| 153 |
|
| 154 |
gosec: |
| 155 |
excludes: |
| 156 |
- G404 # Ignore insecure random number source. |
| 157 |
|
| 158 |
funlen: |
| 159 |
# Checks the number of lines in a function. |
| 160 |
# If lower than 0, disable the check. |
| 161 |
# Default: 60 |
| 162 |
lines: 150 |
| 163 |
# Checks the number of statements in a function. |
| 164 |
# If lower than 0, disable the check. |
| 165 |
# Default: 40 |
| 166 |
statements: 60 |
| 167 |
# Ignore comments when counting lines. |
| 168 |
# Default false |
| 169 |
ignore-comments: true |
| 170 |
|
| 171 |
gocognit: |
| 172 |
# Minimal code complexity to report. |
| 173 |
# Default: 30 (but we recommend 10-20) |
| 174 |
min-complexity: 70 |
| 175 |
|
| 176 |
gocritic: |
| 177 |
# Settings passed to gocritic. |
| 178 |
# The settings key is the name of a supported gocritic checker. |
| 179 |
# The list of supported checkers can be find in https://go-critic.github.io/overview. |
| 180 |
settings: |
| 181 |
captLocal: |
| 182 |
# Whether to restrict checker to params only. |
| 183 |
# Default: true |
| 184 |
paramsOnly: false |
| 185 |
underef: |
| 186 |
# Whether to skip (*x).method() calls where x is a pointer receiver. |
| 187 |
# Default: true |
| 188 |
skipRecvDeref: false |
| 189 |
|
| 190 |
gomodguard: |
| 191 |
blocked: |
| 192 |
# List of blocked modules. |
| 193 |
# Default: [] |
| 194 |
modules: |
| 195 |
- github.com/golang/protobuf: |
| 196 |
recommendations: |
| 197 |
- google.golang.org/protobuf |
| 198 |
reason: "see https://developers.google.com/protocol-buffers/docs/reference/go/faq#modules" |
| 199 |
- github.com/satori/go.uuid: |
| 200 |
recommendations: |
| 201 |
- github.com/google/uuid |
| 202 |
reason: "satori's package is not maintained" |
| 203 |
- github.com/gofrs/uuid: |
| 204 |
recommendations: |
| 205 |
- github.com/google/uuid |
| 206 |
reason: "gofrs' package is not go module" |
| 207 |
|
| 208 |
govet: |
| 209 |
# Enable all analyzers. |
| 210 |
# Default: false |
| 211 |
enable-all: true |
| 212 |
# Disable analyzers by name. |
| 213 |
# Run `go tool vet help` to see all analyzers. |
| 214 |
# Default: [] |
| 215 |
disable: |
| 216 |
- fieldalignment # too strict |
| 217 |
|
| 218 |
nakedret: |
| 219 |
# Make an issue if func has more lines of code than this setting, and it has naked returns. |
| 220 |
# Default: 30 |
| 221 |
max-func-lines: 0 |
| 222 |
|
| 223 |
nolintlint: |
| 224 |
# Exclude following linters from requiring an explanation. |
| 225 |
# Default: [] |
| 226 |
allow-no-explanation: [funlen, gocognit, lll] |
| 227 |
# Enable to require an explanation of nonzero length after each nolint directive. |
| 228 |
# Default: false |
| 229 |
require-explanation: true |
| 230 |
# Enable to require nolint directives to mention the specific linter being suppressed. |
| 231 |
# Default: false |
| 232 |
require-specific: true |
| 233 |
|
| 234 |
rowserrcheck: |
| 235 |
# database/sql is always checked |
| 236 |
# Default: [] |
| 237 |
packages: |
| 238 |
- github.com/jmoiron/sqlx |
| 239 |
|
| 240 |
issues: |
| 241 |
# Maximum count of issues with the same text. |
| 242 |
# Set to 0 to disable. |
| 243 |
# Default: 3 |
| 244 |
max-same-issues: 50 |
| 245 |
|
| 246 |
# Don't lint the vendor or example directories. |
| 247 |
exclude-dirs: |
| 248 |
- ^vendor$ |
| 249 |
- examples |
| 250 |
|
| 251 |
# When enabled, the following directories: are going to be skipped: vendor$, |
| 252 |
# third_party$, testdata$, examples$, Godeps$, builtin$. |
| 253 |
exclude-dirs-use-default: false |
| 254 |
|
| 255 |
exclude-rules: |
| 256 |
- source: "(noinspection|TODO)" |
| 257 |
linters: [godot] |
| 258 |
- source: "//noinspection" |
| 259 |
linters: [gocritic] |
| 260 |
- path: "_test\\.go" |
| 261 |
linters: |
| 262 |
- bodyclose |
| 263 |
- dupl |
| 264 |
- funlen |
| 265 |
- goconst |
| 266 |
- gosec |
| 267 |
- noctx |
| 268 |
- wrapcheck |
| 269 |
- exhaustruct |
| 270 |
- unparam |
| 271 |
- errcheck |