mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-13 17:14:05 -08:00
0f760f63dd
Several things done here: - Set `max-issues-per-linter` to 0 so that we actually see all linter warnings and not just 50 per linter. (As we also set `max-same-issues` to 0, I assume this was the intention from the beginning.) - Stop using the golangci-lint default excludes (by setting `exclude-use-default: false`. Those are too generous and don't match our style conventions. (I have re-added some of the excludes explicitly in this commit. See below.) - Re-add the `errcheck` exclusion we have used so far via the defaults. - Exclude the signature requirement `govet` has for `Seek` methods because we use non-standard `Seek` methods a lot. (But we keep other requirements, while the default excludes completely disabled the check for common method segnatures.) - Exclude warnings about missing doc comments on exported symbols. (We used to be pretty adamant about doc comments, but stopped that at some point in the past. By now, we have about 500 missing doc comments. We may consider reintroducing this check, but that's outside of the scope of this commit. The default excludes of golangci-lint essentially ignore doc comments completely.) - By stop using the default excludes, we now get warnings back on malformed doc comments. That's the most impactful change in this commit. It does not enforce doc comments (again), but _if_ there is a doc comment, it has to have the recommended form. (Most of the changes in this commit are fixing this form.) - Improve wording/spelling of some comments in .golangci.yml, and remove an outdated comment. - Leave `package-comments` inactive, but add a TODO asking if we should change that. - Add a new sub-linter `comment-spacings` (and fix corresponding comments), which avoids missing spaces after the leading `//`. Signed-off-by: beorn7 <beorn@grafana.com>
167 lines
5.4 KiB
YAML
167 lines
5.4 KiB
YAML
run:
|
|
timeout: 15m
|
|
|
|
output:
|
|
sort-results: true
|
|
|
|
linters:
|
|
enable:
|
|
- depguard
|
|
- errorlint
|
|
- gocritic
|
|
- godot
|
|
- gofumpt
|
|
- goimports
|
|
- misspell
|
|
- nolintlint
|
|
- perfsprint
|
|
- predeclared
|
|
- revive
|
|
- testifylint
|
|
- unconvert
|
|
- unused
|
|
- usestdlibvars
|
|
- whitespace
|
|
- loggercheck
|
|
|
|
issues:
|
|
max-issues-per-linter: 0
|
|
max-same-issues: 0
|
|
# The default exclusions are too aggressive. For one, they
|
|
# essentially disable any linting on doc comments. We disable
|
|
# default exclusions here and add exclusions fitting our codebase
|
|
# further down.
|
|
exclude-use-default: false
|
|
exclude-files:
|
|
# Skip autogenerated files.
|
|
- ^.*\.(pb|y)\.go$
|
|
exclude-dirs:
|
|
# Copied it from a different source.
|
|
- storage/remote/otlptranslator/prometheusremotewrite
|
|
- storage/remote/otlptranslator/prometheus
|
|
exclude-rules:
|
|
- linters:
|
|
- errcheck
|
|
# Taken from the default exclusions (that are otherwise disabled above).
|
|
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
|
|
- linters:
|
|
- govet
|
|
# We use many Seek methods that do not follow the usual pattern.
|
|
text: "stdmethods: method Seek.* should have signature Seek"
|
|
- linters:
|
|
- revive
|
|
# We have stopped at some point to write doc comments on exported symbols.
|
|
# TODO(beorn7): Maybe we should enforce this again? There are ~500 offenders right now.
|
|
text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported
|
|
- linters:
|
|
- gocritic
|
|
text: "appendAssign"
|
|
- path: _test.go
|
|
linters:
|
|
- errcheck
|
|
- path: "tsdb/head_wal.go"
|
|
linters:
|
|
- errorlint
|
|
- linters:
|
|
- godot
|
|
source: "^// ==="
|
|
- linters:
|
|
- perfsprint
|
|
text: "fmt.Sprintf can be replaced with string concatenation"
|
|
linters-settings:
|
|
depguard:
|
|
rules:
|
|
main:
|
|
deny:
|
|
- pkg: "sync/atomic"
|
|
desc: "Use go.uber.org/atomic instead of sync/atomic"
|
|
- pkg: "github.com/stretchr/testify/assert"
|
|
desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert"
|
|
- pkg: "github.com/go-kit/kit/log"
|
|
desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
|
|
- pkg: "io/ioutil"
|
|
desc: "Use corresponding 'os' or 'io' functions instead."
|
|
- pkg: "regexp"
|
|
desc: "Use github.com/grafana/regexp instead of regexp"
|
|
- pkg: "github.com/pkg/errors"
|
|
desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors"
|
|
- pkg: "gzip"
|
|
desc: "Use github.com/klauspost/compress instead of gzip"
|
|
- pkg: "zlib"
|
|
desc: "Use github.com/klauspost/compress instead of zlib"
|
|
- pkg: "golang.org/x/exp/slices"
|
|
desc: "Use 'slices' instead."
|
|
errcheck:
|
|
exclude-functions:
|
|
# Don't flag lines such as "io.Copy(io.Discard, resp.Body)".
|
|
- io.Copy
|
|
# The next two are used in HTTP handlers, any error is handled by the server itself.
|
|
- io.WriteString
|
|
- (net/http.ResponseWriter).Write
|
|
# No need to check for errors on server's shutdown.
|
|
- (*net/http.Server).Shutdown
|
|
# Never check for logger errors.
|
|
- (github.com/go-kit/log.Logger).Log
|
|
# Never check for rollback errors as Rollback() is called when a previous error was detected.
|
|
- (github.com/prometheus/prometheus/storage.Appender).Rollback
|
|
goimports:
|
|
local-prefixes: github.com/prometheus/prometheus
|
|
gofumpt:
|
|
extra-rules: true
|
|
perfsprint:
|
|
# Optimizes `fmt.Errorf`.
|
|
errorf: false
|
|
revive:
|
|
# By default, revive will enable only the linting rules that are named in the configuration file.
|
|
# So, it's needed to explicitly enable all required rules here.
|
|
rules:
|
|
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
|
|
- name: blank-imports
|
|
- name: comment-spacings
|
|
- name: context-as-argument
|
|
arguments:
|
|
# Allow functions with test or bench signatures.
|
|
- allowTypesBefore: "*testing.T,testing.TB"
|
|
- name: context-keys-type
|
|
- name: dot-imports
|
|
# A lot of false positives: incorrectly identifies channel draining as "empty code block".
|
|
# See https://github.com/mgechev/revive/issues/386
|
|
- name: empty-block
|
|
disabled: true
|
|
- name: error-naming
|
|
- name: error-return
|
|
- name: error-strings
|
|
- name: errorf
|
|
- name: exported
|
|
- name: increment-decrement
|
|
- name: indent-error-flow
|
|
- name: package-comments
|
|
# TODO(beorn7): Currently, we have a lot of missing package doc comments. Maybe we should have them.
|
|
disabled: true
|
|
- name: range
|
|
- name: receiver-naming
|
|
- name: redefines-builtin-id
|
|
- name: superfluous-else
|
|
- name: time-naming
|
|
- name: unexported-return
|
|
- name: unreachable-code
|
|
- name: unused-parameter
|
|
disabled: true
|
|
- name: var-declaration
|
|
- name: var-naming
|
|
testifylint:
|
|
disable:
|
|
- float-compare
|
|
- go-require
|
|
enable:
|
|
- bool-compare
|
|
- compares
|
|
- empty
|
|
- error-is-as
|
|
- error-nil
|
|
- expected-actual
|
|
- len
|
|
- require-error
|
|
- suite-dont-use-pkg
|
|
- suite-extra-assert-call
|