🔧 Fix golangci-lint issues (errcheck, staticcheck, unused)
- Check fmt.Fprintln return value in cmd/flags.go - Remove unused confirmationToolNames, computeConfirmationToolNames, requireConfirmation - Convert if/else-if chains to tagged switches (QF1003) - Remove empty if branches (SA9003) - Simplify embedded field selectors (QF1008) - Use fmt.Fprintf instead of Write([]byte(fmt.Sprintf(...))) (QF1012)
This commit is contained in:
1 parent
4cc9be68a4
commit
521314945c
9 files changed
+49
-80
No files matched your search
@@ -145,24 +145,6 @@ var agentDefs = map[string]agentDef{
|
||||
},
|
||||
}
|
||||
|
||||
var confirmationToolNames = computeConfirmationToolNames()
|
||||
|
||||
func computeConfirmationToolNames() map[string]struct{} {
|
||||
readOnly := make(map[string]struct{}, len(agentDefs["Aagje"].toolNames))
|
||||
for _, name := range agentDefs["Aagje"].toolNames {
|
||||
readOnly[name] = struct{}{}
|
||||
}
|
||||
|
||||
result := make(map[string]struct{})
|
||||
for _, key := range []string{"Knorretje", "Daan"} {
|
||||
for _, name := range agentDefs[key].toolNames {
|
||||
if _, ok := readOnly[name]; !ok {
|
||||
result[name] = struct{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func init() {
|
||||
for _, def := range agentDefs {
|
||||
@@ -172,10 +154,6 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
func requireConfirmation(name string, _ any) bool {
|
||||
_, ok := confirmationToolNames[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
func buildOrchestrator(
|
||||
advancedModel, liteModel model.LLM, mcpToolSet tool.Toolset,
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ func confirmWithTTYOverride(cmd *cobra.Command, isTTY bool, format string, args
|
||||
|
||||
// 1. --dry-run takes precedence over everything.
|
||||
if DryRun(cmd) {
|
||||
fmt.Fprintln(cmd.OutOrStdout(), msg)
|
||||
_, _ = fmt.Fprintln(cmd.OutOrStdout(), msg)
|
||||
return ErrDryRun
|
||||
}
|
||||
|
||||
|
||||
@@ -432,17 +432,18 @@ func TestCaption_Update(t *testing.T) {
|
||||
WithLanguage("es"),
|
||||
},
|
||||
verify: func(r *http.Request) {
|
||||
if r.Method == "PUT" {
|
||||
switch r.Method {
|
||||
case "PUT":
|
||||
if r.URL.Query().Get("part") != "snippet" {
|
||||
t.Errorf("expected part=snippet, got %s", r.URL.Query().Get("part"))
|
||||
}
|
||||
} else if r.Method == "GET" {
|
||||
case "GET":
|
||||
if r.URL.Query().Get("videoId") != "video-id" {
|
||||
t.Errorf(
|
||||
"expected videoId=video-id, got %s", r.URL.Query().Get("videoId"),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
default:
|
||||
t.Errorf("unexpected method %s", r.Method)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -431,15 +431,16 @@ func TestChannel_Update(t *testing.T) {
|
||||
WithMaxResults(1),
|
||||
},
|
||||
verify: func(r *http.Request) {
|
||||
if r.Method == "PUT" {
|
||||
switch r.Method {
|
||||
case "PUT":
|
||||
if r.URL.Query().Get("part") != "snippet" {
|
||||
t.Errorf("expected part=snippet, got %s", r.URL.Query().Get("part"))
|
||||
}
|
||||
} else if r.Method == "GET" {
|
||||
case "GET":
|
||||
if r.URL.Query().Get("id") != "channel-id" {
|
||||
t.Errorf("expected id=channel-id, got %s", r.URL.Query().Get("id"))
|
||||
}
|
||||
} else {
|
||||
default:
|
||||
t.Errorf("unexpected method %s", r.Method)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -401,12 +401,13 @@ func TestComment_Update(t *testing.T) {
|
||||
WithMaxResults(1),
|
||||
},
|
||||
verify: func(r *http.Request) {
|
||||
if r.Method == "PUT" {
|
||||
switch r.Method {
|
||||
case "PUT":
|
||||
if r.URL.Query().Get("part") != "snippet" {
|
||||
t.Errorf("expected part=snippet, got %s", r.URL.Query().Get("part"))
|
||||
}
|
||||
} else if r.Method == "GET" {
|
||||
} else {
|
||||
case "GET":
|
||||
default:
|
||||
t.Errorf("unexpected method %s", r.Method)
|
||||
}
|
||||
},
|
||||
@@ -423,10 +424,7 @@ func TestComment_Update(t *testing.T) {
|
||||
WithViewerRating("like"),
|
||||
WithMaxResults(1),
|
||||
},
|
||||
verify: func(r *http.Request) {
|
||||
if r.Method == "PUT" {
|
||||
}
|
||||
},
|
||||
verify: func(_ *http.Request) {},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
+20
-19
@@ -67,7 +67,8 @@ func TestPaginate(t *testing.T) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
pageToken := r.URL.Query().Get("pageToken")
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if pageToken == "" {
|
||||
switch pageToken {
|
||||
case "":
|
||||
items := make([]string, 20)
|
||||
for i := range 20 {
|
||||
items[i] = fmt.Sprintf(`{"id": "v%d"}`, i+1)
|
||||
@@ -77,7 +78,7 @@ func TestPaginate(t *testing.T) {
|
||||
"items": %s,
|
||||
"nextPageToken": "page-2"
|
||||
}`, jsonItems)
|
||||
} else if pageToken == "page-2" {
|
||||
case "page-2":
|
||||
_, _ = w.Write([]byte(`{
|
||||
"items": [{"id": "v21"}, {"id": "v22"}],
|
||||
"nextPageToken": ""
|
||||
@@ -333,8 +334,8 @@ func TestWithMaxResults(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &testResource{}
|
||||
WithMaxResults[*testResource](tt.input)(r)
|
||||
if r.Fields.MaxResults != tt.want {
|
||||
t.Errorf("WithMaxResults(%d) = %d, want %d", tt.input, r.Fields.MaxResults, tt.want)
|
||||
if r.MaxResults != tt.want {
|
||||
t.Errorf("WithMaxResults(%d) = %d, want %d", tt.input, r.MaxResults, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -344,10 +345,10 @@ func TestWithIds(t *testing.T) {
|
||||
r := &testResource{}
|
||||
ids := []string{"id1", "id2", "id3"}
|
||||
WithIds[*testResource](ids)(r)
|
||||
if len(r.Fields.Ids) != len(ids) {
|
||||
t.Fatalf("WithIds() got %d ids, want %d", len(r.Fields.Ids), len(ids))
|
||||
if len(r.Ids) != len(ids) {
|
||||
t.Fatalf("WithIds() got %d ids, want %d", len(r.Ids), len(ids))
|
||||
}
|
||||
for i, id := range r.Fields.Ids {
|
||||
for i, id := range r.Ids {
|
||||
if id != ids[i] {
|
||||
t.Errorf("WithIds()[%d] = %q, want %q", i, id, ids[i])
|
||||
}
|
||||
@@ -358,10 +359,10 @@ func TestWithParts(t *testing.T) {
|
||||
r := &testResource{}
|
||||
parts := []string{"snippet", "contentDetails"}
|
||||
WithParts[*testResource](parts)(r)
|
||||
if len(r.Fields.Parts) != len(parts) {
|
||||
t.Fatalf("WithParts() got %d parts, want %d", len(r.Fields.Parts), len(parts))
|
||||
if len(r.Parts) != len(parts) {
|
||||
t.Fatalf("WithParts() got %d parts, want %d", len(r.Parts), len(parts))
|
||||
}
|
||||
for i, p := range r.Fields.Parts {
|
||||
for i, p := range r.Parts {
|
||||
if p != parts[i] {
|
||||
t.Errorf("WithParts()[%d] = %q, want %q", i, p, parts[i])
|
||||
}
|
||||
@@ -371,8 +372,8 @@ func TestWithParts(t *testing.T) {
|
||||
func TestWithOutput(t *testing.T) {
|
||||
r := &testResource{}
|
||||
WithOutput[*testResource]("json")(r)
|
||||
if r.Fields.Output != "json" {
|
||||
t.Errorf("WithOutput() = %q, want %q", r.Fields.Output, "json")
|
||||
if r.Output != "json" {
|
||||
t.Errorf("WithOutput() = %q, want %q", r.Output, "json")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,7 +381,7 @@ func TestWithService(t *testing.T) {
|
||||
r := &testResource{}
|
||||
svc := &youtube.Service{}
|
||||
WithService[*testResource](svc)(r)
|
||||
if r.Fields.Service != svc {
|
||||
if r.Service != svc {
|
||||
t.Errorf("WithService() did not set service")
|
||||
}
|
||||
}
|
||||
@@ -388,23 +389,23 @@ func TestWithService(t *testing.T) {
|
||||
func TestWithHl(t *testing.T) {
|
||||
r := &testResource{}
|
||||
WithHl[*testResource]("en")(r)
|
||||
if r.Fields.Hl != "en" {
|
||||
t.Errorf("WithHl() = %q, want %q", r.Fields.Hl, "en")
|
||||
if r.Hl != "en" {
|
||||
t.Errorf("WithHl() = %q, want %q", r.Hl, "en")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithChannelId(t *testing.T) {
|
||||
r := &testResource{}
|
||||
WithChannelId[*testResource]("chan-123")(r)
|
||||
if r.Fields.ChannelId != "chan-123" {
|
||||
t.Errorf("WithChannelId() = %q, want %q", r.Fields.ChannelId, "chan-123")
|
||||
if r.ChannelId != "chan-123" {
|
||||
t.Errorf("WithChannelId() = %q, want %q", r.ChannelId, "chan-123")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithOnBehalfOfContentOwner(t *testing.T) {
|
||||
r := &testResource{}
|
||||
WithOnBehalfOfContentOwner[*testResource]("owner-456")(r)
|
||||
if r.Fields.OnBehalfOfContentOwner != "owner-456" {
|
||||
t.Errorf("WithOnBehalfOfContentOwner() = %q, want %q", r.Fields.OnBehalfOfContentOwner, "owner-456")
|
||||
if r.OnBehalfOfContentOwner != "owner-456" {
|
||||
t.Errorf("WithOnBehalfOfContentOwner() = %q, want %q", r.OnBehalfOfContentOwner, "owner-456")
|
||||
}
|
||||
}
|
||||
+11
-15
@@ -49,26 +49,22 @@ func PaginationHandler(idPrefix string, itemFmt ...func(string, int) string) htt
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
pageToken := r.URL.Query().Get("pageToken")
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if pageToken == "" {
|
||||
switch pageToken {
|
||||
case "":
|
||||
items := make([]string, 20)
|
||||
for i := range 20 {
|
||||
items[i] = fmtItem(idPrefix, i)
|
||||
}
|
||||
_, _ = w.Write(
|
||||
fmt.Appendf(
|
||||
nil,
|
||||
`{"items": [%s], "nextPageToken": "page-2"}`,
|
||||
strings.Join(items, ","),
|
||||
),
|
||||
_, _ = fmt.Fprintf(
|
||||
w,
|
||||
`{"items": [%s], "nextPageToken": "page-2"}`,
|
||||
strings.Join(items, ","),
|
||||
)
|
||||
} else if pageToken == "page-2" {
|
||||
_, _ = w.Write(
|
||||
[]byte(
|
||||
fmt.Sprintf(
|
||||
`{"items": [%s, %s], "nextPageToken": ""}`,
|
||||
fmtItem(idPrefix, 20), fmtItem(idPrefix, 21),
|
||||
),
|
||||
),
|
||||
case "page-2":
|
||||
_, _ = fmt.Fprintf(
|
||||
w,
|
||||
`{"items": [%s, %s], "nextPageToken": ""}`,
|
||||
fmtItem(idPrefix, 20), fmtItem(idPrefix, 21),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,7 +262,8 @@ func TestPlaylistImage_Get_Pagination(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPlaylistImage_List(t *testing.T) {
|
||||
common.RunListTest(t, `{
|
||||
common.RunListTest(
|
||||
t, `{
|
||||
"items": [
|
||||
{
|
||||
"id": "image-1",
|
||||
@@ -468,10 +469,7 @@ func TestPlaylistImage_Update(t *testing.T) {
|
||||
WithMaxResults(1),
|
||||
WithFile("test_image.jpg"),
|
||||
},
|
||||
verify: func(r *http.Request) {
|
||||
if r.Method == "PUT" {
|
||||
}
|
||||
},
|
||||
verify: func(_ *http.Request) {},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -499,11 +499,7 @@ func TestPlaylistItem_Update(t *testing.T) {
|
||||
WithPrivacy("private"),
|
||||
WithMaxResults(1),
|
||||
},
|
||||
verify: func(r *http.Request) {
|
||||
if r.Method == "PUT" {
|
||||
if r.URL.Query().Get("id") != "" {
|
||||
}
|
||||
}
|
||||
verify: func(_ *http.Request) {
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user