Skip to content

Commit dcb4415

Browse files
committed
Fixed static check failures
1 parent e6d5dde commit dcb4415

File tree

2 files changed

+11
-30
lines changed

2 files changed

+11
-30
lines changed

buildtools/cli.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,10 @@ func GetCommands() []cli.Command {
456456
// so we can capture user-provided flags consistently in one place for all build commands.
457457
func decorateWithFlagCapture(cmds []cli.Command) []cli.Command {
458458
for i := range cmds {
459-
name := cmds[i].Name
460-
aliases := append([]string(nil), cmds[i].Aliases...)
461459
skipFlagParsing := cmds[i].SkipFlagParsing
462460
origBefore := cmds[i].Before
463461
cmds[i].Before = func(c *cli.Context) error {
464-
captureUserFlagsForMetrics(c, name, aliases, skipFlagParsing)
462+
captureUserFlagsForMetrics(c, skipFlagParsing)
465463
if origBefore != nil {
466464
return origBefore(c)
467465
}
@@ -473,7 +471,7 @@ func decorateWithFlagCapture(cmds []cli.Command) []cli.Command {
473471

474472
// captureUserFlagsForMetrics extracts flag names as provided by the end-user for the given command
475473
// and records them for usage metrics. Works even when SkipFlagParsing is true by scanning os.Args.
476-
func captureUserFlagsForMetrics(c *cli.Context, cmdName string, aliases []string, skipFlagParsing bool) {
474+
func captureUserFlagsForMetrics(c *cli.Context, skipFlagParsing bool) {
477475
flagSet := map[string]struct{}{}
478476

479477
if !skipFlagParsing {
@@ -513,15 +511,6 @@ func captureUserFlagsForMetrics(c *cli.Context, cmdName string, aliases []string
513511
commands.SetContextFlags(flags)
514512
}
515513

516-
func containsString(list []string, target string) bool {
517-
for _, s := range list {
518-
if s == target {
519-
return true
520-
}
521-
}
522-
return false
523-
}
524-
525514
func MvnCmd(c *cli.Context) (err error) {
526515
if show, err := cliutils.ShowCmdHelpIfNeeded(c, c.Args()); show || err != nil {
527516
return err

metrics_visibility_test.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"net/http"
77
"net/http/httptest"
88
"os"
9-
"sort"
10-
"strings"
119
"testing"
1210
"time"
1311

@@ -79,18 +77,6 @@ func startVisMockServer(t *testing.T) (*httptest.Server, chan visReq) {
7977
return srv, ch
8078
}
8179

82-
func sortCSV(csv string) string {
83-
if csv == "" {
84-
return ""
85-
}
86-
parts := strings.Split(csv, ",")
87-
for i := range parts {
88-
parts[i] = strings.TrimSpace(parts[i])
89-
}
90-
sort.Strings(parts)
91-
return strings.Join(parts, ",")
92-
}
93-
9480
func TestVisibilitySendUsage_RtCurl_E2E(t *testing.T) {
9581
srv, ch := startMockServer(t)
9682
defer srv.Close()
@@ -187,8 +173,9 @@ func TestVisibilitySendUsage_RtPing_Flags(t *testing.T) {
187173
}
188174

189175
// Run ping with a flag to assert capture
190-
if err := jf.Exec("rt", "ping", "--server-id", "mock"); err != nil {
191-
// ping may fail in some contexts; metrics should still be sent
176+
err := jf.Exec("rt", "ping", "--server-id", "mock")
177+
if err != nil {
178+
t.Logf("jf exec failed: %v", err)
192179
}
193180

194181
// Assert metric was posted with expected flags
@@ -260,7 +247,12 @@ func TestVisibility_GoBuild_Flags(t *testing.T) {
260247
t.Fatalf("write go.yaml: %v", err)
261248
}
262249
cwd, _ := os.Getwd()
263-
defer os.Chdir(cwd)
250+
defer func(dir string) {
251+
err := os.Chdir(dir)
252+
if err != nil {
253+
t.Fatalf("Failed to restore working directory: %v", err)
254+
}
255+
}(cwd)
264256
_ = os.Chdir(projDir)
265257

266258
// Run a buildtools command (go build) with flags; ignore execution error

0 commit comments

Comments
 (0)