Skip to content

Commit

Permalink
Update linter config (#442)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
richvdh and S7evinK authored Nov 6, 2024
1 parent be8877e commit 6c4c6f7
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ["1.20", "1.21"]
go: ["1.21"]
steps:
- uses: actions/checkout@v3
with:
Expand Down
8 changes: 0 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@ run:
timeout: 5m
linters:
enable:
- vet
- vetshadow
- typecheck
- deadcode
- gocyclo
- golint
- varcheck
- structcheck
- maligned
- ineffassign
# - gosec - complains about weak cryptographic primitive sha1 and TLS InsecureSkipVerify set true in getTransport
- misspell
Expand All @@ -19,5 +12,4 @@ linters:
# - goconst
- unconvert
- errcheck
- interfacer
# - testify - not available in golangci-lint
6 changes: 3 additions & 3 deletions fclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -350,7 +350,7 @@ func (fc *Client) LookupUserInfo(
}
if response.StatusCode < 200 || response.StatusCode >= 300 {
var errorOutput []byte
errorOutput, err = ioutil.ReadAll(response.Body)
errorOutput, err = io.ReadAll(response.Body)
if err != nil {
return
}
Expand Down Expand Up @@ -525,7 +525,7 @@ func (fc *Client) DoRequestAndParseResponse(
if response.StatusCode/100 != 2 { // not 2xx
// Adapted from https://github.com/matrix-org/gomatrix/blob/master/client.go
var contents []byte
contents, err = ioutil.ReadAll(response.Body)
contents, err = io.ReadAll(response.Body)
if err != nil {
return err
}
Expand Down
18 changes: 9 additions & 9 deletions fclient/federationclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"reflect"
"strings"
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestSendJoinFallback(t *testing.T) {
if strings.HasPrefix(req.URL.Path, "/_matrix/federation/v2/send_join") {
return &http.Response{
StatusCode: 404,
Body: ioutil.NopCloser(strings.NewReader("404 not found")),
Body: io.NopCloser(strings.NewReader("404 not found")),
}, nil
}
if !strings.HasPrefix(req.URL.Path, "/_matrix/federation/v1/send_join") {
Expand All @@ -72,7 +72,7 @@ func TestSendJoinFallback(t *testing.T) {
t.Logf("Sending response: %s", string(v1ResBytes))
return &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewReader(v1ResBytes)),
Body: io.NopCloser(bytes.NewReader(v1ResBytes)),
}, nil
},
},
Expand Down Expand Up @@ -126,12 +126,12 @@ func TestSendJoinJSON(t *testing.T) {
t.Logf("Sending response: %s", string(respSendJoinResponseJSON))
return &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewReader(respSendJoinResponseJSON)),
Body: io.NopCloser(bytes.NewReader(respSendJoinResponseJSON)),
}, nil
}
return &http.Response{
StatusCode: 404,
Body: ioutil.NopCloser(strings.NewReader("404 not found")),
Body: io.NopCloser(strings.NewReader("404 not found")),
}, nil
},
},
Expand Down Expand Up @@ -185,12 +185,12 @@ func TestSendTransactionToRelay(t *testing.T) {
if strings.HasPrefix(req.URL.Path, "/_matrix/federation/v1/send_relay") {
return &http.Response{
StatusCode: 200,
Body: ioutil.NopCloser(bytes.NewReader(respSendResponseJSON)),
Body: io.NopCloser(bytes.NewReader(respSendResponseJSON)),
}, nil
}
return &http.Response{
StatusCode: 404,
Body: ioutil.NopCloser(strings.NewReader("404 not found")),
Body: io.NopCloser(strings.NewReader("404 not found")),
}, nil
},
},
Expand Down Expand Up @@ -232,12 +232,12 @@ func TestSendTransactionToRelayReportsFailure(t *testing.T) {
if strings.HasPrefix(req.URL.Path, "/_matrix/federation/v1/send_relay") {
return &http.Response{
StatusCode: 400,
Body: ioutil.NopCloser(bytes.NewReader(respSendResponseJSON)),
Body: io.NopCloser(bytes.NewReader(respSendResponseJSON)),
}, nil
}
return &http.Response{
StatusCode: 404,
Body: ioutil.NopCloser(strings.NewReader("404 not found")),
Body: io.NopCloser(strings.NewReader("404 not found")),
}, nil
},
},
Expand Down
5 changes: 2 additions & 3 deletions fclient/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"mime"
"net/http"
"strings"
Expand Down Expand Up @@ -183,7 +182,7 @@ func isSafeInHTTPQuotedString(text string) bool { // nolint: gocyclo
continue
case 0x5D <= c && c <= 0x7E:
continue
case 0x80 <= c && c <= 0xFF:
case 0x80 <= c:
continue
default:
return false
Expand Down Expand Up @@ -274,7 +273,7 @@ func readHTTPRequest(req *http.Request) (*FederationRequest, error) { // nolint:
result.fields.Method = req.Method
result.fields.RequestURI = req.URL.RequestURI()

content, err := ioutil.ReadAll(req.Body)
content, err := io.ReadAll(req.Body)
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions spec/matrixerror.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package spec

import (
"errors"
"fmt"
)

Expand Down Expand Up @@ -63,7 +64,7 @@ func (e MatrixError) Error() string {
}

func (e MatrixError) Unwrap() error {
return fmt.Errorf(e.Err)
return errors.New(e.Err)
}

// InternalServerError
Expand Down Expand Up @@ -231,7 +232,7 @@ func (e IncompatibleRoomVersionError) Error() string {
}

func (e IncompatibleRoomVersionError) Unwrap() error {
return fmt.Errorf(e.Err)
return errors.New(e.Err)
}

// IncompatibleRoomVersion is an error which is returned when the client
Expand Down
6 changes: 3 additions & 3 deletions tokens/tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ func serializationTestError(err error) string {
func TestSerialization(t *testing.T) {
fakeToken, err := GenerateLoginToken(validTokenOp)
if err != nil {
t.Errorf(serializationTestError(err))
t.Errorf("%s", serializationTestError(err))
}

fakeMacaroon, err := deSerializeMacaroon(fakeToken)
if err != nil {
t.Errorf(serializationTestError(err))
t.Errorf("%s", serializationTestError(err))
}

sameFakeToken, err := serializeMacaroon(fakeMacaroon)
if err != nil {
t.Errorf(serializationTestError(err))
t.Errorf("%s", serializationTestError(err))
}

if sameFakeToken != fakeToken {
Expand Down

0 comments on commit 6c4c6f7

Please sign in to comment.