Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add staticcheck #1735

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ lint:

vet:
@GO111MODULE=on go vet ./...
@echo "Installing staticcheck" && go install honnef.co/go/tools/cmd/staticcheck@latest
${GOPATH}/bin/staticcheck -tests=false -checks="all,-ST1000,-ST1003,-ST1016,-ST1020,-ST1021,-ST1022,-ST1023,-ST1005"

test:
@GO111MODULE=on SERVER_ENDPOINT=localhost:9000 ACCESS_KEY=minio SECRET_KEY=minio123 ENABLE_HTTPS=1 MINT_MODE=full go test -race -v ./...
Expand Down
4 changes: 2 additions & 2 deletions api-bucket-lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"bytes"
"context"
"encoding/xml"
"io/ioutil"
"io"
"net/http"
"net/url"

Expand Down Expand Up @@ -143,5 +143,5 @@ func (c *Client) getBucketLifecycle(ctx context.Context, bucketName string) ([]b
}
}

return ioutil.ReadAll(resp.Body)
return io.ReadAll(resp.Body)
}
4 changes: 2 additions & 2 deletions api-bucket-policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package minio

import (
"context"
"io/ioutil"
"io"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -137,7 +137,7 @@ func (c *Client) getBucketPolicy(ctx context.Context, bucketName string) (string
}
}

bucketPolicyBuf, err := ioutil.ReadAll(resp.Body)
bucketPolicyBuf, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions api-bucket-replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"context"
"encoding/json"
"encoding/xml"
"io/ioutil"
"io"
"net/http"
"net/url"
"time"
Expand Down Expand Up @@ -180,7 +180,7 @@ func (c *Client) GetBucketReplicationMetrics(ctx context.Context, bucketName str
if resp.StatusCode != http.StatusOK {
return s, httpRespToErrorResponse(resp, bucketName, "")
}
respBytes, err := ioutil.ReadAll(resp.Body)
respBytes, err := io.ReadAll(resp.Body)
if err != nil {
return s, err
}
Expand Down
3 changes: 1 addition & 2 deletions api-bucket-tagging.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"encoding/xml"
"errors"
"io"
"io/ioutil"
"net/http"
"net/url"

Expand Down Expand Up @@ -58,7 +57,7 @@ func (c *Client) GetBucketTagging(ctx context.Context, bucketName string) (*tags
return nil, httpRespToErrorResponse(resp, bucketName, "")
}

defer io.Copy(ioutil.Discard, resp.Body)
defer io.Copy(io.Discard, resp.Body)
return tags.ParseBucketXML(resp.Body)
}

Expand Down
3 changes: 1 addition & 2 deletions api-compose-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -516,7 +515,7 @@ func (c *Client) ComposeObject(ctx context.Context, dst CopyDestOptions, srcs ..
return UploadInfo{}, err
}
if dst.Progress != nil {
io.CopyN(ioutil.Discard, dst.Progress, end-start+1)
io.CopyN(io.Discard, dst.Progress, end-start+1)
}
objParts = append(objParts, complPart)
partIndex++
Expand Down
3 changes: 1 addition & 2 deletions api-copy-object.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package minio
import (
"context"
"io"
"io/ioutil"
"net/http"
)

Expand Down Expand Up @@ -54,7 +53,7 @@ func (c *Client) CopyObject(ctx context.Context, dst CopyDestOptions, src CopySr

// Update the progress properly after successful copy.
if dst.Progress != nil {
io.Copy(ioutil.Discard, io.LimitReader(dst.Progress, dst.Size))
io.Copy(io.Discard, io.LimitReader(dst.Progress, dst.Size))
}

cpObjRes := copyObjectResult{}
Expand Down
23 changes: 1 addition & 22 deletions api-error-response.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"net/http"
)

Expand Down Expand Up @@ -108,7 +107,7 @@ const (
func xmlDecodeAndBody(bodyReader io.Reader, v interface{}) ([]byte, error) {
// read the whole body (up to 1MB)
const maxBodyLength = 1 << 20
body, err := ioutil.ReadAll(io.LimitReader(bodyReader, maxBodyLength))
body, err := io.ReadAll(io.LimitReader(bodyReader, maxBodyLength))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -253,26 +252,6 @@ func errUnexpectedEOF(totalRead, totalSize int64, bucketName, objectName string)
}
}

// errInvalidBucketName - Invalid bucket name response.
func errInvalidBucketName(message string) error {
return ErrorResponse{
StatusCode: http.StatusBadRequest,
Code: "InvalidBucketName",
Message: message,
RequestID: "minio",
}
}

// errInvalidObjectName - Invalid object name response.
func errInvalidObjectName(message string) error {
return ErrorResponse{
StatusCode: http.StatusNotFound,
Code: "NoSuchKey",
Message: message,
RequestID: "minio",
}
}

// errInvalidArgument - Invalid argument response.
func errInvalidArgument(message string) error {
return ErrorResponse{
Expand Down
34 changes: 3 additions & 31 deletions api-error-response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"bytes"
"encoding/xml"
"fmt"
"io/ioutil"
"io"
"net/http"
"reflect"
"strconv"
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestHttpRespToErrorResponse(t *testing.T) {
resp := &http.Response{}
resp.StatusCode = statusCode
resp.Status = http.StatusText(statusCode)
resp.Body = ioutil.NopCloser(bytes.NewBuffer(body))
resp.Body = io.NopCloser(bytes.NewBuffer(body))
return resp
}

Expand Down Expand Up @@ -113,7 +113,7 @@ func TestHttpRespToErrorResponse(t *testing.T) {
resp := &http.Response{
StatusCode: statusCode,
Status: http.StatusText(statusCode),
Body: ioutil.NopCloser(bytes.NewReader(nil)),
Body: io.NopCloser(bytes.NewReader(nil)),
}
setCommonHeaders(resp)
return resp
Expand Down Expand Up @@ -243,34 +243,6 @@ func TestErrUnexpectedEOF(t *testing.T) {
}
}

// Test validates 'ErrInvalidBucketName' error response.
func TestErrInvalidBucketName(t *testing.T) {
expectedResult := ErrorResponse{
StatusCode: http.StatusBadRequest,
Code: "InvalidBucketName",
Message: "Invalid Bucket name",
RequestID: "minio",
}
actualResult := errInvalidBucketName("Invalid Bucket name")
if !reflect.DeepEqual(expectedResult, actualResult) {
t.Errorf("Expected result to be '%#v', but instead got '%#v'", expectedResult, actualResult)
}
}

// Test validates 'ErrInvalidObjectName' error response.
func TestErrInvalidObjectName(t *testing.T) {
expectedResult := ErrorResponse{
StatusCode: http.StatusNotFound,
Code: "NoSuchKey",
Message: "Invalid Object Key",
RequestID: "minio",
}
actualResult := errInvalidObjectName("Invalid Object Key")
if !reflect.DeepEqual(expectedResult, actualResult) {
t.Errorf("Expected result to be '%#v', but instead got '%#v'", expectedResult, actualResult)
}
}

// Test validates 'errInvalidArgument' response.
func TestErrInvalidArgument(t *testing.T) {
expectedResult := ErrorResponse{
Expand Down
9 changes: 4 additions & 5 deletions api-get-object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"crypto/rand"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -51,7 +50,7 @@ func TestGetObjectReturnSuccess(t *testing.T) {
}

// We expect an error when reading back.
buf, err := ioutil.ReadAll(obj)
buf, err := io.ReadAll(obj)
if err != nil {
t.Fatalf("Expected 'nil', got %v", err)
}
Expand Down Expand Up @@ -85,7 +84,7 @@ func TestGetObjectReturnErrorIfServerTruncatesResponse(t *testing.T) {
}

// We expect an error when reading back.
if _, err = ioutil.ReadAll(obj); err != io.ErrUnexpectedEOF {
if _, err = io.ReadAll(obj); err != io.ErrUnexpectedEOF {
t.Fatalf("Expected %v, got %v", io.ErrUnexpectedEOF, err)
}
}
Expand Down Expand Up @@ -114,7 +113,7 @@ func TestGetObjectReturnErrorIfServerTruncatesResponseDouble(t *testing.T) {
}

// We expect an error when reading back.
if _, err = ioutil.ReadAll(obj); err != io.ErrUnexpectedEOF {
if _, err = io.ReadAll(obj); err != io.ErrUnexpectedEOF {
t.Fatalf("Expected %v, got %v", io.ErrUnexpectedEOF, err)
}
}
Expand Down Expand Up @@ -143,7 +142,7 @@ func TestGetObjectReturnErrorIfServerSendsMore(t *testing.T) {
}

// We expect an error when reading back.
if _, err = ioutil.ReadAll(obj); err != io.ErrUnexpectedEOF {
if _, err = io.ReadAll(obj); err != io.ErrUnexpectedEOF {
t.Fatalf("Expected %v, got %v", io.ErrUnexpectedEOF, err)
}
}
2 changes: 2 additions & 0 deletions api-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,8 @@ func (c *Client) listMultipartUploadsQuery(ctx context.Context, bucketName, keyM
}

// listObjectParts list all object parts recursively.
//
//lint:ignore U1000 Keep this around
func (c *Client) listObjectParts(ctx context.Context, bucketName, objectName, uploadID string) (partsInfo map[int]ObjectPart, err error) {
// Part number marker for the next batch of request.
var nextPartNumberMarker int
Expand Down
3 changes: 1 addition & 2 deletions api-put-object-multipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"fmt"
"hash/crc32"
"io"
"io/ioutil"
"net/http"
"net/url"
"sort"
Expand Down Expand Up @@ -412,7 +411,7 @@ func (c *Client) completeMultipartUpload(ctx context.Context, bucketName, object

// Read resp.Body into a []bytes to parse for Error response inside the body
var b []byte
b, err = ioutil.ReadAll(resp.Body)
b, err = io.ReadAll(resp.Body)
if err != nil {
return UploadInfo{}, err
}
Expand Down
3 changes: 1 addition & 2 deletions api-putobject-snowball.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -107,7 +106,7 @@ func (c Client) PutObjectsSnowball(ctx context.Context, bucketName string, opts
return nopReadSeekCloser{bytes.NewReader(b.Bytes())}, int64(b.Len()), nil
}
} else {
f, err := ioutil.TempFile("", "s3-putsnowballobjects-*")
f, err := os.CreateTemp("", "s3-putsnowballobjects-*")
if err != nil {
return err
}
Expand Down
32 changes: 16 additions & 16 deletions api-select.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type CSVFileHeaderInfo string
// Constants for file header info.
const (
CSVFileHeaderInfoNone CSVFileHeaderInfo = "NONE"
CSVFileHeaderInfoIgnore = "IGNORE"
CSVFileHeaderInfoUse = "USE"
CSVFileHeaderInfoIgnore CSVFileHeaderInfo = "IGNORE"
CSVFileHeaderInfoUse CSVFileHeaderInfo = "USE"
)

// SelectCompressionType - is the parameter for what type of compression is
Expand All @@ -52,15 +52,15 @@ type SelectCompressionType string
// Constants for compression types under select API.
const (
SelectCompressionNONE SelectCompressionType = "NONE"
SelectCompressionGZIP = "GZIP"
SelectCompressionBZIP = "BZIP2"
SelectCompressionGZIP SelectCompressionType = "GZIP"
SelectCompressionBZIP SelectCompressionType = "BZIP2"

// Non-standard compression schemes, supported by MinIO hosts:

SelectCompressionZSTD = "ZSTD" // Zstandard compression.
SelectCompressionLZ4 = "LZ4" // LZ4 Stream
SelectCompressionS2 = "S2" // S2 Stream
SelectCompressionSNAPPY = "SNAPPY" // Snappy stream
SelectCompressionZSTD SelectCompressionType = "ZSTD" // Zstandard compression.
SelectCompressionLZ4 SelectCompressionType = "LZ4" // LZ4 Stream
SelectCompressionS2 SelectCompressionType = "S2" // S2 Stream
SelectCompressionSNAPPY SelectCompressionType = "SNAPPY" // Snappy stream
)

// CSVQuoteFields - is the parameter for how CSV fields are quoted.
Expand All @@ -69,7 +69,7 @@ type CSVQuoteFields string
// Constants for csv quote styles.
const (
CSVQuoteFieldsAlways CSVQuoteFields = "Always"
CSVQuoteFieldsAsNeeded = "AsNeeded"
CSVQuoteFieldsAsNeeded CSVQuoteFields = "AsNeeded"
)

// QueryExpressionType - is of what syntax the expression is, this should only
Expand All @@ -87,7 +87,7 @@ type JSONType string
// Constants for JSONTypes.
const (
JSONDocumentType JSONType = "DOCUMENT"
JSONLinesType = "LINES"
JSONLinesType JSONType = "LINES"
)

// ParquetInputOptions parquet input specific options
Expand Down Expand Up @@ -378,8 +378,8 @@ type SelectObjectType string
// Constants for input data types.
const (
SelectObjectTypeCSV SelectObjectType = "CSV"
SelectObjectTypeJSON = "JSON"
SelectObjectTypeParquet = "Parquet"
SelectObjectTypeJSON SelectObjectType = "JSON"
SelectObjectTypeParquet SelectObjectType = "Parquet"
)

// preludeInfo is used for keeping track of necessary information from the
Expand Down Expand Up @@ -416,7 +416,7 @@ type messageType string

const (
errorMsg messageType = "error"
commonMsg = "event"
commonMsg messageType = "event"
)

// eventType represents the type of event.
Expand All @@ -425,9 +425,9 @@ type eventType string
// list of event-types returned by Select API.
const (
endEvent eventType = "End"
recordsEvent = "Records"
progressEvent = "Progress"
statsEvent = "Stats"
recordsEvent eventType = "Records"
progressEvent eventType = "Progress"
statsEvent eventType = "Stats"
)

// contentType represents content type of event.
Expand Down
Loading