Skip to content

Commit efa2e6b

Browse files
authored
Sync .golangci.yml with prometheus/prometheus (#817)
* Sync .golangci.yml with prometheus/prometheus Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Fix formatting in some *.go files Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> --------- Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
1 parent 9deefba commit efa2e6b

9 files changed

Lines changed: 158 additions & 31 deletions

.golangci.yml

Lines changed: 146 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,103 @@
11
version: "2"
22
linters:
3+
# Keep this list sorted alphabetically
34
enable:
5+
- depguard
46
- errorlint
7+
- exptostd
8+
#- fatcontext
9+
#- gocritic
10+
#- godot
11+
- govet
12+
- loggercheck
513
- misspell
14+
- nilnesserr
15+
# TODO(bwplotka): Enable once https://github.com/golangci/golangci-lint/issues/3228 is fixed.
16+
# - nolintlint
617
- perfsprint
18+
- predeclared
719
- revive
20+
- sloglint
821
- testifylint
22+
#- unconvert
23+
- unused
24+
#- usestdlibvars
25+
- whitespace
26+
exclusions:
27+
generated: lax
28+
presets:
29+
- comments
30+
- common-false-positives
31+
- legacy
32+
- std-error-handling
33+
paths:
34+
- third_party$
35+
- builtin$
36+
- examples$
37+
rules:
38+
- linters:
39+
- errcheck
40+
# Taken from the default exclusions in v1.
41+
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
42+
- linters:
43+
- govet
44+
# We use many Seek methods that do not follow the usual pattern.
45+
text: "stdmethods: method Seek.* should have signature Seek"
46+
- linters:
47+
- revive
48+
# We have stopped at some point to write doc comments on exported symbols.
49+
# TODO(beorn7): Maybe we should enforce this again?
50+
text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported
51+
- linters:
52+
- gocritic
53+
text: "appendAssign"
54+
- linters:
55+
- errcheck
56+
path: _test.go
57+
- linters:
58+
- errorlint
59+
path: "tsdb/head_wal.go"
60+
- linters:
61+
- godot
62+
source: "^// ==="
63+
warn-unused: true
964
settings:
65+
depguard:
66+
rules:
67+
main:
68+
deny:
69+
#- pkg: "sync/atomic"
70+
#desc: "Use go.uber.org/atomic instead of sync/atomic"
71+
- pkg: "github.com/go-kit/kit/log"
72+
desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
73+
- pkg: "io/ioutil"
74+
desc: "Use corresponding 'os' or 'io' functions instead."
75+
#- pkg: "regexp"
76+
#desc: "Use github.com/grafana/regexp instead of regexp"
77+
- pkg: "github.com/pkg/errors"
78+
desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors"
79+
- pkg: "gzip"
80+
desc: "Use github.com/klauspost/compress instead of gzip"
81+
- pkg: "zlib"
82+
desc: "Use github.com/klauspost/compress instead of zlib"
83+
- pkg: "golang.org/x/exp/slices"
84+
desc: "Use 'slices' instead."
85+
errcheck:
86+
exclude-functions:
87+
# Don't flag lines such as "io.Copy(io.Discard, resp.Body)".
88+
- io.Copy
89+
# The next two are used in HTTP handlers, any error is handled by the server itself.
90+
- io.WriteString
91+
- (net/http.ResponseWriter).Write
92+
# No need to check for errors on server's shutdown.
93+
- (*net/http.Server).Shutdown
94+
# Never check for rollback errors as Rollback() is called when a previous error was detected.
95+
- (github.com/prometheus/prometheus/storage.Appender).Rollback
96+
govet:
97+
disable:
98+
- shadow
99+
- fieldalignment
100+
enable-all: true
10101
perfsprint:
11102
# Optimizes even if it requires an int or uint type cast.
12103
int-conversion: true
@@ -19,36 +110,79 @@ linters:
19110
# Optimizes into strings concatenation.
20111
strconcat: false
21112
revive:
113+
# By default, revive will enable only the linting rules that are named in the configuration file.
114+
# So, it's needed to explicitly enable all required rules here.
22115
rules:
23-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
116+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
117+
- name: blank-imports
118+
- name: comment-spacings
119+
- name: context-as-argument
120+
arguments:
121+
# Allow functions with test or bench signatures.
122+
- allowTypesBefore: '*testing.T,testing.TB'
123+
- name: context-keys-type
124+
#- name: dot-imports
125+
#- name: early-return
126+
# arguments:
127+
# - "preserveScope"
128+
# A lot of false positives: incorrectly identifies channel draining as "empty code block".
129+
# See https://github.com/mgechev/revive/issues/386
130+
- name: empty-block
131+
disabled: true
132+
- name: error-naming
133+
- name: error-return
134+
- name: error-strings
135+
- name: errorf
136+
#- name: exported
137+
#- name: increment-decrement
138+
#- name: indent-error-flow
139+
# arguments:
140+
# - "preserveScope"
141+
- name: package-comments
142+
# TODO(beorn7): Currently, we have a lot of missing package doc comments. Maybe we should have them.
143+
disabled: true
144+
- name: range
145+
#- name: receiver-naming
146+
- name: redefines-builtin-id
147+
- name: superfluous-else
148+
arguments:
149+
- "preserveScope"
150+
- name: time-naming
151+
#- name: unexported-return
152+
- name: unreachable-code
24153
- name: unused-parameter
25154
severity: warning
26155
disabled: true
156+
#- name: unused-receiver
157+
#- name: var-declaration
158+
#- name: var-naming
27159
testifylint:
28160
enable-all: true
29161
disable:
162+
- float-compare
30163
- go-require
31164
formatter:
32165
require-f-funcs: true
33-
exclusions:
34-
generated: lax
35-
presets:
36-
- comments
37-
- common-false-positives
38-
- legacy
39-
- std-error-handling
40-
paths:
41-
- third_party$
42-
- builtin$
43-
- examples$
44166
issues:
45167
max-issues-per-linter: 0
46168
max-same-issues: 0
169+
output:
170+
show-stats: false
171+
run:
172+
timeout: 15m
47173
formatters:
48174
enable:
175+
- gci
49176
- gofumpt
50177
- goimports
51178
settings:
179+
gci:
180+
sections:
181+
- standard
182+
- default
183+
- prefix(github.com/prometheus/common)
184+
gofumpt:
185+
extra-rules: true
52186
goimports:
53187
local-prefixes:
54188
- github.com/prometheus/common

expfmt/bench_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ import (
2222
"os"
2323
"testing"
2424

25-
"google.golang.org/protobuf/encoding/protodelim"
26-
2725
dto "github.com/prometheus/client_model/go"
2826
"github.com/stretchr/testify/require"
27+
"google.golang.org/protobuf/encoding/protodelim"
2928

3029
"github.com/prometheus/common/model"
3130
)

expfmt/encode.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ import (
1818
"io"
1919
"net/http"
2020

21+
"github.com/munnerz/goautoneg"
22+
dto "github.com/prometheus/client_model/go"
2123
"google.golang.org/protobuf/encoding/protodelim"
2224
"google.golang.org/protobuf/encoding/prototext"
2325

2426
"github.com/prometheus/common/model"
25-
26-
"github.com/munnerz/goautoneg"
27-
28-
dto "github.com/prometheus/client_model/go"
2927
)
3028

3129
// Encoder types encode metric families into an underlying wire protocol.

expfmt/encode_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ import (
1818
"net/http"
1919
"testing"
2020

21+
dto "github.com/prometheus/client_model/go"
2122
"github.com/stretchr/testify/assert"
2223
"github.com/stretchr/testify/require"
2324
"google.golang.org/protobuf/proto"
2425

2526
"github.com/prometheus/common/model"
26-
27-
dto "github.com/prometheus/client_model/go"
2827
)
2928

3029
func TestNegotiate(t *testing.T) {

expfmt/expfmt_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ package expfmt
1616
import (
1717
"testing"
1818

19-
"github.com/prometheus/common/model"
20-
2119
"github.com/stretchr/testify/require"
20+
21+
"github.com/prometheus/common/model"
2222
)
2323

2424
// Test Format to Escapting Scheme conversion

expfmt/openmetrics_create.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ import (
2222
"strconv"
2323
"strings"
2424

25+
dto "github.com/prometheus/client_model/go"
2526
"google.golang.org/protobuf/types/known/timestamppb"
2627

2728
"github.com/prometheus/common/model"
28-
29-
dto "github.com/prometheus/client_model/go"
3029
)
3130

3231
type encoderOption struct {

expfmt/openmetrics_create_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ import (
2020
"testing"
2121
"time"
2222

23-
"google.golang.org/protobuf/proto"
24-
"google.golang.org/protobuf/types/known/timestamppb"
25-
2623
dto "github.com/prometheus/client_model/go"
2724
"github.com/stretchr/testify/require"
25+
"google.golang.org/protobuf/proto"
26+
"google.golang.org/protobuf/types/known/timestamppb"
2827

2928
"github.com/prometheus/common/model"
3029
)

expfmt/text_create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import (
2222
"strings"
2323
"sync"
2424

25-
"github.com/prometheus/common/model"
26-
2725
dto "github.com/prometheus/client_model/go"
26+
27+
"github.com/prometheus/common/model"
2828
)
2929

3030
// enhancedWriter has all the enhanced write functions needed here. bufio.Writer

expfmt/text_create_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ import (
1919
"strings"
2020
"testing"
2121

22-
"google.golang.org/protobuf/proto"
23-
2422
dto "github.com/prometheus/client_model/go"
2523
"github.com/stretchr/testify/require"
24+
"google.golang.org/protobuf/proto"
2625

2726
"github.com/prometheus/common/model"
2827
)

0 commit comments

Comments
 (0)