diff --git a/.golangci.yml b/.golangci.yml index 844fc2e55..f22a4bcdf 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,12 +1,103 @@ version: "2" linters: + # Keep this list sorted alphabetically enable: + - depguard - errorlint + - exptostd + #- fatcontext + #- gocritic + #- godot + - govet + - loggercheck - misspell + - nilnesserr + # TODO(bwplotka): Enable once https://github.com/golangci/golangci-lint/issues/3228 is fixed. + # - nolintlint - perfsprint + - predeclared - revive + - sloglint - testifylint + #- unconvert + - unused + #- usestdlibvars + - whitespace + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ + rules: + - linters: + - errcheck + # Taken from the default exclusions in v1. + 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? + text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported + - linters: + - gocritic + text: "appendAssign" + - linters: + - errcheck + path: _test.go + - linters: + - errorlint + path: "tsdb/head_wal.go" + - linters: + - godot + source: "^// ===" + warn-unused: true settings: + depguard: + rules: + main: + deny: + #- pkg: "sync/atomic" + #desc: "Use go.uber.org/atomic instead of sync/atomic" + - 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 rollback errors as Rollback() is called when a previous error was detected. + - (github.com/prometheus/prometheus/storage.Appender).Rollback + govet: + disable: + - shadow + - fieldalignment + enable-all: true perfsprint: # Optimizes even if it requires an int or uint type cast. int-conversion: true @@ -19,36 +110,79 @@ linters: # Optimizes into strings concatenation. strconcat: 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#unused-parameter + # 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 + #- name: early-return + # arguments: + # - "preserveScope" + # 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 + # arguments: + # - "preserveScope" + - 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 + arguments: + - "preserveScope" + - name: time-naming + #- name: unexported-return + - name: unreachable-code - name: unused-parameter severity: warning disabled: true + #- name: unused-receiver + #- name: var-declaration + #- name: var-naming testifylint: enable-all: true disable: + - float-compare - go-require formatter: require-f-funcs: true - exclusions: - generated: lax - presets: - - comments - - common-false-positives - - legacy - - std-error-handling - paths: - - third_party$ - - builtin$ - - examples$ issues: max-issues-per-linter: 0 max-same-issues: 0 +output: + show-stats: false +run: + timeout: 15m formatters: enable: + - gci - gofumpt - goimports settings: + gci: + sections: + - standard + - default + - prefix(github.com/prometheus/common) + gofumpt: + extra-rules: true goimports: local-prefixes: - github.com/prometheus/common diff --git a/expfmt/bench_test.go b/expfmt/bench_test.go index 90d9373d9..1acb19965 100644 --- a/expfmt/bench_test.go +++ b/expfmt/bench_test.go @@ -22,10 +22,9 @@ import ( "os" "testing" - "google.golang.org/protobuf/encoding/protodelim" - dto "github.com/prometheus/client_model/go" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/encoding/protodelim" "github.com/prometheus/common/model" ) diff --git a/expfmt/encode.go b/expfmt/encode.go index 6af7e0014..73c24dfbc 100644 --- a/expfmt/encode.go +++ b/expfmt/encode.go @@ -18,14 +18,12 @@ import ( "io" "net/http" + "github.com/munnerz/goautoneg" + dto "github.com/prometheus/client_model/go" "google.golang.org/protobuf/encoding/protodelim" "google.golang.org/protobuf/encoding/prototext" "github.com/prometheus/common/model" - - "github.com/munnerz/goautoneg" - - dto "github.com/prometheus/client_model/go" ) // Encoder types encode metric families into an underlying wire protocol. diff --git a/expfmt/encode_test.go b/expfmt/encode_test.go index ea3cbfac7..6a801629a 100644 --- a/expfmt/encode_test.go +++ b/expfmt/encode_test.go @@ -18,13 +18,12 @@ import ( "net/http" "testing" + dto "github.com/prometheus/client_model/go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" "github.com/prometheus/common/model" - - dto "github.com/prometheus/client_model/go" ) func TestNegotiate(t *testing.T) { diff --git a/expfmt/expfmt_test.go b/expfmt/expfmt_test.go index d9373bcf3..0a5ef55b9 100644 --- a/expfmt/expfmt_test.go +++ b/expfmt/expfmt_test.go @@ -16,9 +16,9 @@ package expfmt import ( "testing" - "github.com/prometheus/common/model" - "github.com/stretchr/testify/require" + + "github.com/prometheus/common/model" ) // Test Format to Escapting Scheme conversion diff --git a/expfmt/openmetrics_create.go b/expfmt/openmetrics_create.go index fed8253ca..2a1ced3f5 100644 --- a/expfmt/openmetrics_create.go +++ b/expfmt/openmetrics_create.go @@ -22,11 +22,10 @@ import ( "strconv" "strings" + dto "github.com/prometheus/client_model/go" "google.golang.org/protobuf/types/known/timestamppb" "github.com/prometheus/common/model" - - dto "github.com/prometheus/client_model/go" ) type encoderOption struct { diff --git a/expfmt/openmetrics_create_test.go b/expfmt/openmetrics_create_test.go index a81bfed3f..eb9a9d387 100644 --- a/expfmt/openmetrics_create_test.go +++ b/expfmt/openmetrics_create_test.go @@ -20,11 +20,10 @@ import ( "testing" "time" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/types/known/timestamppb" - dto "github.com/prometheus/client_model/go" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/timestamppb" "github.com/prometheus/common/model" ) diff --git a/expfmt/text_create.go b/expfmt/text_create.go index e242b3720..c4e9c1bbc 100644 --- a/expfmt/text_create.go +++ b/expfmt/text_create.go @@ -22,9 +22,9 @@ import ( "strings" "sync" - "github.com/prometheus/common/model" - dto "github.com/prometheus/client_model/go" + + "github.com/prometheus/common/model" ) // enhancedWriter has all the enhanced write functions needed here. bufio.Writer diff --git a/expfmt/text_create_test.go b/expfmt/text_create_test.go index bb1c8f77a..967c46a2e 100644 --- a/expfmt/text_create_test.go +++ b/expfmt/text_create_test.go @@ -19,10 +19,9 @@ import ( "strings" "testing" - "google.golang.org/protobuf/proto" - dto "github.com/prometheus/client_model/go" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" "github.com/prometheus/common/model" )