From 736a5626cdb97937206f52838bbeac757bf2a0ce Mon Sep 17 00:00:00 2001 From: William Bezuidenhout Date: Wed, 2 Nov 2022 15:08:25 +0200 Subject: [PATCH] go + golangci: update to go to 1.19.3 and golanci to 1.50.1 (#43747) * upgrade to go 1.19.3 * upgrade golangci-lint 1.50.1 * disable unused and unparam lints * Fix all the lint errors Co-authored-by: Jean-Hadrien Chabran Co-authored-by: Keegan Carruthers-Smith --- .github/workflows/sg-setup.yml | 2 +- .golangci.yml | 16 ++++++++++++-- .tool-versions | 2 +- client/web/src/nav/GlobalNavbar.tsx | 6 ++++- cmd/frontend/internal/app/debug.go | 2 +- .../internal/auth/userpasswd/lockout_test.go | 2 +- .../internal/httpapi/internal_test.go | 2 +- cmd/gitserver/server/cleanup.go | 7 ++++++ cmd/symbols/internal/api/search_sqlite.go | 1 - dev/golangci-lint.sh | 2 +- dev/scaletesting/codehostcopy/gitlab.go | 2 +- dev/scaletesting/codehostcopy/runner.go | 2 +- dev/sg/adr/adr.go | 1 + dev/sg/checks.go | 2 +- dev/sg/internal/images/compose.go | 8 +++---- dev/sg/sg_insights.go | 2 +- dev/sg/sg_start.go | 2 +- .../internal/auth/oauth/middleware.go | 1 - .../internal/executorqueue/gitserverproxy.go | 1 - enterprise/dev/ci/internal/ci/changed/diff.go | 2 +- enterprise/internal/authz/gerrit/gerrit.go | 2 +- .../insights/aggregation/aggregation.go | 2 +- .../background/historical_enqueuer.go | 2 -- .../insights/background/queryrunner/search.go | 2 +- .../insights/query/compute_executor.go | 6 +---- .../insights/query/streaming/search.go | 4 +++- .../resolvers/insight_view_resolvers.go | 10 +++------ .../backfill_state_inprogress_handler.go | 2 +- enterprise/internal/insights/store/store.go | 6 ++++- enterprise/internal/rockskip/search.go | 1 - .../adminanalytics/codeintelbylanguage.go | 2 +- .../codeinteltoprepositories.go | 2 +- internal/adminanalytics/fetcher.go | 4 ++-- internal/adminanalytics/repos.go | 2 +- internal/adminanalytics/users.go | 22 +++++++++---------- .../autoindexing/internal/store/scan.go | 4 +--- internal/comby/comby.go | 4 ++-- internal/database/external_accounts_test.go | 5 ----- internal/database/security_event_logs.go | 3 +-- internal/gitserver/gitdomain/exec.go | 6 +---- internal/honey/slice_wrapper.go | 2 +- internal/repos/github_webhook_handler_test.go | 2 +- internal/search/alert/observer.go | 5 ++--- internal/search/backend/horizontal.go | 2 +- .../search/lucky/feeling_lucky_search_job.go | 2 +- 45 files changed, 86 insertions(+), 83 deletions(-) diff --git a/.github/workflows/sg-setup.yml b/.github/workflows/sg-setup.yml index e193a748ee4..992f5448dc5 100644 --- a/.github/workflows/sg-setup.yml +++ b/.github/workflows/sg-setup.yml @@ -24,7 +24,7 @@ jobs: - name: Install Go uses: actions/setup-go@v2 with: - go-version: 1.18.7 + go-version: 1.19.3 - name: Install asdf plugins uses: asdf-vm/actions/install@v1 diff --git a/.golangci.yml b/.golangci.yml index 8573e65f2eb..b49d8ce0bc8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,8 +16,11 @@ linters: - staticcheck - typecheck - unconvert - - unused - - unparam + # Both of these are disabled because they produce a lot of errors. The issues below address these errors + # https://github.com/sourcegraph/sourcegraph/issues/43753 + # https://github.com/sourcegraph/sourcegraph/issues/43755 + #- unused + #- unparam - exportloopref linters-settings: @@ -43,9 +46,15 @@ linters-settings: - exitAfterDefer # Only occurs in auxiliary tools - ifElseChain # Noisy for not much gain - singleCaseSwitch # Noisy for not much gain + unparam: + govet: disable: - composites + staticcheck: + checks: + - "all" + - "-SA1019" #TODO(burmudar): Mostly because of opentracing deprecatio forbidigo: forbid: # Use errors.Newf instead @@ -58,6 +67,9 @@ issues: - path: _test\.go linters: - bodyclose + - unparam + - gosimple + - unused run: timeout: 5m diff --git a/.tool-versions b/.tool-versions index 9d6f86e0ad5..cb2eb57a5b2 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,4 +1,4 @@ -golang 1.18.7 +golang 1.19.3 nodejs 16.7.0 # We're using yarn classic to install yarn 3.x as defined in package.json yarn 1.22.19 diff --git a/client/web/src/nav/GlobalNavbar.tsx b/client/web/src/nav/GlobalNavbar.tsx index df471859838..e0562593b31 100644 --- a/client/web/src/nav/GlobalNavbar.tsx +++ b/client/web/src/nav/GlobalNavbar.tsx @@ -328,7 +328,11 @@ export const GlobalNavbar: React.FunctionComponent/dev/null mkdir -p .bin -version="1.45.2" +version="1.50.1" suffix="${version}-$(go env GOOS)-$(go env GOARCH)" target="$PWD/.bin/golangci-lint-${suffix}" diff --git a/dev/scaletesting/codehostcopy/gitlab.go b/dev/scaletesting/codehostcopy/gitlab.go index b43938de21c..109d48043b6 100644 --- a/dev/scaletesting/codehostcopy/gitlab.go +++ b/dev/scaletesting/codehostcopy/gitlab.go @@ -13,7 +13,7 @@ type GitLabCodeHost struct { c *gitlab.Client } -func NewGitLabCodeHost(ctx context.Context, def *CodeHostDefinition) (*GitLabCodeHost, error) { +func NewGitLabCodeHost(_ context.Context, def *CodeHostDefinition) (*GitLabCodeHost, error) { baseURL, err := url.Parse(def.URL) if err != nil { return nil, err diff --git a/dev/scaletesting/codehostcopy/runner.go b/dev/scaletesting/codehostcopy/runner.go index 358190cc358..871309eb9ea 100644 --- a/dev/scaletesting/codehostcopy/runner.go +++ b/dev/scaletesting/codehostcopy/runner.go @@ -79,7 +79,7 @@ func (r *Runner) Run(ctx context.Context, concurrency int) error { var done int64 total := len(srcRepos) - g := group.NewWithResults[error]().WithMaxConcurrency(20) + g := group.NewWithResults[error]().WithMaxConcurrency(concurrency) for _, repo := range srcRepos { repo := repo g.Go(func() error { diff --git a/dev/sg/adr/adr.go b/dev/sg/adr/adr.go index 7a4ef6aa5be..8ac59ae590f 100644 --- a/dev/sg/adr/adr.go +++ b/dev/sg/adr/adr.go @@ -47,6 +47,7 @@ var ( // // Must be kept in sync with the generator in Create. func VisitAll(adrDir string, visit func(adr ArchitectureDecisionRecord) error) error { + // nolint:staticcheck,gosimple return filepath.WalkDir(adrDir, func(path string, entry fs.DirEntry, err error) error { if entry.IsDir() { return nil diff --git a/dev/sg/checks.go b/dev/sg/checks.go index c1508059dd4..9b80e0a5a86 100644 --- a/dev/sg/checks.go +++ b/dev/sg/checks.go @@ -34,7 +34,7 @@ var checks = map[string]check.CheckFunc{ "asdf": check.CommandOutputContains("asdf", "version"), "git": check.Combine(check.InPath("git"), checkGitVersion(">= 2.34.1")), "yarn": check.Combine(check.InPath("yarn"), checkYarnVersion("~> 1.22.4")), - "go": check.Combine(check.InPath("go"), checkGoVersion("~> 1.18.7")), + "go": check.Combine(check.InPath("go"), checkGoVersion("~> 1.19.3")), "node": check.Combine(check.InPath("node"), check.CommandOutputContains(`node -e "console.log(\"foobar\")"`, "foobar")), "rust": check.Combine(check.InPath("cargo"), check.CommandOutputContains(`cargo version`, "1.58.0")), "docker-installed": check.WrapErrMessage(check.InPath("docker"), "if Docker is installed and the check fails, you might need to start Docker.app and restart terminal and 'sg setup'"), diff --git a/dev/sg/internal/images/compose.go b/dev/sg/internal/images/compose.go index 7ed51277bca..a654e7a0822 100644 --- a/dev/sg/internal/images/compose.go +++ b/dev/sg/internal/images/compose.go @@ -29,14 +29,14 @@ func UpdateCompose(path string, creds credentials.Credentials, pinTag string) er std.Out.WriteNoticef("Checking %q", path) - composeFile, err := os.ReadFile(path) - if err != nil { + composeFile, innerErr := os.ReadFile(path) + if innerErr != nil { return errors.Wrapf(err, "couldn't read %s", path) } checked++ - newComposeFile, err := updateComposeFile(composeFile, creds, pinTag) - if err != nil { + newComposeFile, innerErr := updateComposeFile(composeFile, creds, pinTag) + if innerErr != nil { return err } if newComposeFile == nil { diff --git a/dev/sg/sg_insights.go b/dev/sg/sg_insights.go index bf36902ffea..ccf1405d21c 100644 --- a/dev/sg/sg_insights.go +++ b/dev/sg/sg_insights.go @@ -119,5 +119,5 @@ func decodeIDIntoUniqueViewID(id string) (string, error) { if !strings.Contains(sDecoded, "insight_view") { return "", errors.Newf("decoded id is not an insight_view id: %s", sDecoded) } - return strings.Trim(strings.TrimLeft(sDecoded, "insight_view:"), "\""), nil + return strings.Trim(strings.TrimPrefix(sDecoded, "insight_view:"), "\""), nil } diff --git a/dev/sg/sg_start.go b/dev/sg/sg_start.go index 4481b528129..6c2d08f61d3 100644 --- a/dev/sg/sg_start.go +++ b/dev/sg/sg_start.go @@ -136,7 +136,7 @@ func constructStartCmdLongHelp() string { case "batches": names = append(names, fmt.Sprintf("%s 🦡", name)) default: - names = append(names, fmt.Sprintf("%s", name)) + names = append(names, name) } } sort.Strings(names) diff --git a/enterprise/cmd/frontend/internal/auth/oauth/middleware.go b/enterprise/cmd/frontend/internal/auth/oauth/middleware.go index 4a3ac038fdc..421e3cdab6f 100644 --- a/enterprise/cmd/frontend/internal/auth/oauth/middleware.go +++ b/enterprise/cmd/frontend/internal/auth/oauth/middleware.go @@ -126,7 +126,6 @@ func newOAuthFlowHandler(db database.DB, serviceType string) http.Handler { return } http.Redirect(w, req, "/install-github-app-success", http.StatusFound) - return })) mux.Handle("/get-github-app-installation", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { logger := log.Scoped("get-github-app-installation", "handler for getting github app installations") diff --git a/enterprise/cmd/frontend/internal/executorqueue/gitserverproxy.go b/enterprise/cmd/frontend/internal/executorqueue/gitserverproxy.go index da60719de58..674c34c8b88 100644 --- a/enterprise/cmd/frontend/internal/executorqueue/gitserverproxy.go +++ b/enterprise/cmd/frontend/internal/executorqueue/gitserverproxy.go @@ -43,7 +43,6 @@ func gitserverProxy(gitserverClient GitserverClient, gitPath string) http.Handle Transport: httpcli.InternalClient.Transport, } p.ServeHTTP(w, r) - return }) } diff --git a/enterprise/dev/ci/internal/ci/changed/diff.go b/enterprise/dev/ci/internal/ci/changed/diff.go index 69ecbfb6943..18257df1453 100644 --- a/enterprise/dev/ci/internal/ci/changed/diff.go +++ b/enterprise/dev/ci/internal/ci/changed/diff.go @@ -161,7 +161,7 @@ func ParseDiff(files []string) (diff Diff) { if err == nil { b := make([]byte, 19) // "#!/usr/bin/env bash" = 19 chars _, _ = f.Read(b) - if bytes.Compare(b[0:2], []byte("#!")) == 0 && bytes.Contains(b, []byte("bash")) { + if bytes.Equal(b[0:2], []byte("#!")) && bytes.Contains(b, []byte("bash")) { // If the file starts with a shebang and has "bash" somewhere after, it's most probably // some shell script. diff |= Shell diff --git a/enterprise/internal/authz/gerrit/gerrit.go b/enterprise/internal/authz/gerrit/gerrit.go index 7c10b1ab54a..159f95bd71c 100644 --- a/enterprise/internal/authz/gerrit/gerrit.go +++ b/enterprise/internal/authz/gerrit/gerrit.go @@ -67,7 +67,7 @@ func (p Provider) FetchAccount(ctx context.Context, user *types.User, current [] } func (p Provider) checkAccountsAgainstVerifiedEmails(accts gerrit.ListAccountsResponse, user *types.User, verifiedEmails []string) (*extsvc.Account, bool, error) { - if accts == nil || len(accts) == 0 { + if len(accts) == 0 { return nil, false, nil } for _, email := range verifiedEmails { diff --git a/enterprise/internal/insights/aggregation/aggregation.go b/enterprise/internal/insights/aggregation/aggregation.go index 7efe17b36dd..b148dcf21c1 100644 --- a/enterprise/internal/insights/aggregation/aggregation.go +++ b/enterprise/internal/insights/aggregation/aggregation.go @@ -248,7 +248,7 @@ func (r *searchAggregationResults) Send(event streaming.SearchEvent) { r.tabulator(nil, err) continue } - current, _ := combined[groupKey] + current := combined[groupKey] combined[groupKey] = current + count } } diff --git a/enterprise/internal/insights/background/historical_enqueuer.go b/enterprise/internal/insights/background/historical_enqueuer.go index 9beb84b972c..4a811fa9bd0 100644 --- a/enterprise/internal/insights/background/historical_enqueuer.go +++ b/enterprise/internal/insights/background/historical_enqueuer.go @@ -437,8 +437,6 @@ func (h *historicalEnqueuer) convertJustInTimeInsights(ctx context.Context) { h.logger.Warn("unable to purge jobs for old seriesID", sglog.String("seriesId", oldSeriesId), sglog.Error(err)) } } - - return } func markInsightsComplete(ctx context.Context, completed []itypes.InsightSeries, dataSeriesStore store.DataSeriesStore) { diff --git a/enterprise/internal/insights/background/queryrunner/search.go b/enterprise/internal/insights/background/queryrunner/search.go index 760b43d9d01..6ff6c5208cd 100644 --- a/enterprise/internal/insights/background/queryrunner/search.go +++ b/enterprise/internal/insights/background/queryrunner/search.go @@ -268,7 +268,7 @@ func filterRecordingsBySeriesRepos(ctx context.Context, repoStore discovery.Repo if record.RepoID == nil { continue } - if included := repos[*record.RepoID]; included == true { + if included := repos[*record.RepoID]; included { filteredRecords = append(filteredRecords, record) } } diff --git a/enterprise/internal/insights/query/compute_executor.go b/enterprise/internal/insights/query/compute_executor.go index b8fdee522ed..d4b3482aa83 100644 --- a/enterprise/internal/insights/query/compute_executor.go +++ b/enterprise/internal/insights/query/compute_executor.go @@ -78,11 +78,7 @@ func (c *ComputeExecutor) Execute(ctx context.Context, query, groupBy string, re }) for _, group := range grouped { - if _, ok := groupedValues[group.Value]; ok { - groupedValues[group.Value] += group.Count - } else { - groupedValues[group.Value] = group.Count - } + groupedValues[group.Value] += group.Count } } diff --git a/enterprise/internal/insights/query/streaming/search.go b/enterprise/internal/insights/query/streaming/search.go index 358c74fa20f..f4f1cc43ea2 100644 --- a/enterprise/internal/insights/query/streaming/search.go +++ b/enterprise/internal/insights/query/streaming/search.go @@ -36,7 +36,9 @@ func Search(ctx context.Context, query string, patternType *string, decoder stre return err } if patternType != nil { - req.URL.Query().Add("t", *patternType) + query := req.URL.Query() + query.Add("t", *patternType) + req.URL.RawQuery = query.Encode() } req = req.WithContext(ctx) diff --git a/enterprise/internal/insights/resolvers/insight_view_resolvers.go b/enterprise/internal/insights/resolvers/insight_view_resolvers.go index f7ec6236343..28bf0290034 100644 --- a/enterprise/internal/insights/resolvers/insight_view_resolvers.go +++ b/enterprise/internal/insights/resolvers/insight_view_resolvers.go @@ -511,15 +511,11 @@ func (r *Resolver) CreateLineChartSearchInsight(ctx context.Context, args *graph seriesFillStrategy := makeFillSeriesStrategy(ctx, insightTx, backfiller, r.scheduler, r.insightEnqueuer) - var scoped []types.InsightSeries for _, series := range args.Input.DataSeries { - c, err := createAndAttachSeries(ctx, insightTx, seriesFillStrategy, view, series) + _, err := createAndAttachSeries(ctx, insightTx, seriesFillStrategy, view, series) if err != nil { return nil, errors.Wrap(err, "createAndAttachSeries") } - if len(c.Repositories) > 0 { - scoped = append(scoped, *c) - } } if len(dashboardIds) > 0 { @@ -1300,7 +1296,7 @@ func sortSeriesResolvers(ctx context.Context, seriesOptions types.SeriesDisplayO // First sort lexicographically (ascending) to make sure the ordering is consistent even if some result counts are equal. sort.SliceStable(resolvers, func(i, j int) bool { hasSemVar, result := ascLexSort(resolvers[i].Label(), resolvers[j].Label()) - if hasSemVar == true { + if hasSemVar { return result } return strings.Compare(resolvers[i].Label(), resolvers[j].Label()) < 0 @@ -1324,7 +1320,7 @@ func sortSeriesResolvers(ctx context.Context, seriesOptions types.SeriesDisplayO } else { sort.SliceStable(resolvers, func(i, j int) bool { hasSemVar, result := ascLexSort(resolvers[i].Label(), resolvers[j].Label()) - if hasSemVar == true { + if hasSemVar { return !result } return strings.Compare(resolvers[i].Label(), resolvers[j].Label()) > 0 diff --git a/enterprise/internal/insights/scheduler/backfill_state_inprogress_handler.go b/enterprise/internal/insights/scheduler/backfill_state_inprogress_handler.go index dd00e5546b1..101ab9a371c 100644 --- a/enterprise/internal/insights/scheduler/backfill_state_inprogress_handler.go +++ b/enterprise/internal/insights/scheduler/backfill_state_inprogress_handler.go @@ -101,7 +101,7 @@ func (h *inProgressHandler) Handle(ctx context.Context, logger log.Logger, recor Value: series.SampleIntervalValue, }, series.CreatedAt.Truncate(time.Hour*24)) - for true { + for { repoId, more, finish := itr.NextWithFinish() if !more { break diff --git a/enterprise/internal/insights/store/store.go b/enterprise/internal/insights/store/store.go index 5a9eb56fb3a..bddb77e76b5 100644 --- a/enterprise/internal/insights/store/store.go +++ b/enterprise/internal/insights/store/store.go @@ -184,7 +184,7 @@ func (s *Store) SeriesPoints(ctx context.Context, opts SeriesPointsOpts) ([]Seri func (s *Store) LoadSeriesInMem(ctx context.Context, opts SeriesPointsOpts) (points []SeriesPoint, err error) { denylist, err := s.permStore.GetUnauthorizedRepoIDs(ctx) if err != nil { - return []SeriesPoint{}, err + return nil, err } denyBitmap := roaring.New() for _, id := range denylist { @@ -255,6 +255,10 @@ func (s *Store) LoadSeriesInMem(ctx context.Context, opts SeriesPointsOpts) (poi return nil }) + if err != nil { + return nil, err + } + pointsMap := make(map[string]*SeriesPoint) captureValues := make(map[string]struct{}) diff --git a/enterprise/internal/rockskip/search.go b/enterprise/internal/rockskip/search.go index 19d6d6dc01c..eb39ac513c3 100644 --- a/enterprise/internal/rockskip/search.go +++ b/enterprise/internal/rockskip/search.go @@ -47,7 +47,6 @@ func (s *Service) Search(ctx context.Context, args search.SymbolsParameters) (_ err = errors.Newf("Still processing symbols ([more details](https://docs.sourcegraph.com/code_navigation/explanations/rockskip)). Estimated completion: %s.", status.Remaining()) } } - return }() } diff --git a/internal/adminanalytics/codeintelbylanguage.go b/internal/adminanalytics/codeintelbylanguage.go index 0afebabf152..4d1dc4c2846 100644 --- a/internal/adminanalytics/codeintelbylanguage.go +++ b/internal/adminanalytics/codeintelbylanguage.go @@ -21,7 +21,7 @@ func (s *CodeIntelByLanguage) Count() float64 { return s.Count_ } func GetCodeIntelByLanguage(ctx context.Context, db database.DB, cache bool, dateRange string) ([]*CodeIntelByLanguage, error) { cacheKey := fmt.Sprintf(`CodeIntelByLanguage:%s`, dateRange) - if cache == true { + if cache { if nodes, err := getArrayFromCache[CodeIntelByLanguage](cacheKey); err == nil { return nodes, nil } diff --git a/internal/adminanalytics/codeinteltoprepositories.go b/internal/adminanalytics/codeinteltoprepositories.go index 1761c699e4d..c1d51941430 100644 --- a/internal/adminanalytics/codeinteltoprepositories.go +++ b/internal/adminanalytics/codeinteltoprepositories.go @@ -28,7 +28,7 @@ func (s *CodeIntelTopRepositories) HasPrecise() bool { return s.HasPrecise_ } func GetCodeIntelTopRepositories(ctx context.Context, db database.DB, cache bool, dateRange string) ([]*CodeIntelTopRepositories, error) { cacheKey := fmt.Sprintf(`CodeIntelTopRepositories:%s`, dateRange) - if cache == true { + if cache { if nodes, err := getArrayFromCache[CodeIntelTopRepositories](cacheKey); err == nil { return nodes, nil } diff --git a/internal/adminanalytics/fetcher.go b/internal/adminanalytics/fetcher.go index 6efff9d4b7e..496ae216224 100644 --- a/internal/adminanalytics/fetcher.go +++ b/internal/adminanalytics/fetcher.go @@ -42,7 +42,7 @@ func (n *AnalyticsNode) RegisteredUsers() float64 { return n.Data.RegisteredUser func (f *AnalyticsFetcher) Nodes(ctx context.Context) ([]*AnalyticsNode, error) { cacheKey := fmt.Sprintf(`%s:%s:%s:%s`, f.group, f.dateRange, f.grouping, "nodes") - if f.cache == true { + if f.cache { if nodes, err := getArrayFromCache[AnalyticsNode](cacheKey); err == nil { return nodes, nil } @@ -137,7 +137,7 @@ func (s *AnalyticsSummary) TotalRegisteredUsers() float64 { return s.Data.TotalR func (f *AnalyticsFetcher) Summary(ctx context.Context) (*AnalyticsSummary, error) { cacheKey := fmt.Sprintf(`%s:%s:%s:%s`, f.group, f.dateRange, f.grouping, "summary") - if f.cache == true { + if f.cache { if summary, err := getItemFromCache[AnalyticsSummary](cacheKey); err == nil { return summary, nil } diff --git a/internal/adminanalytics/repos.go b/internal/adminanalytics/repos.go index 2b58904f268..e22ec697095 100644 --- a/internal/adminanalytics/repos.go +++ b/internal/adminanalytics/repos.go @@ -15,7 +15,7 @@ type Repos struct { func (r *Repos) Summary(ctx context.Context) (*ReposSummary, error) { cacheKey := "Repos:Summary" - if r.Cache == true { + if r.Cache { if summary, err := getItemFromCache[ReposSummary](cacheKey); err == nil { return summary, nil } diff --git a/internal/adminanalytics/users.go b/internal/adminanalytics/users.go index 608b36289f8..8a4aa1d7a44 100644 --- a/internal/adminanalytics/users.go +++ b/internal/adminanalytics/users.go @@ -38,11 +38,11 @@ func (s *Users) Activity() (*AnalyticsFetcher, error) { var ( frequencyQuery = ` WITH user_days_used AS ( - SELECT + SELECT CASE WHEN user_id = 0 THEN anonymous_user_id ELSE CAST(user_id AS TEXT) END AS user_id, - COUNT(DISTINCT DATE(timestamp)) AS days_used + COUNT(DISTINCT DATE(timestamp)) AS days_used FROM event_logs - WHERE + WHERE DATE(timestamp) %s AND %s GROUP BY 1 @@ -53,8 +53,8 @@ var ( GROUP BY 1 ), days_used_total_frequency AS ( - SELECT - days_used_frequency.days_used, + SELECT + days_used_frequency.days_used, SUM(more_days_used_frequency.frequency) AS frequency FROM days_used_frequency LEFT JOIN days_used_frequency AS more_days_used_frequency @@ -65,9 +65,9 @@ var ( SELECT MAX(frequency) AS max_frequency FROM days_used_total_frequency ) - SELECT - days_used, - frequency, + SELECT + days_used, + frequency, frequency * 100.00 / COALESCE(max_frequency, 1) AS percentage FROM days_used_total_frequency, max_days_used_total_frequency ORDER BY 1 ASC; @@ -76,7 +76,7 @@ var ( func (f *Users) Frequencies(ctx context.Context) ([]*UsersFrequencyNode, error) { cacheKey := fmt.Sprintf("Users:%s:%s", "Frequencies", f.DateRange) - if f.Cache == true { + if f.Cache { if nodes, err := getArrayFromCache[UsersFrequencyNode](cacheKey); err == nil { return nodes, nil } @@ -138,11 +138,11 @@ func (n *UsersFrequencyNode) Percentage() float64 { return n.Data.Percentage } var ( mauQuery = ` - SELECT + SELECT TO_CHAR(timestamp, 'YYYY-MM') AS date, COUNT(DISTINCT CASE WHEN user_id = 0 THEN anonymous_user_id ELSE CAST(user_id AS TEXT) END) AS count FROM event_logs - WHERE + WHERE timestamp BETWEEN %s AND %s AND %s GROUP BY 1 diff --git a/internal/codeintel/autoindexing/internal/store/scan.go b/internal/codeintel/autoindexing/internal/store/scan.go index 6bb36569ea9..d264385953f 100644 --- a/internal/codeintel/autoindexing/internal/store/scan.go +++ b/internal/codeintel/autoindexing/internal/store/scan.go @@ -110,9 +110,7 @@ func scanIndexWithCount(s dbutil.Scanner) (index types.Index, count int, err err return index, 0, err } - for _, entry := range executionLogs { - index.ExecutionLogs = append(index.ExecutionLogs, entry) - } + index.ExecutionLogs = append(index.ExecutionLogs, executionLogs...) return index, count, nil } diff --git a/internal/comby/comby.go b/internal/comby/comby.go index 904b5f1598b..f3d954bd184 100644 --- a/internal/comby/comby.go +++ b/internal/comby/comby.go @@ -204,8 +204,8 @@ func StartAndWaitForCompletion(cmd *exec.Cmd) error { if err := cmd.Wait(); err != nil { if len(b.Bytes()) > 0 { - log15.Error("failed to execute comby command", "error", string(b.Bytes())) - msg := fmt.Sprintf("failed to wait for executing comby command: comby error: %s", b.Bytes()) + log15.Error("failed to execute comby command", "error", b.String()) + msg := fmt.Sprintf("failed to wait for executing comby command: comby error: %s", b.String()) return errors.Wrap(err, msg) } var stderr string diff --git a/internal/database/external_accounts_test.go b/internal/database/external_accounts_test.go index cd51f257eea..cf264ab35c7 100644 --- a/internal/database/external_accounts_test.go +++ b/internal/database/external_accounts_test.go @@ -659,11 +659,6 @@ func TestExternalAccounts_UpdateGitHubAppInstallations(t *testing.T) { require.NoError(t, err) require.Equal(t, 3, len(accts)) - acctIds := []int32{} - for _, acct := range accts { - acctIds = append(acctIds, acct.ID) - } - err = db.UserExternalAccounts().UpdateGitHubAppInstallations(ctx, acct, installations) require.NoError(t, err) diff --git a/internal/database/security_event_logs.go b/internal/database/security_event_logs.go index 4282673fa2a..39e74b39004 100644 --- a/internal/database/security_event_logs.go +++ b/internal/database/security_event_logs.go @@ -3,7 +3,6 @@ package database import ( "context" "encoding/json" - "fmt" "strings" "time" @@ -61,7 +60,7 @@ func (e *SecurityEvent) marshalArgumentAsJSON() string { if e.Argument == nil { return "{}" } - return fmt.Sprintf("%s", e.Argument) + return string(e.Argument) } // SecurityEventLogsStore provides persistence for security events. diff --git a/internal/gitserver/gitdomain/exec.go b/internal/gitserver/gitdomain/exec.go index e1ed05d9592..41fc7460324 100644 --- a/internal/gitserver/gitdomain/exec.go +++ b/internal/gitserver/gitdomain/exec.go @@ -98,11 +98,7 @@ func isAllowedDiffArg(arg string) bool { // make sure that arg is not a local file _, err := os.Stat(arg) - if os.IsNotExist(err) { - return true - } - - return false + return os.IsNotExist(err) } // isAllowedGitArg checks if the arg is allowed. diff --git a/internal/honey/slice_wrapper.go b/internal/honey/slice_wrapper.go index 133372105ef..46b8951b292 100644 --- a/internal/honey/slice_wrapper.go +++ b/internal/honey/slice_wrapper.go @@ -11,7 +11,7 @@ import ( type sliceWrapper []any func (s sliceWrapper) MarshalJSON() ([]byte, error) { - if s == nil || len(s) == 0 { + if len(s) == 0 { return nil, nil } diff --git a/internal/repos/github_webhook_handler_test.go b/internal/repos/github_webhook_handler_test.go index 7be4cfb345e..e04a8dd5fe1 100644 --- a/internal/repos/github_webhook_handler_test.go +++ b/internal/repos/github_webhook_handler_test.go @@ -47,7 +47,7 @@ func TestGitHubWebhookHandle(t *testing.T) { t.Fatal(err) } - conn := *&schema.GitHubConnection{ + conn := schema.GitHubConnection{ Url: "https://github.com", Token: "token", Repos: []string{"owner/name"}, diff --git a/internal/search/alert/observer.go b/internal/search/alert/observer.go index 943fba5df55..8b2e4ec0294 100644 --- a/internal/search/alert/observer.go +++ b/internal/search/alert/observer.go @@ -212,7 +212,7 @@ type alertKind string const ( smartSearchAdditionalResults alertKind = "smart-search-additional-results" - smartSearchPureResults = "smart-search-pure-results" + smartSearchPureResults alertKind = "smart-search-pure-results" ) func (o *Observer) errorToAlert(ctx context.Context, err error) (*search.Alert, error) { @@ -256,8 +256,7 @@ func (o *Observer) errorToAlert(ctx context.Context, err error) (*search.Alert, } if errors.As(err, &mErr) { - var a *search.Alert - a = AlertForMissingRepoRevs(mErr.Missing) + a := AlertForMissingRepoRevs(mErr.Missing) a.Priority = 6 return a, nil } diff --git a/internal/search/backend/horizontal.go b/internal/search/backend/horizontal.go index f9e2914baea..47a175cad62 100644 --- a/internal/search/backend/horizontal.go +++ b/internal/search/backend/horizontal.go @@ -205,7 +205,7 @@ func (s *HorizontalSearcher) streamSearchExperimentalRanking(ctx context.Context endpoints := make([]string, 0, len(clients)) for endpoint := range clients { - endpoints = append(endpoints, endpoint) + endpoints = append(endpoints, endpoint) //nolint:staticcheck } siteConfig := newRankingSiteConfig(conf.Get().SiteConfiguration) diff --git a/internal/search/lucky/feeling_lucky_search_job.go b/internal/search/lucky/feeling_lucky_search_job.go index 3e7fd3d969b..0dba0360d7d 100644 --- a/internal/search/lucky/feeling_lucky_search_job.go +++ b/internal/search/lucky/feeling_lucky_search_job.go @@ -220,7 +220,7 @@ func (n *notifier) New(count int) error { if count == limits.DefaultMaxSearchResultsStreaming { resultCountString = fmt.Sprintf("%d+ results", count) } else if count == 1 { - resultCountString = fmt.Sprintf("1 result") + resultCountString = "1 result" } else { resultCountString = fmt.Sprintf("%d additional results", count) }