Other: Update golangci-lint to v1.50.0

This commit is contained in:
Leander Beernaert
2022-10-17 11:02:56 +02:00
parent e0603f741f
commit 9d800324af
70 changed files with 247 additions and 277 deletions

View File

@ -18,7 +18,6 @@
package files
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -93,7 +92,7 @@ func TestRemoveWithExceptions(t *testing.T) {
}
func newTestDir(t *testing.T, subdirs ...string) string {
dir, err := ioutil.TempDir("", "test-files-dir")
dir, err := os.MkdirTemp("", "test-files-dir")
require.NoError(t, err)
for _, target := range subdirs {

View File

@ -20,7 +20,6 @@ package message
import (
"context"
"io"
"io/ioutil"
"sync"
"github.com/ProtonMail/gopenpgp/v2/crypto"
@ -52,8 +51,8 @@ type Fetcher interface {
}
// NewBuilder creates a new builder which manages the given number of fetch/attach/build workers.
// - fetchWorkers: the number of workers which fetch messages from API
// - attachWorkers: the number of workers which fetch attachments from API.
// - fetchWorkers: the number of workers which fetch messages from API
// - attachWorkers: the number of workers which fetch attachments from API.
//
// The returned builder is ready to handle jobs -- see (*Builder).NewJob for more information.
//
@ -167,7 +166,7 @@ func newAttacherWorkFunc() pool.WorkFunc {
return nil, err
}
b, err := ioutil.ReadAll(rc)
b, err := io.ReadAll(rc)
if err != nil {
return nil, err
}
@ -209,7 +208,7 @@ func newFetcherWorkFunc(attachmentPool *pool.Pool) pool.WorkFunc {
return nil, err
}
b, err := ioutil.ReadAll(rc)
b, err := io.ReadAll(rc)
if err != nil {
_ = rc.Close()
return nil, err

View File

@ -21,7 +21,6 @@ import (
"bytes"
"encoding/base64"
"io"
"io/ioutil"
"mime"
"mime/multipart"
"net/http"
@ -83,7 +82,7 @@ func BuildEncrypted(m *pmapi.Message, readers []io.Reader, kr *crypto.KeyRing) (
return nil, err
}
data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return nil, err
}

View File

@ -21,7 +21,6 @@ import (
"bytes"
"encoding/base64"
"io"
"io/ioutil"
"mime"
"mime/quotedprintable"
"strings"
@ -33,7 +32,7 @@ import (
)
func EncryptRFC822(kr *crypto.KeyRing, r io.Reader) ([]byte, error) {
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return nil, err
}
@ -118,7 +117,7 @@ func writeEncryptedPart(kr *crypto.KeyRing, header *textproto.Header, r io.Reade
}
func writeEncryptedTextPart(w io.Writer, r io.Reader, kr *crypto.KeyRing) error {
dec, err := ioutil.ReadAll(r)
dec, err := io.ReadAll(r)
if err != nil {
return err
}
@ -146,7 +145,7 @@ func writeEncryptedTextPart(w io.Writer, r io.Reader, kr *crypto.KeyRing) error
}
func writeEncryptedAttachmentPart(w io.Writer, r io.Reader, kr *crypto.KeyRing) error {
dec, err := ioutil.ReadAll(r)
dec, err := io.ReadAll(r)
if err != nil {
return err
}

View File

@ -19,7 +19,7 @@ package message
import (
"bytes"
"io/ioutil"
"os"
"testing"
"github.com/ProtonMail/gopenpgp/v2/crypto"
@ -27,7 +27,7 @@ import (
)
func TestEncryptRFC822(t *testing.T) {
literal, err := ioutil.ReadFile("testdata/text_plain_latin1.eml")
literal, err := os.ReadFile("testdata/text_plain_latin1.eml")
require.NoError(t, err)
key, err := crypto.GenerateKey("name", "email", "rsa", 2048)
@ -46,7 +46,7 @@ func TestEncryptRFC822(t *testing.T) {
}
func TestEncryptRFC822Multipart(t *testing.T) {
literal, err := ioutil.ReadFile("testdata/multipart_alternative_nested.eml")
literal, err := os.ReadFile("testdata/multipart_alternative_nested.eml")
require.NoError(t, err)
key, err := crypto.GenerateKey("name", "email", "rsa", 2048)

View File

@ -21,7 +21,6 @@ import (
"bufio"
"bytes"
"io"
"io/ioutil"
"unicode"
"github.com/emersion/go-message/textproto"
@ -141,7 +140,7 @@ func splitHeaderBody(b []byte) ([]byte, []byte, error) {
}
}
body, err := ioutil.ReadAll(br)
body, err := io.ReadAll(br)
if err != nil && !errors.Is(err, io.EOF) {
return nil, nil, err
}

View File

@ -215,8 +215,8 @@ func collectAttachments(p *parser.Parser) ([]*pmapi.Attachment, []io.Reader, err
}
// buildBodies collects all text/html and text/plain parts and returns two bodies,
// - a rich text body (in which html is allowed), and
// - a plaintext body (in which html is converted to plaintext).
// - a rich text body (in which html is allowed), and
// - a plaintext body (in which html is converted to plaintext).
//
// text/html parts are converted to plaintext in order to build the plaintext body,
// unless there is already a plaintext part provided via multipart/alternative,

View File

@ -19,7 +19,6 @@ package parser
import (
"io"
"io/ioutil"
"github.com/emersion/go-message"
"github.com/sirupsen/logrus"
@ -129,7 +128,7 @@ func (p *Parser) parseEntity(e *message.Entity) error {
}
func (p *Parser) parsePart(e *message.Entity) (err error) {
bytes, err := ioutil.ReadAll(e.Body)
bytes, err := io.ReadAll(e.Body)
if err != nil {
return
}

View File

@ -19,7 +19,6 @@ package parser
import (
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -44,7 +43,7 @@ func getFileReader(filename string) io.ReadCloser {
}
func getFileAsString(filename string) string {
b, err := ioutil.ReadAll(getFileReader(filename))
b, err := io.ReadAll(getFileReader(filename))
if err != nil {
panic(err)
}

View File

@ -20,7 +20,6 @@ package message
import (
"image/png"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -603,7 +602,7 @@ func getFileReader(filename string) io.Reader {
}
func readerToString(r io.Reader) string {
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
panic(err)
}

View File

@ -21,7 +21,6 @@ import (
"bufio"
"bytes"
"io"
"io/ioutil"
"net/textproto"
"strconv"
"strings"
@ -166,7 +165,7 @@ func (bs *BodyStructure) parseAllChildSections(r io.Reader, currentPath []int, s
}
} else {
// Count length.
_, _ = bodyReader.WriteTo(ioutil.Discard)
_, _ = bodyReader.WriteTo(io.Discard)
}
// Clear all buffers.

View File

@ -20,7 +20,7 @@ package message
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"sort"
@ -93,7 +93,7 @@ func TestParseBodyStructurePGP(t *testing.T) {
"2": "application/pgp-signature; name=\"OpenPGP_signature.asc\"",
}
b, err := ioutil.ReadFile("testdata/enc-body-structure.eml")
b, err := os.ReadFile("testdata/enc-body-structure.eml")
require.NoError(t, err)
bs, err := NewBodyStructure(bytes.NewReader(b))

View File

@ -24,7 +24,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"net/textproto"
@ -114,7 +113,7 @@ func TestClient_CreateAttachment(t *testing.T) {
r.NoError(err)
defer r.NoError(dataFile.Close())
b, err := ioutil.ReadAll(dataFile)
b, err := io.ReadAll(dataFile)
r.NoError(err)
r.Equal(testAttachmentCleartext, string(b))
@ -146,7 +145,7 @@ func TestClient_GetAttachment(t *testing.T) {
defer att.Close() //nolint:errcheck
// In reality, r contains encrypted data
b, err := ioutil.ReadAll(att)
b, err := io.ReadAll(att)
r.NoError(err)
r.Equal(testAttachmentCleartext, string(b))
@ -181,7 +180,7 @@ func TestAttachmentEncrypt(t *testing.T) {
func decryptAndCheck(r *require.Assertions, data io.Reader) {
// First separate KeyPacket from encrypted data. In our case keypacket
// has 271 bytes.
raw, err := ioutil.ReadAll(data)
raw, err := io.ReadAll(data)
r.NoError(err)
rawKeyPacket := raw[:271]
rawDataPacket := raw[271:]
@ -195,7 +194,7 @@ func decryptAndCheck(r *require.Assertions, data io.Reader) {
decryptedReader, err := haveAttachment.Decrypt(bytes.NewBuffer(rawDataPacket), testPrivateKeyRing)
r.NoError(err)
b, err := ioutil.ReadAll(decryptedReader)
b, err := io.ReadAll(decryptedReader)
r.NoError(err)
r.Equal(testAttachmentCleartext, string(b))

View File

@ -20,7 +20,7 @@ package pmapi
import (
"bytes"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"strconv"
"time"
@ -139,6 +139,6 @@ func (r tlsReport) sendReport(cfg Config, uri string) {
logrus.WithField("status", http.StatusOK).Error("StatusCode was not OK")
}
_, _ = ioutil.ReadAll(res.Body)
_, _ = io.ReadAll(res.Body)
_ = res.Body.Close()
}

View File

@ -54,10 +54,10 @@ type Event struct {
type EventAction int
const (
EventDelete EventAction = iota // Item has been deleted.
EventCreate // Item has been created.
EventUpdate // Item has been updated.
EventUpdateFlags // For messages: flags have been updated.
EventDelete EventAction = iota // EventDelete Item has been deleted.
EventCreate // EventCreate Item has been created.
EventUpdate // EventUpdate Item has been updated.
EventUpdateFlags // EventUpdateFlags For messages: flags have been updated.
)
// Flags for event refresh.

View File

@ -29,7 +29,7 @@ import (
const (
MaxImportMessageRequestLength = 10
MaxImportMessageRequestSize = 25 * 1024 * 1024 // 25 MB total limit
MaxImportMessageRequestSize = 25 * 1024 * 1024 // MaxImportMessageRequestSize 25 MB total limit
)
type ImportMsgReq struct {

View File

@ -22,7 +22,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"math/rand"
"mime/multipart"
"net/http"
@ -76,7 +75,7 @@ func TestClient_Import(t *testing.T) { //nolint:funlen
r.Equal(t, "form-data", contentDisp)
r.Equal(t, "0", params["name"])
b, err := ioutil.ReadAll(p)
b, err := io.ReadAll(p)
r.NoError(t, err)
r.Equal(t, string(testImportReqs[0].Message), string(b))

View File

@ -22,7 +22,6 @@ import (
"encoding/base64"
"encoding/json"
"io"
"io/ioutil"
"github.com/ProtonMail/gopenpgp/v2/crypto"
"github.com/pkg/errors"
@ -231,7 +230,7 @@ func encryptAttachment(kr *crypto.KeyRing, data io.Reader, filename string) (enc
return nil, err
}
dataBytes, err := ioutil.ReadAll(data)
dataBytes, err := io.ReadAll(data)
if err != nil {
return
}
@ -253,7 +252,7 @@ func decryptAttachment(kr *crypto.KeyRing, keyPackets []byte, data io.Reader) (d
if kr == nil {
return nil, ErrNoKeyringAvailable
}
dataBytes, err := ioutil.ReadAll(data)
dataBytes, err := io.ReadAll(data)
if err != nil {
return
}
@ -269,7 +268,7 @@ func signAttachment(encrypter *crypto.KeyRing, data io.Reader) (signature io.Rea
if encrypter == nil {
return nil, ErrNoKeyringAvailable
}
dataBytes, err := ioutil.ReadAll(data)
dataBytes, err := io.ReadAll(data)
if err != nil {
return
}

View File

@ -18,7 +18,7 @@
package pmapi
import (
"io/ioutil"
"io"
"github.com/ProtonMail/gopenpgp/v2/crypto"
"golang.org/x/net/context"
@ -56,7 +56,7 @@ func (m *manager) fetchFile(url string) ([]byte, error) {
return nil, err
}
b, err := ioutil.ReadAll(res.RawBody())
b, err := io.ReadAll(res.RawBody())
if err != nil {
return nil, err
}

View File

@ -20,7 +20,7 @@ package pmapi
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"strings"
@ -68,7 +68,7 @@ func TestClient_BugReportWithAttachment(t *testing.T) {
attReader, err := req.MultipartForm.File["log"][0].Open()
r.NoError(t, err)
_, err = ioutil.ReadAll(attReader)
_, err = io.ReadAll(attReader)
r.NoError(t, err)
w.Header().Set("Content-Type", "application/json")

View File

@ -27,7 +27,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/mail"
"net/url"
@ -133,10 +132,10 @@ const (
type LabelsOperation int
const (
KeepLabels LabelsOperation = iota // Do nothing.
ReplaceLabels // Replace current labels with new ones.
AddLabels // Add new labels to current ones.
RemoveLabels // Remove specified labels from current ones.
KeepLabels LabelsOperation = iota // KeepLabels Do nothing.
ReplaceLabels // ReplaceLabels Replace current labels with new ones.
AddLabels // AddLabels Add new labels to current ones.
RemoveLabels // RemoveLabels Remove specified labels from current ones.
)
// Due to API limitations, we shouldn't make requests with more than 100 message IDs at a time.
@ -309,7 +308,7 @@ func (m *Message) ExtractSignatures(kr *crypto.KeyRing) ([]Signature, error) {
return nil, err
}
if _, err := ioutil.ReadAll(msg.UnverifiedBody); err != nil {
if _, err := io.ReadAll(msg.UnverifiedBody); err != nil {
return nil, err
}

View File

@ -18,7 +18,7 @@
package pmapi
import (
"io/ioutil"
"os"
"strings"
"github.com/ProtonMail/gopenpgp/v2/crypto"
@ -65,7 +65,7 @@ func init() {
}
func readTestFile(name string, trimNewlines bool) string { //nolint:unparam
data, err := ioutil.ReadFile("testdata/" + name)
data, err := os.ReadFile("testdata/" + name)
if err != nil {
panic(err)
}

View File

@ -18,7 +18,7 @@
package sum
import (
"io/ioutil"
"io"
"os"
"path/filepath"
"testing"
@ -27,7 +27,7 @@ import (
)
func TestRecursiveSum(t *testing.T) {
tempDir, err := ioutil.TempDir("", "verify-test")
tempDir, err := os.MkdirTemp("", "verify-test")
require.NoError(t, err)
createFiles(t, tempDir,
@ -97,7 +97,7 @@ func modifyFile(t *testing.T, path string, data []byte) []byte {
r, err := os.Open(path)
require.NoError(t, err)
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
require.NoError(t, err)
require.NoError(t, r.Close())