Skip to content

Commit 7e668d5

Browse files
authored
chore: migrate to golangci-lint v2 (#962)
Signed-off-by: Donnie Adams <[email protected]>
1 parent 4b87a83 commit 7e668d5

File tree

20 files changed

+158
-144
lines changed

20 files changed

+158
-144
lines changed

.golangci.yml

+34-17
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
1+
version: "2"
12
run:
23
timeout: 5m
3-
44
output:
55
formats:
6-
- format: colored-line-number
7-
6+
text:
7+
path: stdout
88
linters:
9-
disable-all: true
9+
default: none
1010
enable:
11-
- errcheck
12-
- gofmt
13-
- gosimple
14-
- govet
15-
- ineffassign
16-
- staticcheck
17-
- typecheck
18-
- thelper
19-
- unused
20-
- goimports
21-
- whitespace
22-
- revive
23-
fast: false
11+
- errcheck
12+
- govet
13+
- ineffassign
14+
- revive
15+
- staticcheck
16+
- thelper
17+
- unused
18+
- whitespace
19+
exclusions:
20+
generated: lax
21+
presets:
22+
- comments
23+
- common-false-positives
24+
- legacy
25+
- std-error-handling
26+
paths:
27+
- third_party$
28+
- builtin$
29+
- examples$
30+
issues:
2431
max-same-issues: 50
32+
formatters:
33+
enable:
34+
- gofmt
35+
- goimports
36+
exclusions:
37+
generated: lax
38+
paths:
39+
- third_party$
40+
- builtin$
41+
- examples$

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ smoke: build
2222
smoke:
2323
go test -v -tags='smoke' ./pkg/tests/smoke/...
2424

25-
GOLANGCI_LINT_VERSION ?= v1.60.1
25+
GOLANGCI_LINT_VERSION ?= v2.1.2
2626
lint:
2727
if ! command -v golangci-lint &> /dev/null; then \
2828
echo "Could not find golangci-lint, installing version $(GOLANGCI_LINT_VERSION)."; \

pkg/builtin/builtin.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ func DefaultModel(name, defaultModel string) (types.Tool, bool) {
280280
// Legacy syntax not used anymore
281281
name = strings.TrimSuffix(name, "?")
282282
t, ok := tools[name]
283-
t.Parameters.Name = name
284-
t.Parameters.ModelName = defaultModel
283+
t.Name = name
284+
t.ModelName = defaultModel
285285
t.ID = name
286286
t.Instructions = "#!" + name
287287
return SetDefaults(t), ok

pkg/builtin/defaults.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ func SetDefaultModel(model string) {
1818
}
1919

2020
func SetDefaults(tool types.Tool) types.Tool {
21-
if tool.Parameters.ModelName == "" {
22-
tool.Parameters.ModelName = GetDefaultModel()
21+
if tool.ModelName == "" {
22+
tool.ModelName = GetDefaultModel()
2323
}
2424
return tool
2525
}

pkg/chat/chat.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func Start(ctx context.Context, prevState runner.ChatState, chatter Chatter, prg
6161
if startInput != "" {
6262
input = startInput
6363
startInput = ""
64-
} else if targetTool := prog.ToolSet[prog.EntryToolID]; !((prevState == nil || prevState == "") && targetTool.Arguments == nil && targetTool.Instructions != "") {
64+
} else if targetTool := prog.ToolSet[prog.EntryToolID]; prevState != nil && prevState != "" || targetTool.Arguments != nil || targetTool.Instructions == "" {
6565
// The above logic will skip prompting if this is the first loop and the chat expects no args
6666
input, ok, err = prompter.Readline()
6767
if !ok || err != nil {

pkg/cli/gptscript.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
366366

367367
// If the file is external, then set the SCRIPTS_PATH to the current working directory. Otherwise,
368368
// set it to the directory of the script and set the file to the base.
369-
if !(strings.HasPrefix(file, "http://") || strings.HasPrefix(file, "https://") || strings.HasPrefix(file, "github.com")) {
369+
if !strings.HasPrefix(file, "http://") && !strings.HasPrefix(file, "https://") && !strings.HasPrefix(file, "github.com") {
370370
absPathToScript, err := filepath.Abs(file)
371371
if err != nil {
372372
return fmt.Errorf("cannot determine absolute path to script %s: %v", file, err)
@@ -469,8 +469,8 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) {
469469
// Don't use cmd.Context() because then sigint will cancel everything
470470
return tui.Run(context.Background(), args[0], tui.RunOptions{
471471
ClientOpts: &gptscript2.GlobalOptions{
472-
OpenAIAPIKey: r.OpenAIOptions.APIKey,
473-
OpenAIBaseURL: r.OpenAIOptions.BaseURL,
472+
OpenAIAPIKey: r.APIKey,
473+
OpenAIBaseURL: r.BaseURL,
474474
DefaultModel: r.DefaultModel,
475475
DefaultModelProvider: r.DefaultModelProvider,
476476
},

pkg/engine/cmd.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (e *Engine) runCommand(ctx Context, tool types.Tool, input string, toolCate
171171
// If this is a sub-call, then don't return the error; return the error as a message so that the LLM can retry.
172172
return fmt.Sprintf("ERROR: got (%v) while running tool, OUTPUT: %s", err, stdoutAndErr), nil
173173
}
174-
log.Errorf("failed to run tool [%s] cmd %v: %v", tool.Parameters.Name, cmd.Args, err)
174+
log.Errorf("failed to run tool [%s] cmd %v: %v", tool.Name, cmd.Args, err)
175175
return "", fmt.Errorf("ERROR: %s: %w", stdoutAndErr, err)
176176
}
177177

pkg/engine/daemon.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (e *Engine) startDaemon(tool types.Tool) (string, error) {
175175
return w.Close()
176176
}
177177

178-
log.Infof("launched [%s][%s] port [%d] %v", tool.Parameters.Name, tool.ID, port, cmd.Args)
178+
log.Infof("launched [%s][%s] port [%d] %v", tool.Name, tool.ID, port, cmd.Args)
179179
if err := cmd.Start(); err != nil {
180180
stop()
181181
return url, err
@@ -195,7 +195,7 @@ func (e *Engine) startDaemon(tool types.Tool) (string, error) {
195195
go func() {
196196
err := cmd.Wait()
197197
if err != nil {
198-
log.Debugf("daemon exited tool [%s] %v: %v", tool.Parameters.Name, cmd.Args, err)
198+
log.Debugf("daemon exited tool [%s] %v: %v", tool.Name, cmd.Args, err)
199199
}
200200
_ = r.Close()
201201
_ = w.Close()

pkg/engine/engine.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ func (c *Context) WrappedContext(e *Engine) context.Context {
285285
}
286286

287287
func populateMessageParams(ctx Context, completion *types.CompletionRequest, tool types.Tool) error {
288-
completion.Model = tool.Parameters.ModelName
289-
completion.MaxTokens = tool.Parameters.MaxTokens
290-
completion.JSONResponse = tool.Parameters.JSONResponse
291-
completion.Cache = tool.Parameters.Cache
292-
completion.Chat = tool.Parameters.Chat
293-
completion.Temperature = tool.Parameters.Temperature
294-
completion.InternalSystemPrompt = tool.Parameters.InternalPrompt
288+
completion.Model = tool.ModelName
289+
completion.MaxTokens = tool.MaxTokens
290+
completion.JSONResponse = tool.JSONResponse
291+
completion.Cache = tool.Cache
292+
completion.Chat = tool.Chat
293+
completion.Temperature = tool.Temperature
294+
completion.InternalSystemPrompt = tool.InternalPrompt
295295

296296
if tool.Chat && completion.InternalSystemPrompt == nil {
297297
completion.InternalSystemPrompt = new(bool)

pkg/engine/http.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (e *Engine) runHTTP(ctx Context, tool types.Tool, input string) (cmdRet *Re
112112
}
113113
}
114114

115-
req.Header.Set("X-GPTScript-Tool-Name", tool.Parameters.Name)
115+
req.Header.Set("X-GPTScript-Tool-Name", tool.Name)
116116

117117
if err := json.Unmarshal([]byte(input), &map[string]any{}); err == nil {
118118
req.Header.Set("Content-Type", "application/json")

pkg/loader/loader.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,15 @@ func readTool(ctx context.Context, cache *cache.Client, prg *types.Program, base
225225
// Probably a better way to come up with an ID
226226
tool.ID = tool.Source.Location + ":" + tool.Name
227227

228-
if i != 0 && tool.Parameters.Name == "" {
228+
if i != 0 && tool.Name == "" {
229229
return nil, parser.NewErrLine(tool.Source.Location, tool.Source.LineNo, fmt.Errorf("only the first tool in a file can have no name"))
230230
}
231231

232-
if i != 0 && tool.Parameters.GlobalModelName != "" {
232+
if i != 0 && tool.GlobalModelName != "" {
233233
return nil, parser.NewErrLine(tool.Source.Location, tool.Source.LineNo, fmt.Errorf("only the first tool in a file can have global model name"))
234234
}
235235

236-
if i != 0 && len(tool.Parameters.GlobalTools) > 0 {
236+
if i != 0 && len(tool.GlobalTools) > 0 {
237237
return nil, parser.NewErrLine(tool.Source.Location, tool.Source.LineNo, fmt.Errorf("only the first tool in a file can have global tools"))
238238
}
239239

@@ -245,8 +245,8 @@ func readTool(ctx context.Context, cache *cache.Client, prg *types.Program, base
245245
targetTools = append(targetTools, tool)
246246
}
247247

248-
if targetToolName != "" && tool.Parameters.Name != "" {
249-
if strings.EqualFold(tool.Parameters.Name, targetToolName) {
248+
if targetToolName != "" && tool.Name != "" {
249+
if strings.EqualFold(tool.Name, targetToolName) {
250250
targetTools = append(targetTools, tool)
251251
} else if strings.Contains(targetToolName, "*") {
252252
var patterns []string
@@ -257,7 +257,7 @@ func readTool(ctx context.Context, cache *cache.Client, prg *types.Program, base
257257
}
258258

259259
for _, pattern := range patterns {
260-
match, err := filepath.Match(strings.ToLower(pattern), strings.ToLower(tool.Parameters.Name))
260+
match, err := filepath.Match(strings.ToLower(pattern), strings.ToLower(tool.Name))
261261
if err != nil {
262262
return nil, parser.NewErrLine(tool.Source.Location, tool.Source.LineNo, err)
263263
}
@@ -270,13 +270,13 @@ func readTool(ctx context.Context, cache *cache.Client, prg *types.Program, base
270270
}
271271
}
272272

273-
if existing, ok := localTools[strings.ToLower(tool.Parameters.Name)]; ok {
273+
if existing, ok := localTools[strings.ToLower(tool.Name)]; ok {
274274
return nil, parser.NewErrLine(tool.Source.Location, tool.Source.LineNo,
275-
fmt.Errorf("duplicate tool name [%s] in %s found at lines %d and %d", tool.Parameters.Name, tool.Source.Location,
275+
fmt.Errorf("duplicate tool name [%s] in %s found at lines %d and %d", tool.Name, tool.Source.Location,
276276
tool.Source.LineNo, existing.Source.LineNo))
277277
}
278278

279-
localTools[strings.ToLower(tool.Parameters.Name)] = tool
279+
localTools[strings.ToLower(tool.Name)] = tool
280280
}
281281

282282
return linkAll(ctx, cache, prg, base, targetTools, localTools, defaultModel)
@@ -285,7 +285,7 @@ func readTool(ctx context.Context, cache *cache.Client, prg *types.Program, base
285285
func linkAll(ctx context.Context, cache *cache.Client, prg *types.Program, base *source, tools []types.Tool, localTools types.ToolSet, defaultModel string) (result []types.Tool, _ error) {
286286
localToolsMapping := make(map[string]string, len(tools))
287287
for _, localTool := range localTools {
288-
localToolsMapping[strings.ToLower(localTool.Parameters.Name)] = localTool.ID
288+
localToolsMapping[strings.ToLower(localTool.Name)] = localTool.ID
289289
}
290290

291291
for _, tool := range tools {
@@ -314,7 +314,7 @@ func link(ctx context.Context, cache *cache.Client, prg *types.Program, base *so
314314
// The below is done in two loops so that local names stay as the tool names
315315
// and don't get mangled by external references
316316

317-
for _, targetToolName := range tool.Parameters.ToolRefNames() {
317+
for _, targetToolName := range tool.ToolRefNames() {
318318
noArgs, _ := types.SplitArg(targetToolName)
319319
localTool, ok := localTools[strings.ToLower(noArgs)]
320320
if ok {

pkg/loader/openapi.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ func getOpenAPITools(t *openapi3.T, defaultHost, source, targetToolName string)
174174
}
175175

176176
// Add the new arg to the tool's arguments
177-
tool.Parameters.Arguments.Properties[param.Value.Name] = &openapi3.SchemaRef{Value: arg}
177+
tool.Arguments.Properties[param.Value.Name] = &openapi3.SchemaRef{Value: arg}
178178

179179
// Check whether it is required
180180
if param.Value.Required {
181-
tool.Parameters.Arguments.Required = append(tool.Parameters.Arguments.Required, param.Value.Name)
181+
tool.Arguments.Required = append(tool.Arguments.Required, param.Value.Name)
182182
}
183183

184184
// Add the parameter to the appropriate list for the tool's instructions
@@ -227,7 +227,7 @@ func getOpenAPITools(t *openapi3.T, defaultHost, source, targetToolName string)
227227
}
228228
// Unfortunately, the request body doesn't contain any good descriptor for it,
229229
// so we just use "requestBodyContent" as the name of the arg.
230-
tool.Parameters.Arguments.Properties["requestBodyContent"] = &openapi3.SchemaRef{Value: arg}
230+
tool.Arguments.Properties["requestBodyContent"] = &openapi3.SchemaRef{Value: arg}
231231
break
232232
}
233233

@@ -310,7 +310,7 @@ func getOpenAPITools(t *openapi3.T, defaultHost, source, targetToolName string)
310310
}
311311

312312
// Register
313-
toolNames = append(toolNames, tool.Parameters.Name)
313+
toolNames = append(toolNames, tool.Name)
314314
tools = append(tools, tool)
315315
operationNum++
316316
}
@@ -457,7 +457,7 @@ func getOpenAPIToolsRevamp(t *openapi3.T, source, targetToolName string) ([]type
457457
exportTool := types.Tool{
458458
ToolDef: types.ToolDef{
459459
Parameters: types.Parameters{
460-
Export: []string{list.Parameters.Name, getSchema.Parameters.Name, run.Parameters.Name},
460+
Export: []string{list.Name, getSchema.Name, run.Name},
461461
},
462462
},
463463
}

pkg/monitor/display.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func (c callName) String() string {
386386

387387
for {
388388
tool := c.prg.ToolSet[currentCall.ToolID]
389-
name := tool.Parameters.Name
389+
name := tool.Name
390390
if name == "" {
391391
name = tool.Source.Location
392392
}

0 commit comments

Comments
 (0)