Skip to content

Commit

Permalink
add the stylecheck linter
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Sep 17, 2019
1 parent ab2b26a commit 6b22f36
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 20 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ linters:
- prealloc
- scopelint
- staticcheck
- stylecheck
- structcheck
- unconvert
- unparam
Expand Down
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ func (c *client) handleVersionNegotiationPacket(p *receivedPacket) {
c.logger.Infof("Received a Version Negotiation packet. Supported Versions: %s", hdr.SupportedVersions)
newVersion, ok := protocol.ChooseSupportedVersion(c.config.Versions, hdr.SupportedVersions)
if !ok {
//nolint:stylecheck
c.session.destroy(fmt.Errorf("No compatible QUIC version found. We support %s, server offered %s", c.config.Versions, hdr.SupportedVersions))
c.logger.Debugf("No compatible QUIC version found.")
return
Expand Down
4 changes: 2 additions & 2 deletions frame_sorter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type frameSorter struct {
gaps *utils.ByteIntervalList
}

var errDuplicateStreamData = errors.New("Duplicate Stream Data")
var errDuplicateStreamData = errors.New("duplicate stream data")

func newFrameSorter() *frameSorter {
s := frameSorter{
Expand Down Expand Up @@ -146,7 +146,7 @@ func (s *frameSorter) push(data []byte, offset protocol.ByteCount, doneCb func()
}

if s.gaps.Len() > protocol.MaxStreamFrameSorterGaps {
return errors.New("Too many gaps in received data")
return errors.New("too many gaps in received data")
}

if wasCut && len(data) < protocol.MinStreamFrameBufferSize {
Expand Down
2 changes: 1 addition & 1 deletion frame_sorter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ var _ = Describe("frame sorter", func() {
}
Expect(s.gaps.Len()).To(Equal(protocol.MaxStreamFrameSorterGaps))
err := s.Push([]byte("foobar"), protocol.ByteCount(protocol.MaxStreamFrameSorterGaps*7)+100, nil)
Expect(err).To(MatchError("Too many gaps in received data"))
Expect(err).To(MatchError("too many gaps in received data"))
})
})
})
Expand Down
12 changes: 6 additions & 6 deletions integrationtests/self/cancelation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var _ = Describe("Stream Cancelations", func() {
str, err := sess.OpenUniStreamSync(context.Background())
Expect(err).ToNot(HaveOccurred())
if _, err = str.Write(testserver.PRData); err != nil {
Expect(err).To(MatchError(fmt.Sprintf("Stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
atomic.AddInt32(&canceledCounter, 1)
return
}
Expand Down Expand Up @@ -174,7 +174,7 @@ var _ = Describe("Stream Cancelations", func() {
data, err := ioutil.ReadAll(str)
if err != nil {
atomic.AddInt32(&counter, 1)
Expect(err).To(MatchError(fmt.Sprintf("Stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
return
}
Expect(data).To(Equal(testserver.PRData))
Expand Down Expand Up @@ -281,7 +281,7 @@ var _ = Describe("Stream Cancelations", func() {
return
}
if _, err = str.Write(testserver.PRData); err != nil {
Expect(err).To(MatchError(fmt.Sprintf("Stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
return
}
Expect(str.Close()).To(Succeed())
Expand Down Expand Up @@ -314,7 +314,7 @@ var _ = Describe("Stream Cancelations", func() {
}
data, err := ioutil.ReadAll(str)
if err != nil {
Expect(err).To(MatchError(fmt.Sprintf("Stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
return
}
atomic.AddInt32(&counter, 1)
Expand Down Expand Up @@ -355,7 +355,7 @@ var _ = Describe("Stream Cancelations", func() {
length = int(rand.Int31n(int32(len(testserver.PRData) - 1)))
}
if _, err = str.Write(testserver.PRData[:length]); err != nil {
Expect(err).To(MatchError(fmt.Sprintf("Stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
return
}
if length < len(testserver.PRData) {
Expand Down Expand Up @@ -396,7 +396,7 @@ var _ = Describe("Stream Cancelations", func() {
}
data, err := ioutil.ReadAll(r)
if err != nil {
Expect(err).To(MatchError(fmt.Sprintf("Stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
Expect(err).To(MatchError(fmt.Sprintf("stream %d was reset with error code %d", str.StreamID(), str.StreamID())))
return
}
Expect(data).To(Equal(testserver.PRData[:length]))
Expand Down
2 changes: 2 additions & 0 deletions integrationtests/tools/testlog/testlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (

"github.com/lucas-clemente/quic-go/internal/utils"

//nolint:stylecheck
. "github.com/onsi/ginkgo"
//nolint:stylecheck
. "github.com/onsi/gomega"
)

Expand Down
2 changes: 2 additions & 0 deletions integrationtests/tools/testserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/testdata"

//nolint:stylecheck
. "github.com/onsi/ginkgo"
//nolint:stylecheck
. "github.com/onsi/gomega"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/handshake/token_protector.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *tokenProtectorImpl) NewToken(data []byte) ([]byte, error) {
// DecodeToken decodes a token.
func (s *tokenProtectorImpl) DecodeToken(p []byte) ([]byte, error) {
if len(p) < tokenNonceSize {
return nil, fmt.Errorf("Token too short: %d", len(p))
return nil, fmt.Errorf("token too short: %d", len(p))
}
nonce := p[:tokenNonceSize]
aead, aeadNonce, err := s.createAEAD(nonce)
Expand Down
2 changes: 1 addition & 1 deletion internal/handshake/token_protector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ var _ = Describe("Token Protector", func() {

It("errors when decoding too short tokens", func() {
_, err := tp.DecodeToken([]byte("foobar"))
Expect(err).To(MatchError("Token too short: 6"))
Expect(err).To(MatchError("token too short: 6"))
})
})
2 changes: 2 additions & 0 deletions internal/wire/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,11 @@ func (h *Header) parseLongHeader(b *bytes.Reader) error {

func (h *Header) parseVersionNegotiationPacket(b *bytes.Reader) error {
if b.Len() == 0 {
//nolint:stylecheck
return errors.New("Version Negotiation packet has empty version list")
}
if b.Len()%4 != 0 {
//nolint:stylecheck
return errors.New("Version Negotiation packet has a version list with an invalid length")
}
h.SupportedVersions = make([]protocol.VersionNumber, b.Len()/4)
Expand Down
1 change: 1 addition & 0 deletions internal/wire/new_connection_id_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func parseNewConnectionIDFrame(r *bytes.Reader, _ protocol.VersionNumber) (*NewC
return nil, err
}
if ret > seq {
//nolint:stylecheck
return nil, fmt.Errorf("Retire Prior To value (%d) larger than Sequence Number (%d)", ret, seq)
}
connIDLen, err := r.ReadByte()
Expand Down
2 changes: 1 addition & 1 deletion internal/wire/new_token_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func parseNewTokenFrame(r *bytes.Reader, _ protocol.VersionNumber) (*NewTokenFra
return nil, io.EOF
}
if tokenLen == 0 {
return nil, errors.New("Token must not be empty.")
return nil, errors.New("token must not be empty")
}
token := make([]byte, int(tokenLen))
if _, err := io.ReadFull(r, token); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/wire/new_token_frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var _ = Describe("NEW_TOKEN frame", func() {
data = append(data, encodeVarInt(uint64(0))...)
b := bytes.NewReader(data)
_, err := parseNewTokenFrame(b, protocol.VersionWhatever)
Expect(err).To(MatchError("Token must not be empty."))
Expect(err).To(MatchError("token must not be empty"))
})

It("errors on EOFs", func() {
Expand Down
1 change: 1 addition & 0 deletions packet_unpacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (u *packetUnpacker) unpack(hd headerDecryptor, hdr *wire.Header, data []byt

hdrLen := int(hdr.ParsedLen())
if len(data) < hdrLen+4+16 {
//nolint:stylecheck
return nil, fmt.Errorf("Packet too small. Expected at least 20 bytes after the header, got %d", len(data)-hdrLen)
}
// The packet number can be up to 4 bytes long, but we won't know the length until we decrypt it.
Expand Down
2 changes: 1 addition & 1 deletion quictrace/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (t *tracer) Emit(connID protocol.ConnectionID) ([]byte, error) {
func (t *tracer) emitByConnIDAsString(connID string) ([]byte, error) {
events, ok := t.events[connID]
if !ok {
return nil, fmt.Errorf("No trace found for connection ID %s", connID)
return nil, fmt.Errorf("no trace found for connection ID %s", connID)
}
trace := &pb.Trace{
DestinationConnectionId: []byte{1, 2, 3, 4, 5, 6, 7, 8},
Expand Down
2 changes: 1 addition & 1 deletion receive_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (s *receiveStream) handleResetStreamFrameImpl(frame *wire.ResetStreamFrame)
s.resetRemotely = true
s.resetRemotelyErr = streamCanceledError{
errorCode: frame.ErrorCode,
error: fmt.Errorf("Stream %d was reset with error code %d", s.streamID, frame.ErrorCode),
error: fmt.Errorf("stream %d was reset with error code %d", s.streamID, frame.ErrorCode),
}
s.signalRead()
return true, nil
Expand Down
4 changes: 2 additions & 2 deletions receive_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ var _ = Describe("Receive Stream", func() {
go func() {
defer GinkgoRecover()
_, err := strWithTimeout.Read([]byte{0})
Expect(err).To(MatchError("Stream 1337 was reset with error code 1234"))
Expect(err).To(MatchError("stream 1337 was reset with error code 1234"))
Expect(err).To(BeAssignableToTypeOf(streamCanceledError{}))
Expect(err.(streamCanceledError).Canceled()).To(BeTrue())
Expect(err.(streamCanceledError).ErrorCode()).To(Equal(protocol.ApplicationErrorCode(1234)))
Expand All @@ -576,7 +576,7 @@ var _ = Describe("Receive Stream", func() {
)
Expect(str.handleResetStreamFrame(rst)).To(Succeed())
_, err := strWithTimeout.Read([]byte{0})
Expect(err).To(MatchError("Stream 1337 was reset with error code 1234"))
Expect(err).To(MatchError("stream 1337 was reset with error code 1234"))
Expect(err).To(BeAssignableToTypeOf(streamCanceledError{}))
Expect(err.(streamCanceledError).Canceled()).To(BeTrue())
Expect(err.(streamCanceledError).ErrorCode()).To(Equal(protocol.ApplicationErrorCode(1234)))
Expand Down
2 changes: 1 addition & 1 deletion send_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func (s *sendStream) handleMaxStreamDataFrame(frame *wire.MaxStreamDataFrame) {
func (s *sendStream) handleStopSendingFrame(frame *wire.StopSendingFrame) {
writeErr := streamCanceledError{
errorCode: frame.ErrorCode,
error: fmt.Errorf("Stream %d was reset with error code %d", s.streamID, frame.ErrorCode),
error: fmt.Errorf("stream %d was reset with error code %d", s.streamID, frame.ErrorCode),
}
s.cancelWriteImpl(frame.ErrorCode, writeErr)
}
Expand Down
4 changes: 2 additions & 2 deletions send_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ var _ = Describe("Send Stream", func() {
go func() {
defer GinkgoRecover()
_, err := str.Write([]byte("foobar"))
Expect(err).To(MatchError("Stream 1337 was reset with error code 123"))
Expect(err).To(MatchError("stream 1337 was reset with error code 123"))
Expect(err).To(BeAssignableToTypeOf(streamCanceledError{}))
Expect(err.(streamCanceledError).Canceled()).To(BeTrue())
Expect(err.(streamCanceledError).ErrorCode()).To(Equal(protocol.ApplicationErrorCode(123)))
Expand All @@ -663,7 +663,7 @@ var _ = Describe("Send Stream", func() {
ErrorCode: 123,
})
_, err := str.Write([]byte("foobar"))
Expect(err).To(MatchError("Stream 1337 was reset with error code 123"))
Expect(err).To(MatchError("stream 1337 was reset with error code 123"))
Expect(err).To(BeAssignableToTypeOf(streamCanceledError{}))
Expect(err.(streamCanceledError).Canceled()).To(BeTrue())
Expect(err.(streamCanceledError).ErrorCode()).To(Equal(protocol.ApplicationErrorCode(123)))
Expand Down

0 comments on commit 6b22f36

Please sign in to comment.