Skip to content

Commit 6124ca1

Browse files
committed
Fix gocritic issues in our code base
Summary: This fixes all known gocritic issues. Test Plan: existing Reviewers: michelle, vihang Reviewed By: michelle Differential Revision: https://phab.corp.pixielabs.ai/D7887 GitOrigin-RevId: 70a5ed2
1 parent 39c00b6 commit 6124ca1

32 files changed

Lines changed: 119 additions & 111 deletions

File tree

src/carnot/docstring/pkg/docstring.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ func processRemainingDesc(lines *[]string, i int, tabChar string, argDoc *docspb
219219
break
220220
}
221221
if hasContent((*lines)[i]) {
222-
argDoc.Desc = argDoc.Desc + " " + strings.Trim((*lines)[i], tabChar)
222+
argDoc.Desc += " " + strings.Trim((*lines)[i], tabChar)
223223
} else {
224-
argDoc.Desc = argDoc.Desc + "\n"
224+
argDoc.Desc += "\n"
225225
}
226226
i++
227227
}
@@ -423,22 +423,23 @@ func parseDocstringAndWrite(outDocs *docspb.StructuredDocs, rawDocstring string,
423423
}
424424
genDocString.body.Name = name
425425

426-
if topic == PixieMutation {
426+
switch topic {
427+
case PixieMutation:
427428
outDocs.MutationDocs = append(outDocs.MutationDocs, &docspb.MutationDoc{
428429
Body: genDocString.body,
429430
FuncDoc: genDocString.function,
430431
})
431-
} else if topic == TracepointDecorator {
432+
case TracepointDecorator:
432433
outDocs.TracepointDecoratorDocs = append(outDocs.TracepointDecoratorDocs, &docspb.TracepointDecoratorDoc{
433434
Body: genDocString.body,
434435
FuncDoc: genDocString.function,
435436
})
436-
} else if topic == TracepointFields {
437+
case TracepointFields:
437438
outDocs.TracepointFieldDocs = append(outDocs.TracepointFieldDocs, &docspb.TracepointFieldDoc{
438439
Body: genDocString.body,
439440
FuncDoc: genDocString.function,
440441
})
441-
} else if topic == DataFrameOps {
442+
case DataFrameOps:
442443
body := genDocString.body
443444
if len(opname) > 0 {
444445
body.Name = opname
@@ -448,12 +449,12 @@ func parseDocstringAndWrite(outDocs *docspb.StructuredDocs, rawDocstring string,
448449
Body: body,
449450
FuncDoc: genDocString.function,
450451
})
451-
} else if topic == CompileTimeFns {
452+
case CompileTimeFns:
452453
outDocs.CompileFnDocs = append(outDocs.CompileFnDocs, &docspb.CompileFnDoc{
453454
Body: genDocString.body,
454455
FuncDoc: genDocString.function,
455456
})
456-
} else {
457+
default:
457458
return fmt.Errorf("topic not found %s", topic)
458459
}
459460

src/cloud/api/controller/cluster_name.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88
// PrettifyClusterName uses heuristics to try to generate a better looking cluster name.
99
func PrettifyClusterName(name string, expanded bool) string {
1010
name = strings.ToLower(name)
11-
if strings.HasPrefix(name, "gke") {
11+
switch {
12+
case strings.HasPrefix(name, "gke"):
1213
splits := strings.Split(name, "_")
1314
// GKE names are <gke>_<project>_<region>_<cluster_name>_<our suffix>
1415
if len(splits) > 3 && len(splits[3]) > 0 {
@@ -19,7 +20,7 @@ func PrettifyClusterName(name string, expanded bool) string {
1920
}
2021
return name
2122
}
22-
} else if strings.HasPrefix(name, "arn") {
23+
case strings.HasPrefix(name, "arn"):
2324
// EKS names are "ARN::::CLUSTER/NAME"
2425
splits := strings.Split(name, ":")
2526
if len(splits) > 0 && len(splits[len(splits)-1]) > 0 {
@@ -30,7 +31,7 @@ func PrettifyClusterName(name string, expanded bool) string {
3031
}
3132
return fmt.Sprintf("eks:%s", eksName)
3233
}
33-
} else if strings.HasPrefix(name, "aks-") {
34+
case strings.HasPrefix(name, "aks-"):
3435
return fmt.Sprintf("aks:%s", strings.TrimPrefix(name, "aks-"))
3536
}
3637
return name

src/cloud/artifact_tracker/controller/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ func (s *Server) GetArtifactList(ctx context.Context, in *apb.GetArtifactListReq
8383
var rows *sqlx.Rows
8484
var err error
8585
if limit != 0 && limit != -1 {
86-
query = query + " LIMIT $3;"
86+
query += " LIMIT $3;"
8787
rows, err = s.db.Queryx(query, name, at, limit)
8888
} else {
89-
query = query + ";"
89+
query += ";"
9090
rows, err = s.db.Queryx(query, name, at)
9191
}
9292

src/cloud/auth/auth_server.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,18 @@ func main() {
5959

6060
authProvider := viper.GetString("oauth_provider")
6161

62-
if authProvider == "auth0" {
62+
switch authProvider {
63+
case "auth0":
6364
a, err = controllers.NewAuth0Connector(controllers.NewAuth0Config())
6465
if err != nil {
6566
log.WithError(err).Fatal("Failed to initialize Auth0")
6667
}
67-
} else if authProvider == "hydra" {
68+
case "hydra":
6869
a, err = controllers.NewHydraKratosConnector()
6970
if err != nil {
7071
log.WithError(err).Fatal("Failed to initialize hydraKratosConnector")
7172
}
72-
} else {
73+
default:
7374
log.Fatalf("Cannot initialize authProvider '%s'. Only 'auth0' and 'hydra' are supported.", authProvider)
7475
}
7576

src/cloud/autocomplete/autocomplete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ func (cmd *Command) ToFormatString(action cloudapipb.AutocompleteActionType, s S
428428
} else {
429429
// Move the cursor to the next invalid tabstop.
430430
cmd.TabStops[curTabStop].Value = strings.Replace(cmd.TabStops[curTabStop].Value, CursorMarker, "", 1)
431-
cmd.TabStops[nextInvalidTabStop].Value = cmd.TabStops[nextInvalidTabStop].Value + CursorMarker
431+
cmd.TabStops[nextInvalidTabStop].Value += CursorMarker
432432
curTabStop = nextInvalidTabStop
433433
}
434434
}
@@ -512,7 +512,7 @@ func (cmd *Command) processTabStops() (int, int, map[int]bool) {
512512

513513
if curTabStop == -1 { // For some reason, if there is no cursor, we should put it at the very end.
514514
curTabStop = len(cmd.TabStops) - 1
515-
cmd.TabStops[curTabStop].Value = cmd.TabStops[curTabStop].Value + CursorMarker
515+
cmd.TabStops[curTabStop].Value += CursorMarker
516516
}
517517
if nextInvalidTabStop == -1 { // All tabstops are valid.
518518
nextInvalidTabStop = len(cmd.TabStops) - 1

src/cloud/project_manager/controller/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (s *Server) GetProjectForOrg(ctx context.Context, req *uuidpb.UUID) (*proje
131131
func (s *Server) GetProjectByName(ctx context.Context, req *projectmanagerpb.GetProjectByNameRequest) (*projectmanagerpb.ProjectInfo, error) {
132132
pn := strings.ToLower(req.ProjectName)
133133

134-
if len(pn) <= 0 {
134+
if len(pn) == 0 {
135135
return nil, status.Error(codes.InvalidArgument, "project name is a required argument")
136136
}
137137

src/cloud/shared/esutils/index.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,8 @@ func getSettingsToUpdate(expected map[string]interface{}, actual map[string]inte
178178
if needsUpdate {
179179
toUpdate[k] = newVal
180180
}
181-
} else {
182-
// Elastic will convert numbers and floats to strings sometimes,
183-
// so check the string version of the expected val as well.
184-
if expectedVal != actualVal && fmt.Sprint(expectedVal) != actualVal {
185-
toUpdate[k] = expectedVal
186-
}
181+
} else if expectedVal != actualVal && fmt.Sprint(expectedVal) != actualVal {
182+
toUpdate[k] = expectedVal
187183
}
188184
}
189185
return len(toUpdate) > 0, toUpdate

src/cloud/shared/esutils/index_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,12 @@ func init() {
554554
func copyIgnoredSettingsPaths(expected map[string]interface{}, actual map[string]interface{}, currentPath string) {
555555
for k, v := range actual {
556556
path := strings.Join([]string{currentPath, k}, ".")
557-
switch v.(type) {
557+
switch tv := v.(type) {
558558
case map[string]interface{}:
559559
if _, ok := expected[k]; !ok || expected[k] == nil {
560560
expected[k] = make(map[string]interface{})
561561
}
562-
copyIgnoredSettingsPaths(expected[k].(map[string]interface{}), v.(map[string]interface{}), path)
562+
copyIgnoredSettingsPaths(expected[k].(map[string]interface{}), tv, path)
563563
default:
564564
if _, ok := settingsIgnorePaths[path]; !ok {
565565
continue

src/cloud/shared/vzutils/vzwatcher_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,17 @@ func TestVzWatcher(t *testing.T) {
8989
w.RegisterVizierHandler(func(id uuid.UUID, orgID uuid.UUID, uid string) error {
9090
defer wg.Done()
9191

92-
if id == existingVzID {
92+
switch id {
93+
case existingVzID:
9394
assert.Equal(t, existingOrgID, orgID)
9495
assert.Equal(t, existingK8sUID, uid)
9596
if test.expectError {
9697
return errors.New("Some error")
9798
}
98-
} else if id == newVzID {
99+
case newVzID:
99100
assert.Equal(t, newOrgID, orgID)
100101
assert.Equal(t, newK8sUID, uid)
101-
} else {
102+
default:
102103
t.Fatal("Called Vizier handler with unexpected vizier")
103104
}
104105
return nil

src/cloud/vzmgr/controller/server.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,9 +1017,6 @@ func (s *Server) ProvisionOrClaimVizier(ctx context.Context, orgID uuid.UUID, us
10171017
var clusterID uuid.UUID
10181018
inputName := strings.TrimSpace(clusterName)
10191019

1020-
generateRandomName := func(i int) string {
1021-
return namesgenerator.GetRandomName(i)
1022-
}
10231020
generateFromGivenName := func(i int) string {
10241021
name := inputName
10251022
if i > 0 {
@@ -1068,7 +1065,7 @@ func (s *Server) ProvisionOrClaimVizier(ctx context.Context, orgID uuid.UUID, us
10681065
}
10691066
}
10701067

1071-
generateNameFunc := generateRandomName
1068+
generateNameFunc := namesgenerator.GetRandomName
10721069
if inputName != "" {
10731070
generateNameFunc = generateFromGivenName
10741071
}

0 commit comments

Comments
 (0)