1
0
mirror of https://github.com/minio/mc.git synced 2025-11-10 13:42:32 +03:00

add new linters and fix unnecessary type conversions (#3835)

This commit is contained in:
Harshavardhana
2021-10-14 15:33:31 -07:00
committed by GitHub
parent 0eef0174a7
commit ae271e7645
13 changed files with 31 additions and 45 deletions

View File

@@ -8,15 +8,20 @@ linters-settings:
linters:
disable-all: true
enable:
- revive
- typecheck
- goimports
- misspell
- govet
- revive
- ineffassign
- gosimple
- deadcode
- structcheck
- gomodguard
- gofmt
- unused
- structcheck
- varcheck
issues:
exclude-use-default: false
@@ -24,5 +29,6 @@ issues:
- instead of using struct literal
- should have a package comment
- error strings should not be capitalized or end with punctuation or a newline
service:
golangci-lint-version: 1.20.0 # use the fixed version to not introduce new linters unexpectedly

View File

@@ -224,7 +224,7 @@ func (u clusterStruct) String() (msg string) {
// Summary on used space, total no of buckets and
// total no of objects at the Cluster level
usedTotal := humanize.IBytes(uint64(u.Info.Usage.Size))
usedTotal := humanize.IBytes(u.Info.Usage.Size)
if u.Info.Buckets.Count > 0 {
msg += fmt.Sprintf("%s Used, %s, %s\n", usedTotal,
english.Plural(int(u.Info.Buckets.Count), "Bucket", ""),
@@ -281,7 +281,7 @@ func mainAdminInfo(ctx *cli.Context) error {
clusterInfo.Error = ""
}
clusterInfo.Info = admInfo
printMsg(clusterStruct(clusterInfo))
printMsg(clusterInfo)
return nil
}

View File

@@ -134,7 +134,7 @@ func mainAdminPolicyAdd(ctx *cli.Context) error {
client, err := newAdminClient(aliasedURL)
fatalIf(err, "Unable to initialize admin connection.")
fatalIf(probe.NewError(client.AddCannedPolicy(globalContext, args.Get(1), []byte(policy))).Trace(args...), "Unable to add new policy")
fatalIf(probe.NewError(client.AddCannedPolicy(globalContext, args.Get(1), policy)).Trace(args...), "Unable to add new policy")
printMsg(userPolicyMessage{
op: "add",

View File

@@ -86,10 +86,10 @@ func (s speedTestResult) String() (msg string) {
if globalSpeedTestVerbose {
msg += "\n"
}
msg += fmt.Sprintf("PUT: %s/s, %d objs/s\n", humanize.IBytes(uint64(s.PUTStats.ThroughputPerSec)), s.PUTStats.ObjectsPerSec)
msg += fmt.Sprintf("PUT: %s/s, %d objs/s\n", humanize.IBytes(s.PUTStats.ThroughputPerSec), s.PUTStats.ObjectsPerSec)
if globalSpeedTestVerbose {
for _, node := range s.PUTStats.Servers {
msg += fmt.Sprintf(" * %s:, %s/s, %d objs/s", node.Endpoint, humanize.IBytes(uint64(node.ThroughputPerSec)), node.ObjectsPerSec)
msg += fmt.Sprintf(" * %s:, %s/s, %d objs/s", node.Endpoint, humanize.IBytes(node.ThroughputPerSec), node.ObjectsPerSec)
if node.Err != "" {
msg += " error: " + node.Err
}
@@ -100,10 +100,10 @@ func (s speedTestResult) String() (msg string) {
if globalSpeedTestVerbose {
msg += "\n"
}
msg += fmt.Sprintf("GET: %s/s, %d objs/s\n", humanize.IBytes(uint64(s.GETStats.ThroughputPerSec)), s.GETStats.ObjectsPerSec)
msg += fmt.Sprintf("GET: %s/s, %d objs/s\n", humanize.IBytes(s.GETStats.ThroughputPerSec), s.GETStats.ObjectsPerSec)
if globalSpeedTestVerbose {
for _, node := range s.GETStats.Servers {
msg += fmt.Sprintf(" * %s:, %s/s, %d objs/s", node.Endpoint, humanize.IBytes(uint64(node.ThroughputPerSec)), node.ObjectsPerSec)
msg += fmt.Sprintf(" * %s:, %s/s, %d objs/s", node.Endpoint, humanize.IBytes(node.ThroughputPerSec), node.ObjectsPerSec)
if node.Err != "" {
msg += " error: " + node.Err
}

View File

@@ -321,7 +321,7 @@ func uploadHealthReport(alias string, filename string, reqURL string, headers ma
}
msg := "MinIO Health data was successfully uploaded to SUBNET."
clusterURL, _ := url.PathUnescape(gjson.Get(string(resp), "cluster_url").String())
clusterURL, _ := url.PathUnescape(gjson.Get(resp, "cluster_url").String())
if len(clusterURL) > 0 {
msg += fmt.Sprintf(" Can be viewed at: %s", clusterURL)
}

View File

@@ -478,7 +478,7 @@ func colorizedNodeName(nodeName string) string {
nodeHash := fnv.New32a()
nodeHash.Write([]byte(nodeName))
nHashSum := nodeHash.Sum32()
idx := uint32(nHashSum) % uint32(len(colors))
idx := nHashSum % uint32(len(colors))
return console.Colorize(fmt.Sprintf("Node%d", colors[idx]), nodeName)
}

View File

@@ -164,7 +164,7 @@ type anonymousLinksMessage struct {
// String colorized access message.
func (s anonymousLinksMessage) String() string {
return console.Colorize("Anonymous", string(s.URL))
return console.Colorize("Anonymous", s.URL)
}
// JSON jsonified anonymous message.
@@ -203,7 +203,7 @@ func checkAnonymousSyntax(ctx *cli.Context) {
accessPerms(secondArg) != accessPrivate &&
accessPerms(secondArg) != accessPublic {
fatalIf(errDummy().Trace(),
"Unrecognized permission `"+string(secondArg)+"`. Allowed values are [private, public, download, upload].")
"Unrecognized permission `"+secondArg+"`. Allowed values are [private, public, download, upload].")
}
case "set-json":

View File

@@ -86,7 +86,7 @@ func isNotSupported(e error) bool {
}
// check if filesystem supports extended attributes
return errno.Err == syscall.Errno(syscall.ENOTSUP) || errno.Err == syscall.Errno(syscall.EOPNOTSUPP)
return errno.Err == syscall.ENOTSUP || errno.Err == syscall.EOPNOTSUPP
}
// isIgnoredFile returns true if 'filename' is on the exclude list.

View File

@@ -1900,26 +1900,6 @@ func (c *S3Client) listIncompleteRecursiveInRoutine(ctx context.Context, content
}
}
// Convert objectMultipartInfo to ClientContent
func (c *S3Client) objectMultipartInfo2ClientContent(bucket string, entry minio.ObjectMultipartInfo) ClientContent {
content := ClientContent{}
url := c.targetURL.Clone()
// Join bucket and incoming object key.
url.Path = c.joinPath(bucket, entry.Key)
content.URL = url
content.Size = entry.Size
content.Time = entry.Initiated
if strings.HasSuffix(entry.Key, string(c.targetURL.Separator)) {
content.Type = os.ModeDir
} else {
content.Type = os.ModeTemporary
}
return content
}
// Returns new path by joining path segments with URL path separator.
func (c *S3Client) joinPath(bucket string, objects ...string) string {
p := string(c.targetURL.Separator) + bucket

View File

@@ -158,9 +158,9 @@ func (h objectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Test bucket operations.
func (s *TestSuite) TestBucketOperations(c *C) {
bucket := bucketHandler(bucketHandler{
bucket := bucketHandler{
resource: "/bucket/",
})
}
server := httptest.NewServer(bucket)
defer server.Close()
@@ -205,10 +205,10 @@ func (s *TestSuite) TestBucketOperations(c *C) {
// Test all object operations.
func (s *TestSuite) TestObjectOperations(c *C) {
object := objectHandler(objectHandler{
object := objectHandler{
resource: "/bucket/object",
data: []byte("Hello, World"),
})
}
server := httptest.NewServer(object)
defer server.Close()

View File

@@ -576,7 +576,7 @@ func uploadSourceToTargetURL(ctx context.Context, urls URLs, progress io.Reader,
md5: urls.MD5,
disableMultipart: urls.DisableMultipart,
isPreserve: preserve,
multipartSize: uint64(multipartSize),
multipartSize: multipartSize,
multipartThreads: uint(multipartThreads),
}

View File

@@ -162,7 +162,7 @@ type policyLinksMessage struct {
// String colorized access message.
func (s policyLinksMessage) String() string {
return console.Colorize("Policy", string(s.URL))
return console.Colorize("Policy", s.URL)
}
// JSON jsonified policy message.
@@ -200,7 +200,7 @@ func checkPolicySyntax(ctx *cli.Context) {
accessPerms(secondArg) != accessUpload &&
accessPerms(secondArg) != accessPublic {
fatalIf(errDummy().Trace(),
"Unrecognized permission `"+string(secondArg)+"`. Allowed values are [none, download, upload, public].")
"Unrecognized permission `"+secondArg+"`. Allowed values are [none, download, upload, public].")
}
case "set-json":

View File

@@ -343,7 +343,7 @@ func parseAtimeMtime(attr map[string]string) (atime, mtime time.Time, err *probe
return atime, mtime, probe.NewError(e)
}
}
atime = time.Unix(int64(atim), int64(atimnsec))
atime = time.Unix(atim, atimnsec)
}
if val, ok := attr["mtime"]; ok {
@@ -359,7 +359,7 @@ func parseAtimeMtime(attr map[string]string) (atime, mtime time.Time, err *probe
return atime, mtime, probe.NewError(e)
}
}
mtime = time.Unix(int64(mtim), int64(mtimnsec))
mtime = time.Unix(mtim, mtimnsec)
}
return atime, mtime, nil
}