Skip to content

Commit 92f0bff

Browse files
committed
Enable nakedret golangci-lint linter
Summary: TSIA Test Plan: `GO_ENABLED=0 golangci-lint run` reports no errors Reviewers: zasgar Reviewed By: zasgar Differential Revision: https://phab.corp.pixielabs.ai/D7908 GitOrigin-RevId: 2ce6dc2
1 parent e08bdca commit 92f0bff

7 files changed

Lines changed: 28 additions & 24 deletions

File tree

.golangci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ linters:
1919
- ineffassign
2020
- makezero
2121
- misspell
22+
- nakedret
2223
- nolintlint
2324
- staticcheck
2425
- structcheck
@@ -39,3 +40,5 @@ linters:
3940
linters-settings:
4041
goimports:
4142
local-prefixes: pixielabs.ai
43+
nakedret:
44+
max-func-lines: 0

src/cloud/api/ptproxy/vizier_pt_proxy.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,11 @@ func (v *VizierPassThroughProxy) DebugPods(req *pl_api_vizierpb.DebugPodsRequest
9595
return rp.Run()
9696
}
9797

98-
func getCredsFromCtx(ctx context.Context) (token string, claim *jwt.JWTClaims, err error) {
99-
var aCtx *authcontext.AuthContext
100-
aCtx, err = authcontext.FromContext(ctx)
98+
func getCredsFromCtx(ctx context.Context) (string, *jwt.JWTClaims, error) {
99+
aCtx, err := authcontext.FromContext(ctx)
101100
if err != nil {
102-
return
101+
return "", nil, err
103102
}
104103

105-
token = aCtx.AuthToken
106-
claim = aCtx.Claims
107-
return
104+
return aCtx.AuthToken, aCtx.Claims, nil
108105
}

src/cloud/indexer/indexer_server.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,24 @@ func newVZMgrClient() (vzmgrpb.VZMgrServiceClient, error) {
5050
return vzmgrpb.NewVZMgrServiceClient(vzmgrChannel), nil
5151
}
5252

53-
func createStanNatsConnection(clientID string) (nc *nats.Conn, sc stan.Conn, err error) {
54-
nc, err = nats.Connect(viper.GetString("nats_url"),
53+
func createStanNatsConnection(clientID string) (*nats.Conn, stan.Conn, error) {
54+
nc, err := nats.Connect(viper.GetString("nats_url"),
5555
nats.ClientCert(viper.GetString("client_tls_cert"), viper.GetString("client_tls_key")),
5656
nats.RootCAs(viper.GetString("tls_ca_cert")))
5757
if err != nil {
5858
log.WithError(err).Error("NATS connection failed")
59-
return
59+
return nil, nil, err
6060
}
61-
sc, err = stan.Connect(viper.GetString("stan_cluster"),
61+
sc, err := stan.Connect(viper.GetString("stan_cluster"),
6262
clientID, stan.NatsConn(nc),
6363
stan.SetConnectionLostHandler(func(_ stan.Conn, err error) {
6464
log.WithError(err).Fatal("STAN Connection Lost")
6565
}))
6666
if err != nil {
6767
log.WithError(err).Error("STAN connection failed")
68+
return nil, nil, err
6869
}
69-
return
70+
return nc, sc, nil
7071
}
7172

7273
func getESHTTPSClient() (*http.Client, error) {

src/cloud/vzconn/vzconn_server.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,24 @@ func newVZMgrClients() (vzmgrpb.VZMgrServiceClient, vzmgrpb.VZDeploymentServiceC
4141
return vzmgrpb.NewVZMgrServiceClient(vzmgrChannel), vzmgrpb.NewVZDeploymentServiceClient(vzmgrChannel), nil
4242
}
4343

44-
func createStanNatsConnection(clientID string) (nc *nats.Conn, sc stan.Conn, err error) {
45-
nc, err = nats.Connect(viper.GetString("nats_url"),
44+
func createStanNatsConnection(clientID string) (*nats.Conn, stan.Conn, error) {
45+
nc, err := nats.Connect(viper.GetString("nats_url"),
4646
nats.ClientCert(viper.GetString("client_tls_cert"), viper.GetString("client_tls_key")),
4747
nats.RootCAs(viper.GetString("tls_ca_cert")))
4848
if err != nil {
4949
log.WithError(err).Error("NATS connection failed")
50-
return
50+
return nil, nil, err
5151
}
52-
sc, err = stan.Connect(viper.GetString("stan_cluster"),
52+
sc, err := stan.Connect(viper.GetString("stan_cluster"),
5353
clientID, stan.NatsConn(nc),
5454
stan.SetConnectionLostHandler(func(_ stan.Conn, err error) {
5555
log.WithError(err).Fatal("STAN Connection Lost")
5656
}))
5757
if err != nil {
5858
log.WithError(err).Error("STAN connection failed")
59+
return nil, nil, err
5960
}
60-
return
61+
return nc, sc, nil
6162
}
6263

6364
func main() {

src/pixie_cli/pkg/components/input_field.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,8 @@ func (i *InputField) Focus(func(p tview.Primitive)) {
374374
// stringWidth returns the number of horizontal cells needed to print the given
375375
// text. It splits the text into its grapheme clusters, calculates each
376376
// cluster's width, and adds them up to a total.
377-
func stringWidth(text string) (width int) {
377+
func stringWidth(text string) int {
378+
width := 0
378379
g := uniseg.NewGraphemes(text)
379380
for g.Next() {
380381
var chWidth int
@@ -386,7 +387,7 @@ func stringWidth(text string) (width int) {
386387
}
387388
width += chWidth
388389
}
389-
return
390+
return width
390391
}
391392

392393
// iterateString iterates through the given string one printed character at a

src/pixie_cli/pkg/components/status.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ var (
1111
statusErr = "\u2715"
1212
)
1313

14-
func computePadding(s string, pad int) (padS int, padE int) {
14+
func computePadding(s string, pad int) (int, int) {
15+
var padS, padE int
1516
pad -= len([]rune(s))
1617
if pad < 0 {
1718
pad = 0
@@ -22,7 +23,7 @@ func computePadding(s string, pad int) (padS int, padE int) {
2223
if pad%2 != 0 {
2324
padE = padS + 1
2425
}
25-
return
26+
return padS, padE
2627
}
2728

2829
// StatusOK prints out the default OK symbol, center padded to the size specified.

src/vizier/services/cloud_connector/bridge/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,8 @@ func (s *Bridge) publishBridgeSync(stream vzconnpb.VZConnService_NATSBridgeClien
937937
return nil
938938
}
939939

940-
func (s *Bridge) generateHeartbeats(done <-chan bool) (hbCh chan *cvmsgspb.VizierHeartbeat) {
941-
hbCh = make(chan *cvmsgspb.VizierHeartbeat)
940+
func (s *Bridge) generateHeartbeats(done <-chan bool) chan *cvmsgspb.VizierHeartbeat {
941+
hbCh := make(chan *cvmsgspb.VizierHeartbeat)
942942

943943
sendHeartbeat := func() {
944944
addr, port, err := s.vzInfo.GetAddress()
@@ -992,7 +992,7 @@ func (s *Bridge) generateHeartbeats(done <-chan bool) (hbCh chan *cvmsgspb.Vizie
992992
}
993993
}
994994
}()
995-
return
995+
return hbCh
996996
}
997997

998998
func (s *Bridge) currentStatus() cvmsgspb.VizierStatus {

0 commit comments

Comments
 (0)