Skip to content

Commit d1b8ef1

Browse files
authored
chore: enable several rules from go-critic (#766)
* chore: enable-all rules from go-critic Signed-off-by: Matthieu MOREL <[email protected]> * chore: enable httpNoBody from go-critic Signed-off-by: Matthieu MOREL <[email protected]> * chore: enable assignOp rule from go-critic Signed-off-by: Matthieu MOREL <[email protected]> * chore: enable commentedOutCode rule from go-critic Signed-off-by: Matthieu MOREL <[email protected]> --------- Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 93021d2 commit d1b8ef1

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

.golangci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ linters:
88
enable:
99
- errcheck
1010
- errorlint
11+
- gocritic
1112
- misspell
1213
- testifylint
1314

@@ -16,6 +17,17 @@ linters:
1617
exclude-functions:
1718
- (github.com/go-kit/log.Logger).Log
1819

20+
gocritic:
21+
disabled-checks:
22+
- appendAssign
23+
- builtinShadow
24+
- deferInLoop
25+
- exitAfterDefer
26+
- hugeParam
27+
- importShadow
28+
- unnamedResult
29+
enable-all: true
30+
1931
testifylint:
2032
disable:
2133
- go-require

interceptors/realip/realip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func ipFromHeaders(ctx context.Context, headers []string, trustedProxies []netip
8181
a := strings.Split(getHeader(ctx, header), ",")
8282
idx := len(a) - 1
8383
if header == XForwardedFor {
84-
idx = idx - int(trustedProxyCnt)
84+
idx -= int(trustedProxyCnt)
8585
if idx < 0 {
8686
continue
8787
}

providers/prometheus/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (s *ServerInterceptorTestSuite) TestContextCancelledTreatedAsStatus() {
175175
// Order of matching label vales does not matter.
176176
func fetchPrometheusLines(t *testing.T, reg prometheus.Gatherer, metricName string, matchingLabelValues ...string) []string {
177177
resp := httptest.NewRecorder()
178-
req, err := http.NewRequest("GET", "/", nil)
178+
req, err := http.NewRequest("GET", "/", http.NoBody)
179179
require.NoError(t, err, "failed creating request for Prometheus handler")
180180

181181
promhttp.HandlerFor(reg, promhttp.HandlerOpts{}).ServeHTTP(resp, req)

testing/testpb/interceptor_suite.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ func ExtractErrorFields(err error) []any {
188188
// UnaryServerInterceptor returns a new unary server interceptors that adds query information logging.
189189
func UnaryServerInterceptor() grpc.UnaryServerInterceptor {
190190
return func(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
191-
// newCtx := newContext(ctx, log, opts)
192191
newCtx := ctx
193192
resp, err := handler(newCtx, req)
194193
return resp, err

0 commit comments

Comments
 (0)