diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2020-04-10 12:25:25 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2020-04-14 19:19:36 +0300 |
commit | ff414ff895a778df25f4d1b11f304612995c3b10 (patch) | |
tree | f5d68ad2c2173a30549803da8413dfc31670d68b | |
parent | b64d38d6c42166bafc27615af6e5244226471b67 (diff) |
Static code analysis: introduction of new linters
New linter 'unconvert' reports about unneeded type conversions.
-rw-r--r-- | .golangci.yml | 1 | ||||
-rw-r--r-- | auth/token.go | 2 | ||||
-rw-r--r-- | internal/git/log/tag.go | 2 | ||||
-rw-r--r-- | internal/git/stats/reference_discovery.go | 4 | ||||
-rw-r--r-- | internal/middleware/cache/cache_test.go | 8 | ||||
-rw-r--r-- | internal/service/commit/count_diverging_commits.go | 4 | ||||
-rw-r--r-- | internal/service/commit/languages.go | 2 | ||||
-rw-r--r-- | internal/service/commit/last_commit_for_path_test.go | 2 | ||||
-rw-r--r-- | internal/service/commit/list_last_commits_for_tree.go | 2 | ||||
-rw-r--r-- | internal/service/commit/list_last_commits_for_tree_test.go | 2 | ||||
-rw-r--r-- | internal/service/objectpool/fetch_into_object_pool_test.go | 2 | ||||
-rw-r--r-- | internal/service/operations/submodules_test.go | 2 | ||||
-rw-r--r-- | internal/service/ref/delete_refs.go | 2 | ||||
-rw-r--r-- | internal/service/ref/refs_test.go | 40 | ||||
-rw-r--r-- | internal/service/repository/repack_test.go | 2 | ||||
-rw-r--r-- | internal/service/repository/replicate_test.go | 2 |
16 files changed, 38 insertions, 41 deletions
diff --git a/.golangci.yml b/.golangci.yml index c2aade89b..40f340537 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,6 +16,7 @@ linters: - megacheck - varcheck - misspell + - unconvert issues: # Excluding configuration per-path, per-linter, per-text and per-source diff --git a/auth/token.go b/auth/token.go index 9355750aa..755d68933 100644 --- a/auth/token.go +++ b/auth/token.go @@ -89,7 +89,7 @@ func ExtractAuthInfo(ctx context.Context) (*AuthInfo, error) { return nil, err } - split := strings.SplitN(string(token), ".", 3) + split := strings.SplitN(token, ".", 3) // v1 is base64-encoded using base64.StdEncoding, which cannot contain a ".". // A v1 token cannot slip through here. diff --git a/internal/git/log/tag.go b/internal/git/log/tag.go index 1f251fa3a..0b71ef3df 100644 --- a/internal/git/log/tag.go +++ b/internal/git/log/tag.go @@ -121,7 +121,7 @@ func buildAnnotatedTag(b *catfile.Batch, tagID, name string, header *tagHeader, // tags contain the signature block in the message: // https://github.com/git/git/blob/master/Documentation/technical/signature-format.txt#L12 - index := bytes.Index([]byte(tag.Message), []byte("-----BEGIN")) + index := bytes.Index(tag.Message, []byte("-----BEGIN")) if index > 0 { signature := string(tag.Message[index : bytes.Index(tag.Message[index:], []byte("\n"))+index]) tag.SignatureType = detectSignatureType(signature) diff --git a/internal/git/stats/reference_discovery.go b/internal/git/stats/reference_discovery.go index bcf1dc344..0bd83628d 100644 --- a/internal/git/stats/reference_discovery.go +++ b/internal/git/stats/reference_discovery.go @@ -94,12 +94,12 @@ func (d *ReferenceDiscovery) Parse(body io.Reader) error { return errors.New("invalid first reference line") } - ref := strings.SplitN(string(split[0]), " ", 2) + ref := strings.SplitN(split[0], " ", 2) if len(ref) != 2 { return errors.New("invalid reference line") } d.Refs = append(d.Refs, Reference{Oid: ref[0], Name: ref[1]}) - d.Caps = strings.Split(string(split[1]), " ") + d.Caps = strings.Split(split[1], " ") state = referenceDiscoveryExpectRef case referenceDiscoveryExpectRef: diff --git a/internal/middleware/cache/cache_test.go b/internal/middleware/cache/cache_test.go index 0d9d126de..23c2d97dd 100644 --- a/internal/middleware/cache/cache_test.go +++ b/internal/middleware/cache/cache_test.go @@ -32,14 +32,10 @@ func TestInvalidators(t *testing.T) { srvr := grpc.NewServer( grpc.StreamInterceptor( - grpc.StreamServerInterceptor( - cache.StreamInvalidator(mCache, reg), - ), + cache.StreamInvalidator(mCache, reg), ), grpc.UnaryInterceptor( - grpc.UnaryServerInterceptor( - cache.UnaryInvalidator(mCache, reg), - ), + cache.UnaryInvalidator(mCache, reg), ), ) diff --git a/internal/service/commit/count_diverging_commits.go b/internal/service/commit/count_diverging_commits.go index 1593d8b57..52750feb9 100644 --- a/internal/service/commit/count_diverging_commits.go +++ b/internal/service/commit/count_diverging_commits.go @@ -79,12 +79,12 @@ func findLeftRightCount(ctx context.Context, repo *gitalypb.Repository, from, to return 0, 0, fmt.Errorf("invalid output from git rev-list --left-right: %v", string(countStr)) } - leftCount, err = strconv.ParseInt(string(counts[0]), 10, 32) + leftCount, err = strconv.ParseInt(counts[0], 10, 32) if err != nil { return 0, 0, fmt.Errorf("invalid left count value: %v", counts[0]) } - rightCount, err = strconv.ParseInt(string(counts[1]), 10, 32) + rightCount, err = strconv.ParseInt(counts[1], 10, 32) if err != nil { return 0, 0, fmt.Errorf("invalid right count value: %v", counts[1]) } diff --git a/internal/service/commit/languages.go b/internal/service/commit/languages.go index 72d66a1c4..19ee7ffe2 100644 --- a/internal/service/commit/languages.go +++ b/internal/service/commit/languages.go @@ -82,7 +82,7 @@ func (*server) CommitLanguages(ctx context.Context, req *gitalypb.CommitLanguage Share: float32(100*count) / float32(total), Color: linguist.Color(lang), FileCount: uint32(fileCountStats[lang]), - Bytes: uint64(stats[lang]), + Bytes: stats[lang], } resp.Languages = append(resp.Languages, l) } diff --git a/internal/service/commit/last_commit_for_path_test.go b/internal/service/commit/last_commit_for_path_test.go index 484d0ed9e..2b6f2ec75 100644 --- a/internal/service/commit/last_commit_for_path_test.go +++ b/internal/service/commit/last_commit_for_path_test.go @@ -77,7 +77,7 @@ func TestSuccessfulLastCommitForPathRequest(t *testing.T) { request := &gitalypb.LastCommitForPathRequest{ Repository: testRepo, Revision: []byte(testCase.revision), - Path: []byte(testCase.path), + Path: testCase.path, } ctx, cancel := context.WithCancel(context.Background()) diff --git a/internal/service/commit/list_last_commits_for_tree.go b/internal/service/commit/list_last_commits_for_tree.go index 05535ca9e..e938b8631 100644 --- a/internal/service/commit/list_last_commits_for_tree.go +++ b/internal/service/commit/list_last_commits_for_tree.go @@ -68,7 +68,7 @@ func listLastCommitsForTree(in *gitalypb.ListLastCommitsForTreeRequest, stream g } for _, entry := range entries[offset:limit] { - commit, err := log.LastCommitForPath(ctx, c, repo, string(in.GetRevision()), entry.Path) + commit, err := log.LastCommitForPath(ctx, c, repo, in.GetRevision(), entry.Path) if err != nil { return err } diff --git a/internal/service/commit/list_last_commits_for_tree_test.go b/internal/service/commit/list_last_commits_for_tree_test.go index eecb8a6e5..4b9c22412 100644 --- a/internal/service/commit/list_last_commits_for_tree_test.go +++ b/internal/service/commit/list_last_commits_for_tree_test.go @@ -353,7 +353,7 @@ func TestNonUtf8ListLastCommitsForTreeRequest(t *testing.T) { request := &gitalypb.ListLastCommitsForTreeRequest{ Repository: testRepo, - Revision: string(commitID), + Revision: commitID, Limit: 100, Offset: 0, } diff --git a/internal/service/objectpool/fetch_into_object_pool_test.go b/internal/service/objectpool/fetch_into_object_pool_test.go index d689c0215..714c71cac 100644 --- a/internal/service/objectpool/fetch_into_object_pool_test.go +++ b/internal/service/objectpool/fetch_into_object_pool_test.go @@ -57,7 +57,7 @@ func TestFetchIntoObjectPool_Success(t *testing.T) { require.Len(t, packFiles, 1, "ensure commits got packed") packContents := testhelper.MustRunCommand(t, nil, "git", "-C", pool.FullPath(), "verify-pack", "-v", packFiles[0]) - require.Contains(t, string(packContents), string(repoCommit)) + require.Contains(t, string(packContents), repoCommit) _, err = client.FetchIntoObjectPool(ctx, req) require.NoError(t, err, "calling FetchIntoObjectPool twice should be OK") diff --git a/internal/service/operations/submodules_test.go b/internal/service/operations/submodules_test.go index d85632567..0bfd7735c 100644 --- a/internal/service/operations/submodules_test.go +++ b/internal/service/operations/submodules_test.go @@ -77,7 +77,7 @@ func TestSuccessfulUserUpdateSubmoduleRequest(t *testing.T) { parser := lstree.NewParser(bytes.NewReader(entry)) parsedEntry, err := parser.NextEntry() require.NoError(t, err) - require.Equal(t, testCase.submodule, string(parsedEntry.Path)) + require.Equal(t, testCase.submodule, parsedEntry.Path) require.Equal(t, testCase.commitSha, parsedEntry.Oid) }) } diff --git a/internal/service/ref/delete_refs.go b/internal/service/ref/delete_refs.go index 44ff3a17b..a5fbde68a 100644 --- a/internal/service/ref/delete_refs.go +++ b/internal/service/ref/delete_refs.go @@ -72,7 +72,7 @@ func refsToRemove(ctx context.Context, req *gitalypb.DeleteRefsRequest) ([]strin continue } - refs = append(refs, string(refName)) + refs = append(refs, refName) } if err != nil { diff --git a/internal/service/ref/refs_test.go b/internal/service/ref/refs_test.go index c71efba88..c9159c67e 100644 --- a/internal/service/ref/refs_test.go +++ b/internal/service/ref/refs_test.go @@ -515,7 +515,7 @@ func TestSuccessfulFindAllTagsRequest(t *testing.T) { expectedTags := []*gitalypb.Tag{ { Name: []byte(commitID), - Id: string(commitTagID), + Id: commitTagID, TargetCommit: gitCommit, Message: []byte("commit tag with a commit sha as the name"), MessageSize: 40, @@ -528,7 +528,7 @@ func TestSuccessfulFindAllTagsRequest(t *testing.T) { }, { Name: []byte("tag-of-tag"), - Id: string(tagOfTagID), + Id: tagOfTagID, TargetCommit: gitCommit, Message: []byte("tag of a tag"), MessageSize: 12, @@ -619,7 +619,7 @@ func TestSuccessfulFindAllTagsRequest(t *testing.T) { }, { Name: []byte("v1.2.0"), - Id: string(annotatedTagID), + Id: annotatedTagID, Message: []byte("Blob tag"), MessageSize: 8, Tagger: &gitalypb.CommitAuthor{ @@ -631,26 +631,26 @@ func TestSuccessfulFindAllTagsRequest(t *testing.T) { }, { Name: []byte("v1.3.0"), - Id: string(commitID), + Id: commitID, TargetCommit: gitCommit, }, { Name: []byte("v1.4.0"), - Id: string(blobID), + Id: blobID, }, { Name: []byte("v1.5.0"), - Id: string(commitID), + Id: commitID, TargetCommit: gitCommit, }, { Name: []byte("v1.6.0"), - Id: string(bigCommitID), + Id: bigCommitID, TargetCommit: bigCommit, }, { Name: []byte("v1.7.0"), - Id: string(bigMessageTag1ID), + Id: bigMessageTag1ID, Message: []byte(bigMessage[:helper.MaxCommitOrTagMessageSize]), MessageSize: int64(len(bigMessage)), TargetCommit: gitCommit, @@ -727,11 +727,11 @@ func TestFindAllTagNestedTags(t *testing.T) { for depth := 0; depth < tc.depth; depth++ { tagName := fmt.Sprintf("tag-depth-%d", depth) tagMessage := fmt.Sprintf("a commit %d deep", depth) - tagID = string(testhelper.CreateTag(t, testRepoCopyPath, tagName, tagID, &testhelper.CreateTagOpts{Message: tagMessage})) + tagID = testhelper.CreateTag(t, testRepoCopyPath, tagName, tagID, &testhelper.CreateTagOpts{Message: tagMessage}) expectedTag := &gitalypb.Tag{ Name: []byte(tagName), - Id: string(tagID), + Id: tagID, Message: []byte(tagMessage), MessageSize: int64(len([]byte(tagMessage))), Tagger: &gitalypb.CommitAuthor{ @@ -1431,7 +1431,7 @@ func TestSuccessfulFindTagRequest(t *testing.T) { expectedTags := []*gitalypb.Tag{ { Name: []byte(commitID), - Id: string(commitTagID), + Id: commitTagID, TargetCommit: gitCommit, Message: []byte("commit tag with a commit sha as the name"), MessageSize: 40, @@ -1444,7 +1444,7 @@ func TestSuccessfulFindTagRequest(t *testing.T) { }, { Name: []byte("tag-of-tag"), - Id: string(tagOfTagID), + Id: tagOfTagID, TargetCommit: gitCommit, Message: []byte("tag of a tag"), MessageSize: 12, @@ -1536,7 +1536,7 @@ func TestSuccessfulFindTagRequest(t *testing.T) { }, { Name: []byte("v1.2.0"), - Id: string(annotatedTagID), + Id: annotatedTagID, Message: []byte("Blob tag"), MessageSize: 8, Tagger: &gitalypb.CommitAuthor{ @@ -1548,26 +1548,26 @@ func TestSuccessfulFindTagRequest(t *testing.T) { }, { Name: []byte("v1.3.0"), - Id: string(commitID), + Id: commitID, TargetCommit: gitCommit, }, { Name: []byte("v1.4.0"), - Id: string(blobID), + Id: blobID, }, { Name: []byte("v1.5.0"), - Id: string(commitID), + Id: commitID, TargetCommit: gitCommit, }, { Name: []byte("v1.6.0"), - Id: string(bigCommitID), + Id: bigCommitID, TargetCommit: bigCommit, }, { Name: []byte("v1.7.0"), - Id: string(bigMessageTag1ID), + Id: bigMessageTag1ID, Message: []byte(bigMessage[:helper.MaxCommitOrTagMessageSize]), MessageSize: int64(len(bigMessage)), TargetCommit: gitCommit, @@ -1650,11 +1650,11 @@ func TestFindTagNestedTag(t *testing.T) { for depth := 0; depth < tc.depth; depth++ { tagName = fmt.Sprintf("tag-depth-%d", depth) tagMessage = fmt.Sprintf("a commit %d deep", depth) - tagID = string(testhelper.CreateTag(t, testRepoCopyPath, tagName, tagID, &testhelper.CreateTagOpts{Message: tagMessage})) + tagID = testhelper.CreateTag(t, testRepoCopyPath, tagName, tagID, &testhelper.CreateTagOpts{Message: tagMessage}) } expectedTag := &gitalypb.Tag{ Name: []byte(tagName), - Id: string(tagID), + Id: tagID, Message: []byte(tagMessage), MessageSize: int64(len([]byte(tagMessage))), Tagger: &gitalypb.CommitAuthor{ diff --git a/internal/service/repository/repack_test.go b/internal/service/repository/repack_test.go index c35fe1769..c8bc43c5f 100644 --- a/internal/service/repository/repack_test.go +++ b/internal/service/repository/repack_test.go @@ -114,7 +114,7 @@ func TestRepackLocal(t *testing.T) { packContents := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "verify-pack", "-v", packFiles[0]) require.NotContains(t, string(packContents), string(altDirsCommit)) - require.Contains(t, string(packContents), string(repoCommit)) + require.Contains(t, string(packContents), repoCommit) } func TestRepackIncrementalFailure(t *testing.T) { diff --git a/internal/service/repository/replicate_test.go b/internal/service/repository/replicate_test.go index 2dd9a8fbf..cf008e9c3 100644 --- a/internal/service/repository/replicate_test.go +++ b/internal/service/repository/replicate_test.go @@ -104,7 +104,7 @@ func TestReplicateRepository(t *testing.T) { ) // if an unreachable object has been replicated, that means snapshot replication was used - testhelper.MustRunCommand(t, nil, "git", "-C", targetRepoPath, "cat-file", "-p", string(blobID)) + testhelper.MustRunCommand(t, nil, "git", "-C", targetRepoPath, "cat-file", "-p", blobID) } func TestReplicateRepositoryInvalidArguments(t *testing.T) { |