Skip to content

Commit 48260bf

Browse files
authored
Upgrade golangci-lint to 1.53.3 and adjust the linters used (#76)
Some linters had been deprecated and/or replaced so they had to be removed, but we also add a bunch of new linters. Some of them found new violations that we had to address. The most visible change is the reformatting of the copyright notice, required (I guess) when the golangci-lint release binary started being built with 1.19 or whenever the formatting of indented blocks changed. There are definitely more linters we could enable, but they would require more significant changes to the code.
1 parent 621679c commit 48260bf

21 files changed

+61
-39
lines changed

.golangci.yml

+26-5
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,51 @@ linters:
55
- asciicheck
66
- bidichk
77
- bodyclose
8+
- containedctx
89
- contextcheck
9-
- deadcode
1010
- durationcheck
1111
- errcheck
12+
- errchkjson
1213
- errname
1314
- errorlint
15+
- exhaustive
1416
- exportloopref
15-
- forcetypeassert
17+
- gocheckcompilerdirectives
1618
- gocyclo
1719
- godot
18-
- gofmt
20+
- gofumpt
1921
- gosec
2022
- gosimple
23+
- gosmopolitan
2124
- govet
22-
- ifshort
25+
- importas
2326
- ineffassign
27+
- makezero
28+
- mirror
2429
- misspell
30+
- nilerr
31+
- nilnil
32+
- noctx
33+
- nosprintfhostport
34+
- predeclared
35+
- reassign
36+
- revive
2537
- staticcheck
38+
- tenv
39+
- testableexamples
2640
- typecheck
2741
- unconvert
2842
- unused
29-
- varcheck
43+
- usestdlibvars
3044
- wastedassign
3145
- whitespace
3246
linters-settings:
3347
misspell:
3448
locale: US
49+
usestdlibvars:
50+
crypto-hash: true
51+
http-method: false
52+
os-dev-null: true
53+
sql-isolation-level: true
54+
time-layout: true
55+
tls-signature-scheme: true

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ GOVVV = $(GOBIN)/govvv
1414
MOCKGEN = $(GOBIN)/mockgen
1515
PIGEON = $(GOBIN)/pigeon
1616

17-
GOLANGCI_LINT_VERSION := v1.43.0
18-
GOLANGCI_LINT_INSTALLATION_SHA256 := 294771225087ee48c8e0a45a99ac82ed8f9c6e9d384e692ab201986479c8594f
19-
GOLANGCI_LINT_BINARY_SHA256 := c6f662fd533a7bff89c2d554dbe0708b6d3925f4b305d3522591d6bca0b48469
17+
GOLANGCI_LINT_VERSION := v1.53.3
18+
GOLANGCI_LINT_INSTALLATION_SHA256 := 060f1f3deb31b3d3b9515d691d9a776354cd63c7fcb5e036f18f0444cf2c934b
19+
GOLANGCI_LINT_BINARY_SHA256 := 09237052ea9582630019182e890288ec155567fc949e6f329e3beb2c6e76b1b5
2020

2121
.PHONY: all
2222
all: test build start

cmd/goer/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,

internal/config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,

internal/config/config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,

internal/database/database.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,

internal/database/database_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,

internal/database/drivers/drivers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,

internal/database/drivers/mongodb/mongodb.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -180,7 +180,6 @@ func (m *Database) GetEvents(ctx context.Context, request requests.MultipleEvent
180180
SetSkip(int64((request.PageNo-1)*request.PageSize)).
181181
SetLimit(int64(limit)),
182182
)
183-
184183
if err != nil {
185184
continue
186185
}
@@ -201,7 +200,7 @@ func (m *Database) GetEvents(ctx context.Context, request requests.MultipleEvent
201200
}
202201

203202
// UpstreamDownstreamSearch searches for events upstream and/or downstream of event by ID.
204-
func (m *Database) UpstreamDownstreamSearch(ctx context.Context, id string) ([]drivers.EiffelEvent, error) {
203+
func (m *Database) UpstreamDownstreamSearch(_ context.Context, _ string) ([]drivers.EiffelEvent, error) {
205204
return nil, errors.New("not yet implemented")
206205
}
207206

@@ -220,9 +219,8 @@ func (m *Database) GetEventByID(ctx context.Context, id string) (drivers.EiffelE
220219
err := singleResult.Decode(&event)
221220
if err != nil {
222221
continue
223-
} else {
224-
return drivers.EiffelEvent(event), nil
225222
}
223+
return drivers.EiffelEvent(event), nil
226224
}
227225
return nil, fmt.Errorf("%q not found in any collection", id)
228226
}

internal/logger/logger.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,

internal/responses/responses.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -22,7 +22,7 @@ import (
2222

2323
// RespondWithJSON writes a JSON response with a status code to the HTTP ResponseWriter.
2424
func RespondWithJSON(w http.ResponseWriter, code int, payload interface{}) {
25-
response, _ := json.Marshal(payload)
25+
response, _ := json.Marshal(payload) //nolint:errchkjson
2626

2727
w.Header().Set("Content-Type", "application/json")
2828
w.WriteHeader(code)

internal/responses/responses_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -27,14 +27,14 @@ func TestRespondWithJSON(t *testing.T) {
2727
responseRecorder := httptest.NewRecorder()
2828
RespondWithJSON(responseRecorder, 200, map[string]string{"hello": "world"})
2929
assert.Equal(t, "application/json", responseRecorder.Header().Get("Content-Type"))
30-
assert.Equal(t, 200, responseRecorder.Result().StatusCode)
30+
assert.Equal(t, 200, responseRecorder.Result().StatusCode) //nolint:bodyclose
3131
assert.JSONEq(t, `{"hello": "world"}`, responseRecorder.Body.String())
3232
}
3333

3434
// Test that RespondWithError writes the correct HTTP code, message and adds a content type header.
3535
func TestRespondWithError(t *testing.T) {
3636
responseRecorder := httptest.NewRecorder()
3737
RespondWithError(responseRecorder, 400, "Bad Request")
38-
assert.Equal(t, 400, responseRecorder.Result().StatusCode)
38+
assert.Equal(t, 400, responseRecorder.Result().StatusCode) //nolint:bodyclose
3939
assert.Equal(t, "Bad Request", responseRecorder.Body.String())
4040
}

pkg/application/application.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,

pkg/application/application_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,

pkg/server/server.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -19,6 +19,7 @@ import (
1919
"errors"
2020
"log"
2121
"net/http"
22+
"time"
2223

2324
"github.com/gorilla/mux"
2425
)
@@ -44,7 +45,9 @@ type WebServer struct {
4445
// Create a new WebServer.
4546
func Get() Server {
4647
return &WebServer{
47-
server: &http.Server{},
48+
server: &http.Server{
49+
ReadTimeout: 10 * time.Second,
50+
},
4851
running: make(chan bool, 2), // Buffer up to two messages.
4952
stopped: make(chan bool, 2), // Buffer up to two messages.
5053
}

pkg/server/server_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,

pkg/v1/api/api.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,

pkg/v1/handlers/events/events.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,

pkg/v1/handlers/events/events_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,

pkg/v1/handlers/search/search.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -25,21 +25,21 @@ import (
2525
"github.com/eiffel-community/eiffel-goer/internal/responses"
2626
)
2727

28-
type SearchHandler struct {
28+
type Handler struct {
2929
Config config.Config
3030
Database drivers.Database
3131
Logger *log.Entry
3232
}
3333

3434
// Get a new handler for the search endpoint.
35-
func Get(cfg config.Config, db drivers.Database, logger *log.Entry) *SearchHandler {
36-
return &SearchHandler{
35+
func Get(cfg config.Config, db drivers.Database, logger *log.Entry) *Handler {
36+
return &Handler{
3737
cfg, db, logger,
3838
}
3939
}
4040

4141
// UpstreamDownstream handles POST requests against the /search/{id} endpoint.
4242
// To get upstream/downstream events for an event based on the searchParameters passed.
43-
func (h *SearchHandler) UpstreamDownstream(w http.ResponseWriter, r *http.Request) {
43+
func (h *Handler) UpstreamDownstream(w http.ResponseWriter, _ *http.Request) {
4444
responses.RespondWithError(w, http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
4545
}

pkg/v1/handlers/search/test_search.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// you may not use this file except in compliance with the License.
77
// You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,

0 commit comments

Comments
 (0)