chore: remove some dead code found by linter. (#46940)

Test plan:
CI should pass.
This commit is contained in:
Alex Ostrikov 2023-01-25 20:43:54 +04:00 committed by GitHub
parent b5dc735f60
commit 6a3096bfbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 8 additions and 143 deletions

View File

@ -136,8 +136,4 @@ var (
Name: "blobstore_service_running",
Help: "Number of running blobstore requests.",
})
metricRequestTotal = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "blobstore_service_request_total",
Help: "Number of returned blobstore requests.",
}, []string{"code"})
)

View File

@ -20,9 +20,6 @@ import (
"github.com/sourcegraph/sourcegraph/lib/errors"
)
// slowRequestRedisFIFOListDefaultSize sets a default value for the FIFO list.
const slowRequestRedisFIFOListDefaultSize = 5000
// slowRequestRedisFIFOListPerPage sets the default count of returned request.
const slowRequestRedisFIFOListPerPage = 50

View File

@ -38,8 +38,7 @@ func NewRubyPackagesSyncer(
}
type rubyDependencySource struct {
repositoryURL string
client *rubygems.Client
client *rubygems.Client
}
func (rubyDependencySource) ParseVersionedPackageFromNameAndVersion(name reposource.PackageName, version string) (reposource.VersionedPackage, error) {

View File

@ -17,13 +17,9 @@ import (
"github.com/sourcegraph/sourcegraph/lib/output"
)
// https://buildkite.com/sourcegraph
// BuildkiteOrg is a Sourcegraph org in Buildkite. See: is https://buildkite.com/sourcegraph
const BuildkiteOrg = "sourcegraph"
type buildkiteSecrets struct {
Token string `json:"token"`
}
type Build struct {
buildkite.Build
}

View File

@ -27,14 +27,6 @@ func NewService(
)
}
type serviceDependencies struct {
db database.DB
codeIntelDB codeintelshared.CodeIntelDB
uploadSvc UploadService
gitserver GitserverClient
observationCtx *observation.Context
}
func scopedContext(component string, parent *observation.Context) *observation.Context {
return observation.ScopedContext("codeintel", "codenav", component, parent)
}

View File

@ -24,13 +24,6 @@ func NewService(
)
}
type serviceDependencies struct {
db database.DB
uploadSvc UploadService
gitserver GitserverClient
observationCtx *observation.Context
}
func scopedContext(component string, parent *observation.Context) *observation.Context {
return observation.ScopedContext("codeintel", "policies", component, parent)
}

View File

@ -4,7 +4,6 @@ import (
"context"
"io/fs"
"strconv"
"strings"
"time"
"github.com/prometheus/client_golang/prometheus"
@ -63,11 +62,11 @@ var DefaultSubRepoPermsChecker SubRepoPermissionChecker = &noopPermsChecker{}
type noopPermsChecker struct{}
func (*noopPermsChecker) Permissions(ctx context.Context, userID int32, content RepoContent) (Perms, error) {
func (*noopPermsChecker) Permissions(_ context.Context, _ int32, _ RepoContent) (Perms, error) {
return None, nil
}
func (*noopPermsChecker) FilePermissionsFunc(ctx context.Context, userID int32, repo api.RepoName) (FilePermissionFunc, error) {
func (*noopPermsChecker) FilePermissionsFunc(_ context.Context, _ int32, _ api.RepoName) (FilePermissionFunc, error) {
return func(path string) (Perms, error) {
return None, nil
}, nil
@ -77,54 +76,14 @@ func (*noopPermsChecker) Enabled() bool {
return false
}
func (*noopPermsChecker) EnabledForRepoID(ctx context.Context, repoID api.RepoID) (bool, error) {
func (*noopPermsChecker) EnabledForRepoID(_ context.Context, _ api.RepoID) (bool, error) {
return false, nil
}
func (*noopPermsChecker) EnabledForRepo(ctx context.Context, repo api.RepoName) (bool, error) {
func (*noopPermsChecker) EnabledForRepo(_ context.Context, _ api.RepoName) (bool, error) {
return false, nil
}
// filePermissionsFuncAllRead is a FilePermissionFunc which _always_ returns
// Read. Only use in cases that sub repo permission checks should not be done.
func filePermissionsFuncAllRead(_ string) (Perms, error) {
return Read, nil
}
// expandDirs will return a new set of rules that will match all directories
// above the supplied rule. As a special case, if the rule starts with a wildcard
// we return a rule to match all directories.
func expandDirs(rule string) []string {
dirs := make([]string, 0)
// Make sure the rule starts with a slash
if !strings.HasPrefix(rule, "/") {
rule = "/" + rule
}
// If a rule starts with a wildcard it can match at any level in the tree
// structure so there's no way of walking up the tree and expand out to the list
// of valid directories. Instead, we just return a rule that matches any
// directory
if strings.HasPrefix(rule, "/*") {
dirs = append(dirs, "**/")
return dirs
}
for {
lastSlash := strings.LastIndex(rule, "/")
if lastSlash <= 0 { // we have to ignore the slash at index 0
break
}
// Drop anything after the last slash
rule = rule[:lastSlash]
dirs = append(dirs, rule+"/")
}
return dirs
}
// ActorPermissions returns the level of access the given actor has for the requested
// content.
//

View File

@ -12,13 +12,8 @@ func NewService(observationCtx *observation.Context, db database.DB) *Service {
return newService(scopedContext("service", observationCtx), store.New(scopedContext("store", observationCtx), db))
}
type serviceDependencies struct {
db database.DB
observationCtx *observation.Context
}
// TestService creates a new dependencies service with noop observation contexts.
func TestService(db database.DB, gitserver GitserverClient) *Service {
func TestService(db database.DB, _ GitserverClient) *Service {
store := store.New(&observation.TestContext, db)
return newService(&observation.TestContext, store)

View File

@ -178,8 +178,6 @@ type Client struct {
Auth auth.Authenticator
rateLimitMonitor *ratelimit.Monitor
rateLimiter *ratelimit.InstrumentedLimiter // Our internal rate limiter
tokenRefresher oauthutil.TokenRefresher
}
// newClient creates a new GitLab API client with an optional personal access token to authenticate requests.

View File

@ -2,10 +2,7 @@ package oauthutil
import (
"context"
"encoding/json"
"fmt"
"net/http"
"strings"
"golang.org/x/oauth2"
@ -32,32 +29,6 @@ type OAuthContext struct {
Scopes []string
}
type oauthError struct {
Err string `json:"error"`
ErrorDescription string `json:"error_description"`
}
func (e oauthError) Error() string {
return fmt.Sprintf("OAuth response error %q description %q", e.Err, e.ErrorDescription)
}
// getOAuthErrorDetails is a method that only returns OAuth errors.
// It is intended to be used in the oauth flow, when refreshing an expired token.
func getOAuthErrorDetails(body []byte) error {
var oe oauthError
if err := json.Unmarshal(body, &oe); err != nil {
// If we failed to unmarshal body with oauth error, it's not oauthError and we should return nil.
return nil
}
// https://www.oauth.com/oauth2-servers/access-tokens/access-token-response/
// {"error":"invalid_token","error_description":"Token is expired. You can either do re-authorization or token refresh."}
if oe.Err == "invalid_token" && strings.Contains(oe.ErrorDescription, "expired") {
return &oe
}
return nil
}
// TokenRefresher is a function to refresh and return the new OAuth token.
type TokenRefresher func(ctx context.Context, doer httpcli.Doer, oauthCtx OAuthContext) (*auth.OAuthBearerToken, error)

View File

@ -107,7 +107,7 @@ type syncHandler struct {
minSyncInterval func() time.Duration
}
func (s *syncHandler) Handle(ctx context.Context, logger log.Logger, sj *SyncJob) (err error) {
func (s *syncHandler) Handle(ctx context.Context, _ log.Logger, sj *SyncJob) (err error) {
// Limit calls to progressRecorder as it will most likely hit the database
progressLimiter := rate.NewLimiter(rate.Limit(1.0), 1)

View File

@ -944,22 +944,6 @@ func optimizeRepoPatternWithHeuristics(repoPattern string) string {
return repoPattern
}
type badRequestError struct {
err error
}
func (e *badRequestError) BadRequest() bool {
return true
}
func (e *badRequestError) Error() string {
return "bad request: " + e.err.Error()
}
func (e *badRequestError) Cause() error {
return e.err
}
var ErrNoResolvedRepos = errors.New("no resolved repositories")
type MissingRepoRevsError struct {

View File

@ -12,8 +12,6 @@ import (
"github.com/sourcegraph/sourcegraph/lib/errors"
)
var errOptionalPublishedUnsupported = NewValidationError(errors.New(`This Sourcegraph version requires the "published" field to be specified in the batch spec; upgrade to version 3.30.0 or later to be able to omit the published field and control publication from the UI.`))
// Repository is a repository in which the steps of a batch spec are executed.
//
// It is part of the cache.ExecutionKey, so changes to the names of fields here

View File

@ -297,16 +297,3 @@ func extractLanguageFromIndexerName(indexerName string) string {
return ""
}
// flattenNonEmptyMap returns an ordered slice of the keys from the given map, excluding the empty string.
func flattenNonEmptyMap(m map[string]struct{}) []string {
s := make([]string, 0, len(m))
for k := range m {
if k != "" {
s = append(s, k)
}
}
sort.Strings(s)
return s
}