Skip to content

Commit 6c4c6f7

Browse files
richvdhS7evinK
andauthored
Update linter config (#442)
A bunch of changes to get the linter (and CI in general) passing again. Review commit-by-commit for details of the changes. --------- Co-authored-by: Till <[email protected]>
1 parent be8877e commit 6c4c6f7

File tree

7 files changed

+21
-29
lines changed

7 files changed

+21
-29
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
strategy:
8484
fail-fast: false
8585
matrix:
86-
go: ["1.20", "1.21"]
86+
go: ["1.21"]
8787
steps:
8888
- uses: actions/checkout@v3
8989
with:

.golangci.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,8 @@ run:
22
timeout: 5m
33
linters:
44
enable:
5-
- vet
6-
- vetshadow
75
- typecheck
8-
- deadcode
96
- gocyclo
10-
- golint
11-
- varcheck
12-
- structcheck
13-
- maligned
147
- ineffassign
158
# - gosec - complains about weak cryptographic primitive sha1 and TLS InsecureSkipVerify set true in getTransport
169
- misspell
@@ -19,5 +12,4 @@ linters:
1912
# - goconst
2013
- unconvert
2114
- errcheck
22-
- interfacer
2315
# - testify - not available in golangci-lint

fclient/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"crypto/tls"
2222
"encoding/json"
2323
"fmt"
24-
"io/ioutil"
24+
"io"
2525
"net"
2626
"net/http"
2727
"net/url"
@@ -350,7 +350,7 @@ func (fc *Client) LookupUserInfo(
350350
}
351351
if response.StatusCode < 200 || response.StatusCode >= 300 {
352352
var errorOutput []byte
353-
errorOutput, err = ioutil.ReadAll(response.Body)
353+
errorOutput, err = io.ReadAll(response.Body)
354354
if err != nil {
355355
return
356356
}
@@ -525,7 +525,7 @@ func (fc *Client) DoRequestAndParseResponse(
525525
if response.StatusCode/100 != 2 { // not 2xx
526526
// Adapted from https://github.com/matrix-org/gomatrix/blob/master/client.go
527527
var contents []byte
528-
contents, err = ioutil.ReadAll(response.Body)
528+
contents, err = io.ReadAll(response.Body)
529529
if err != nil {
530530
return err
531531
}

fclient/federationclient_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"net/http"
1010
"reflect"
1111
"strings"
@@ -63,7 +63,7 @@ func TestSendJoinFallback(t *testing.T) {
6363
if strings.HasPrefix(req.URL.Path, "/_matrix/federation/v2/send_join") {
6464
return &http.Response{
6565
StatusCode: 404,
66-
Body: ioutil.NopCloser(strings.NewReader("404 not found")),
66+
Body: io.NopCloser(strings.NewReader("404 not found")),
6767
}, nil
6868
}
6969
if !strings.HasPrefix(req.URL.Path, "/_matrix/federation/v1/send_join") {
@@ -72,7 +72,7 @@ func TestSendJoinFallback(t *testing.T) {
7272
t.Logf("Sending response: %s", string(v1ResBytes))
7373
return &http.Response{
7474
StatusCode: 200,
75-
Body: ioutil.NopCloser(bytes.NewReader(v1ResBytes)),
75+
Body: io.NopCloser(bytes.NewReader(v1ResBytes)),
7676
}, nil
7777
},
7878
},
@@ -126,12 +126,12 @@ func TestSendJoinJSON(t *testing.T) {
126126
t.Logf("Sending response: %s", string(respSendJoinResponseJSON))
127127
return &http.Response{
128128
StatusCode: 200,
129-
Body: ioutil.NopCloser(bytes.NewReader(respSendJoinResponseJSON)),
129+
Body: io.NopCloser(bytes.NewReader(respSendJoinResponseJSON)),
130130
}, nil
131131
}
132132
return &http.Response{
133133
StatusCode: 404,
134-
Body: ioutil.NopCloser(strings.NewReader("404 not found")),
134+
Body: io.NopCloser(strings.NewReader("404 not found")),
135135
}, nil
136136
},
137137
},
@@ -185,12 +185,12 @@ func TestSendTransactionToRelay(t *testing.T) {
185185
if strings.HasPrefix(req.URL.Path, "/_matrix/federation/v1/send_relay") {
186186
return &http.Response{
187187
StatusCode: 200,
188-
Body: ioutil.NopCloser(bytes.NewReader(respSendResponseJSON)),
188+
Body: io.NopCloser(bytes.NewReader(respSendResponseJSON)),
189189
}, nil
190190
}
191191
return &http.Response{
192192
StatusCode: 404,
193-
Body: ioutil.NopCloser(strings.NewReader("404 not found")),
193+
Body: io.NopCloser(strings.NewReader("404 not found")),
194194
}, nil
195195
},
196196
},
@@ -232,12 +232,12 @@ func TestSendTransactionToRelayReportsFailure(t *testing.T) {
232232
if strings.HasPrefix(req.URL.Path, "/_matrix/federation/v1/send_relay") {
233233
return &http.Response{
234234
StatusCode: 400,
235-
Body: ioutil.NopCloser(bytes.NewReader(respSendResponseJSON)),
235+
Body: io.NopCloser(bytes.NewReader(respSendResponseJSON)),
236236
}, nil
237237
}
238238
return &http.Response{
239239
StatusCode: 404,
240-
Body: ioutil.NopCloser(strings.NewReader("404 not found")),
240+
Body: io.NopCloser(strings.NewReader("404 not found")),
241241
}, nil
242242
},
243243
},

fclient/request.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8-
"io/ioutil"
98
"mime"
109
"net/http"
1110
"strings"
@@ -183,7 +182,7 @@ func isSafeInHTTPQuotedString(text string) bool { // nolint: gocyclo
183182
continue
184183
case 0x5D <= c && c <= 0x7E:
185184
continue
186-
case 0x80 <= c && c <= 0xFF:
185+
case 0x80 <= c:
187186
continue
188187
default:
189188
return false
@@ -274,7 +273,7 @@ func readHTTPRequest(req *http.Request) (*FederationRequest, error) { // nolint:
274273
result.fields.Method = req.Method
275274
result.fields.RequestURI = req.URL.RequestURI()
276275

277-
content, err := ioutil.ReadAll(req.Body)
276+
content, err := io.ReadAll(req.Body)
278277
if err != nil {
279278
return nil, err
280279
}

spec/matrixerror.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package spec
1616

1717
import (
18+
"errors"
1819
"fmt"
1920
)
2021

@@ -63,7 +64,7 @@ func (e MatrixError) Error() string {
6364
}
6465

6566
func (e MatrixError) Unwrap() error {
66-
return fmt.Errorf(e.Err)
67+
return errors.New(e.Err)
6768
}
6869

6970
// InternalServerError
@@ -231,7 +232,7 @@ func (e IncompatibleRoomVersionError) Error() string {
231232
}
232233

233234
func (e IncompatibleRoomVersionError) Unwrap() error {
234-
return fmt.Errorf(e.Err)
235+
return errors.New(e.Err)
235236
}
236237

237238
// IncompatibleRoomVersion is an error which is returned when the client

tokens/tokens_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ func serializationTestError(err error) string {
6161
func TestSerialization(t *testing.T) {
6262
fakeToken, err := GenerateLoginToken(validTokenOp)
6363
if err != nil {
64-
t.Errorf(serializationTestError(err))
64+
t.Errorf("%s", serializationTestError(err))
6565
}
6666

6767
fakeMacaroon, err := deSerializeMacaroon(fakeToken)
6868
if err != nil {
69-
t.Errorf(serializationTestError(err))
69+
t.Errorf("%s", serializationTestError(err))
7070
}
7171

7272
sameFakeToken, err := serializeMacaroon(fakeMacaroon)
7373
if err != nil {
74-
t.Errorf(serializationTestError(err))
74+
t.Errorf("%s", serializationTestError(err))
7575
}
7676

7777
if sameFakeToken != fakeToken {

0 commit comments

Comments
 (0)